first commit
This commit is contained in:
commit
a71fe2ecda
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
__pycache__
|
||||||
|
env
|
||||||
|
venv
|
9
ITPlanning/api/__init__.py
Normal file
9
ITPlanning/api/__init__.py
Normal file
@ -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 *
|
0
ITPlanning/api/appointement.py
Normal file
0
ITPlanning/api/appointement.py
Normal file
0
ITPlanning/api/planning.py
Normal file
0
ITPlanning/api/planning.py
Normal file
0
ITPlanning/api/service.py
Normal file
0
ITPlanning/api/service.py
Normal file
0
ITPlanning/api/ticket.py
Normal file
0
ITPlanning/api/ticket.py
Normal file
0
ITPlanning/api/user.py
Normal file
0
ITPlanning/api/user.py
Normal file
21
ITPlanning/app.py
Normal file
21
ITPlanning/app.py
Normal file
@ -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
|
27
ITPlanning/config.py
Normal file
27
ITPlanning/config.py
Normal file
@ -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
|
125
ITPlanning/db.py
Normal file
125
ITPlanning/db.py
Normal file
@ -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()
|
0
ITPlanning/frontend/__init__.py
Normal file
0
ITPlanning/frontend/__init__.py
Normal file
47
Readme.md
Executable file
47
Readme.md
Executable file
@ -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:
|
Loading…
Reference in New Issue
Block a user