modify DB
This commit is contained in:
parent
d91d0b398c
commit
f83b3d5f82
@ -4,8 +4,8 @@ from logging.handlers import TimedRotatingFileHandler
|
||||
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
|
||||
from ITPlanning.db import init_database
|
||||
from ITPlanning.config import IniConfig
|
||||
logger = logging.getLogger("ITPlanning")
|
||||
|
||||
|
@ -2,28 +2,30 @@
|
||||
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlparse, parse_qsl
|
||||
from pony.orm import Database, Required, Optional, Set, PrimaryKey, LongStr
|
||||
from pony.orm import Database, Required, Optional, Set, PrimaryKey, LongStr, Json
|
||||
from pony.orm import DatabaseError
|
||||
|
||||
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')
|
||||
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)
|
||||
working_plan = Required(Json)
|
||||
services = Set(Service)
|
||||
appointments = Set('Appointment')
|
||||
planners = Set('Planner')
|
||||
appointments = Set("Appointment")
|
||||
planners = Set("Planner")
|
||||
|
||||
|
||||
class Setting(db.Entity):
|
||||
@ -41,8 +43,8 @@ class Appointment(db.Entity):
|
||||
is_unavaillable = Required(bool)
|
||||
service = Required(Service)
|
||||
planning = Required(Planning)
|
||||
ticket = Optional('Ticket')
|
||||
customer = Optional('Customer')
|
||||
ticket = Optional("Ticket")
|
||||
customer = Optional("Customer")
|
||||
notes = Optional(LongStr)
|
||||
|
||||
|
||||
@ -54,7 +56,7 @@ class Customer(db.Entity):
|
||||
localisation = Optional(str)
|
||||
mobile_number = Optional(str)
|
||||
phone_number = Optional(str)
|
||||
tickets = Set('Ticket')
|
||||
tickets = Set("Ticket")
|
||||
appointments = Set(Appointment)
|
||||
notes = Optional(str)
|
||||
|
||||
@ -62,7 +64,7 @@ class Customer(db.Entity):
|
||||
class Ticket(db.Entity):
|
||||
id = PrimaryKey(int, auto=True)
|
||||
ref = Optional(str, unique=True)
|
||||
service_category = Required('Service_category')
|
||||
service_category = Required("Service_category")
|
||||
customer = Required(Customer)
|
||||
appointment = Required(Appointment)
|
||||
notes = Optional(str)
|
||||
@ -83,6 +85,7 @@ class Planner(Customer):
|
||||
password = Required(str)
|
||||
is_admin = Optional(bool)
|
||||
|
||||
|
||||
def parse_uri(database_uri):
|
||||
if not isinstance(database_uri, str):
|
||||
raise TypeError("Expecting a string")
|
||||
@ -122,10 +125,16 @@ def parse_uri(database_uri):
|
||||
)
|
||||
return dict()
|
||||
|
||||
|
||||
def init_database(database_uri):
|
||||
settings = parse_uri(database_uri)
|
||||
db.bind(**settings)
|
||||
db.generate_mapping(create_tables=True)
|
||||
db.generate_mapping(check_tables=False)
|
||||
try:
|
||||
db.check_tables()
|
||||
except DatabaseError:
|
||||
db.create_tables()
|
||||
|
||||
|
||||
def release_database():
|
||||
db.disconnect()
|
||||
|
Loading…
Reference in New Issue
Block a user