From a71fe2ecda56129caea78bf57fb5b5dc1e8fba90 Mon Sep 17 00:00:00 2001 From: vincent Date: Tue, 25 May 2021 21:01:20 +0200 Subject: [PATCH] first commit --- .gitignore | 3 + .pylintrc | 0 ITPlanning/api/__init__.py | 9 +++ ITPlanning/api/appointement.py | 0 ITPlanning/api/planning.py | 0 ITPlanning/api/service.py | 0 ITPlanning/api/ticket.py | 0 ITPlanning/api/user.py | 0 ITPlanning/app.py | 21 ++++++ ITPlanning/config.py | 27 +++++++ ITPlanning/db.py | 125 ++++++++++++++++++++++++++++++++ ITPlanning/frontend/__init__.py | 0 Readme.md | 47 ++++++++++++ run.py | 5 ++ 14 files changed, 237 insertions(+) create mode 100644 .gitignore create mode 100644 .pylintrc create mode 100644 ITPlanning/api/__init__.py create mode 100644 ITPlanning/api/appointement.py create mode 100644 ITPlanning/api/planning.py create mode 100644 ITPlanning/api/service.py create mode 100644 ITPlanning/api/ticket.py create mode 100644 ITPlanning/api/user.py create mode 100644 ITPlanning/app.py create mode 100644 ITPlanning/config.py create mode 100644 ITPlanning/db.py create mode 100644 ITPlanning/frontend/__init__.py create mode 100755 Readme.md create mode 100644 run.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d32c97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +env +venv diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..e69de29 diff --git a/ITPlanning/api/__init__.py b/ITPlanning/api/__init__.py new file mode 100644 index 0000000..6bc74ac --- /dev/null +++ b/ITPlanning/api/__init__.py @@ -0,0 +1,9 @@ +from flask import Blueprint + +api = Blueprint("api",__name__) + +from .appointement import * +from .planning import * +from .service import * +from .ticket import * +from .user import * diff --git a/ITPlanning/api/appointement.py b/ITPlanning/api/appointement.py new file mode 100644 index 0000000..e69de29 diff --git a/ITPlanning/api/planning.py b/ITPlanning/api/planning.py new file mode 100644 index 0000000..e69de29 diff --git a/ITPlanning/api/service.py b/ITPlanning/api/service.py new file mode 100644 index 0000000..e69de29 diff --git a/ITPlanning/api/ticket.py b/ITPlanning/api/ticket.py new file mode 100644 index 0000000..e69de29 diff --git a/ITPlanning/api/user.py b/ITPlanning/api/user.py new file mode 100644 index 0000000..e69de29 diff --git a/ITPlanning/app.py b/ITPlanning/app.py new file mode 100644 index 0000000..e8f4062 --- /dev/null +++ b/ITPlanning/app.py @@ -0,0 +1,21 @@ +""" flask apps initialisation """ +import logging +from flask import Flask +from pony.flask import Pony +from ITPlanning.api import api +from ITPlanning.db import init_database, release_database +#from ITPlanning.frontend import frontend + +logger = logging.getLogger(__name__) + +def create_app(): + app=Flask(__name__, static_folder= "static",template_folder="view") + app.config.from_object("ITPlanning.config.DefaultConfig") + app.register_blueprint(api, url_prefix="/api/v1") + #app.register_blueprint(frontend) + + # Initialize database + logger.warning(app.config["BASE"]["database_uri"]) + init_database(app.config["BASE"]["database_uri"]) + Pony(app) + return app diff --git a/ITPlanning/config.py b/ITPlanning/config.py new file mode 100644 index 0000000..99e7d2c --- /dev/null +++ b/ITPlanning/config.py @@ -0,0 +1,27 @@ +""" config management """ + +from os import makedirs, path +import tempfile + +current_config = None + +class DefaultConfig: + + DEBUG = False + SECRET_KEY="toto" + tempdir= path.join(tempfile.gettempdir(), "ITPlanning") + BASE = { + "database_uri": "sqlite:///" + path.join(tempdir, "ITPlanning.db"), + } + def __init__(self): + if not path.exists(self.tempdir): + makedirs(self.tempdir) + current_config = self + + + +def get_current_config(): + + if current_config is None: + DefaultConfig() + return current_config diff --git a/ITPlanning/db.py b/ITPlanning/db.py new file mode 100644 index 0000000..01a8c82 --- /dev/null +++ b/ITPlanning/db.py @@ -0,0 +1,125 @@ +""" Database management """ + +from datetime import datetime +from urllib.parse import urlparse, parse_qsl +from pony.orm import Database, Required, Optional, Set, PrimaryKey, LongStr + +db = Database() +class Service(db.Entity): + id = PrimaryKey(int, auto=True) + name = Required(str, unique=True) + localisation = Optional(str) + max_appointement = Required(int) + plannings = Set('Planning') + service_category = Required('Service_category') + appointments = Set('Appointment') + description = Optional(str) + + +class Planning(db.Entity): + id = PrimaryKey(int, auto=True) + name = Required(str, unique=True) + working_plan = Required(LongStr) + services = Set(Service) + appointments = Set('Appointment') + + +class Setting(db.Entity): + id = PrimaryKey(int, auto=True) + name = Required(str, unique=True) + value = Optional(str) + + +class Appointment(db.Entity): + id = PrimaryKey(int, auto=True) + book_datetime = Required(datetime) + start_datetime = Required(datetime) + end_datetime = Required(str) + localisation = Optional(str, nullable=True) + is_unavaillable = Required(bool) + service = Required(Service) + planning = Required(Planning) + ticket = Optional('Ticket') + user = Optional('User') + notes = Optional(LongStr) + + +class User(db.Entity): + id = PrimaryKey(int, auto=True) + first_name = Required(str) + last_name = Required(str) + email = Required(str, unique=True) + localisation = Optional(str) + mobile_number = Optional(str) + phone_number = Optional(str) + tickets = Set('Ticket') + appointments = Set(Appointment) + notes = Optional(str) + + +class Ticket(db.Entity): + id = PrimaryKey(int, auto=True) + ref = Optional(str, unique=True) + service_category = Required('Service_category') + user = Required(User) + appointment = Required(Appointment) + notes = Optional(str) + + +class Service_category(db.Entity): + id = PrimaryKey(int, auto=True) + name = Required(str) + tickets = Set(Ticket) + duration = Required(int) + free_order = Required(bool) + services = Set(Service) + description = Optional(str) + + + +def parse_uri(database_uri): + if not isinstance(database_uri, str): + raise TypeError("Expecting a string") + + uri = urlparse(database_uri) + args = dict(parse_qsl(uri.query)) + if uri.port is not None: + args["port"] = uri.port + + if uri.scheme == "sqlite": + path = uri.path + if not path: + path = ":memory:" + elif path[0] == "/": + path = path[1:] + + return dict(provider="sqlite", filename=path, create_db=True, **args) + elif uri.scheme in ("postgres", "postgresql"): + return dict( + provider="postgres", + user=uri.username, + password=uri.password, + host=uri.hostname, + dbname=uri.path[1:], + **args + ) + elif uri.scheme == "mysql": + args.setdefault("charset", "utf8mb4") + args.setdefault("binary_prefix", True) + return dict( + provider="mysql", + user=uri.username, + passwd=uri.password, + host=uri.hostname, + db=uri.path[1:], + **args + ) + return dict() + +def init_database(database_uri): + settings = parse_uri(database_uri) + db.bind(**settings) + db.generate_mapping(create_tables=True) + +def release_database(): + db.disconnect() diff --git a/ITPlanning/frontend/__init__.py b/ITPlanning/frontend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Readme.md b/Readme.md new file mode 100755 index 0000000..9440f42 --- /dev/null +++ b/Readme.md @@ -0,0 +1,47 @@ +# IT Planning + +# table + +## Service + +id +nom: install,refresh +durée: +loca: optionelle si set prend le dessus dur loca du ticket +nombre_appointement + +## planning + +id +nom: +working_plan + +## planning_service + +planning_id +service_id + +## appointment + +book_date +start +end +loca +planning_id +service_id +ticket_id +is_unavaillable + +## ticket + +num: +first_name +last_name +email: +loca: + +## settings + +id: +name: +value: diff --git a/run.py b/run.py new file mode 100644 index 0000000..700f9a3 --- /dev/null +++ b/run.py @@ -0,0 +1,5 @@ + +from ITPlanning.app import create_app +app= create_app() +if __name__ == '__main__': + app.run()