forked from sonofmun/MM-Python-Course
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0e4f7e
commit 0898657
Showing
41 changed files
with
18,485 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ pyhum | |
pydf | ||
styles | ||
*.bak | ||
pages.csv | ||
pages.csv | ||
*.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_login import LoginManager | ||
import os | ||
from .constantes import CONFIG | ||
|
||
chemin_actuel = os.path.dirname(os.path.abspath(__file__)) | ||
templates = os.path.join(chemin_actuel, "templates") | ||
statics = os.path.join(chemin_actuel, "static") | ||
|
||
# On initie l'extension | ||
db = SQLAlchemy() | ||
# On met en place la gestion d'utilisateur-rice-s | ||
login = LoginManager() | ||
|
||
app = Flask( | ||
__name__, | ||
template_folder=templates, | ||
static_folder=statics | ||
) | ||
|
||
|
||
from .routes import generic | ||
from .routes import api | ||
|
||
|
||
def config_app(config_name="test"): | ||
""" Create the application """ | ||
app.config.from_object(CONFIG[config_name]) | ||
|
||
# Set up extensions | ||
db.init_app(app) | ||
# assets_env = Environment(app) | ||
login.init_app(app) | ||
|
||
# Register Jinja template functions | ||
|
||
return app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from warnings import warn | ||
|
||
LIEUX_PAR_PAGE = 2 | ||
SECRET_KEY = "JE SUIS UN SECRET !" | ||
API_ROUTE = "/api" | ||
|
||
if SECRET_KEY == "JE SUIS UN SECRET !": | ||
warn("Le secret par défaut n'a pas été changé, vous devriez le faire", Warning) | ||
|
||
|
||
class _TEST: | ||
SECRET_KEY = SECRET_KEY | ||
# On configure la base de données | ||
SQLALCHEMY_DATABASE_URI = 'sqlite:///test_db.sqlite' | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
|
||
|
||
class _PRODUCTION: | ||
SECRET_KEY = SECRET_KEY | ||
# On configure la base de données | ||
SQLALCHEMY_DATABASE_URI = 'mysql://gazetteer_user:password@localhost/gazetteer' | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
|
||
CONFIG = { | ||
"test": _TEST, | ||
"production": _PRODUCTION | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from flask import url_for | ||
import datetime | ||
|
||
from .. app import db | ||
|
||
|
||
class Authorship(db.Model): | ||
__tablename__ = "authorship" | ||
authorship_id = db.Column(db.Integer, nullable=True, autoincrement=True, primary_key=True) | ||
authorship_place_id = db.Column(db.Integer, db.ForeignKey('place.place_id')) | ||
authorship_user_id = db.Column(db.Integer, db.ForeignKey('user.user_id')) | ||
authorship_date = db.Column(db.DateTime, default=datetime.datetime.utcnow) | ||
user = db.relationship("User", back_populates="authorships") | ||
place = db.relationship("Place", back_populates="authorships") | ||
|
||
def author_to_json(self): | ||
return { | ||
"author": self.user.to_jsonapi_dict(), | ||
"on": self.authorship_date | ||
} | ||
|
||
|
||
# On crée notre modèle | ||
class Place(db.Model): | ||
place_id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True, autoincrement=True) | ||
place_nom = db.Column(db.Text) | ||
place_description = db.Column(db.Text) | ||
place_longitude = db.Column(db.Float) | ||
place_latitude = db.Column(db.Float) | ||
place_type = db.Column(db.String(45)) | ||
authorships = db.relationship("Authorship", back_populates="place") | ||
|
||
def to_jsonapi_dict(self): | ||
""" It ressembles a little JSON API format but it is not completely compatible | ||
:return: | ||
""" | ||
return { | ||
"type": "place", | ||
"id": self.place_id, | ||
"attributes": { | ||
"name": self.place_nom, | ||
"description": self.place_description, | ||
"longitude": self.place_longitude, | ||
"latitude": self.place_latitude, | ||
"category": self.place_type | ||
}, | ||
"links": { | ||
"self": url_for("lieu", place_id=self.place_id, _external=True), | ||
"json": url_for("api_places_single", place_id=self.place_id, _external=True) | ||
}, | ||
"relationships": { | ||
"editions": [ | ||
author.author_to_json() | ||
for author in self.authorships | ||
] | ||
} | ||
} |
Oops, something went wrong.