-
Notifications
You must be signed in to change notification settings - Fork 1
/
manager.py
116 lines (94 loc) · 4.74 KB
/
manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
from flask.ext.script import Manager
from webserver import app, db
manager = Manager(app)
@manager.command
def install():
# Create database
db.drop_all()
db.create_all()
print("...Database successfuly installed")
# Add fixtures
add_country()
add_state_order()
@manager.command
def install_with_data():
# Create database with fixtures
install()
# Add restaurateurs
from webserver.models import Restaurateur, Country
ct1 = db.session.query(Country).filter(Country.name=="Canada").one()
rs1 = Restaurateur(firstname="Valentino", lastname="Rossi", mail="rossi@ducati.it", password="quarantesix", phone="123-456-7890", address="1001 Rue Notre Dame", city="Montreal", zipcode="H3S 1Z1", country=ct1)
rs2 = Restaurateur(firstname="Fernando", lastname="Alonso", mail="alonso@ferrari.it", password="asturie", phone="123-456-7890", address="1001 Rue Notre Dame", city="Montreal", zipcode="H3S 1Z1", country=ct1)
rs3 = Restaurateur(firstname="Marcel", lastname="Proust", mail="restau", password="rateur", phone="123-456-7890", address="1001 Rue Notre Dame", city="Montreal", zipcode="H3S 1Z1", country=ct1)
db.session.add(rs1)
db.session.add(rs2)
db.session.add(rs3)
# Add entrepreneurs
from webserver.models import Entrepreneur
e1 = Entrepreneur(firstname="Jay", lastname="UnNom", mail="un@mail.com", password="passwd", phone="123-456-7890", address="1001 Rue Notre Dame", city="Montreal", zipcode="H3S 1Z1", country=ct1)
import datetime
e2 = Entrepreneur(firstname="Entre", lastname="Preneur", mail="entre", password="preneur", phone="123-456-7890", address="1001 Rue Notre Dame", city="Montreal", zipcode="H3S 1Z1", country=ct1, birthdate=datetime.datetime(2010, 10, 10))
db.session.add(e1)
db.session.add(e2)
# Add clients
from webserver.models import Client
c1 = Client(firstname="Yvon", lastname="Gagner", mail="gagner@ducati.it", password="passwdc1", phone="123-456-7890", address="1001 Rue Notre Dame", city="Montreal", zipcode="H3S 1Z1", country=ct1)
c2 = Client(firstname="Leo", lastname="Pard", mail="pard@ferrari.it", password="passwdc2", phone="123-456-7890", address="1001 Rue Notre Dame", city="Montreal", zipcode="H3S 1Z1", country=ct1)
db.session.add(c1)
db.session.add(c2)
# Add restaurants
from webserver.models import Restaurant
r1 = Restaurant(name="Subway", phone="514-444-4444", address="1001 Ste-Catherine", city="Montreal", zipcode="H3K 3P2", cooking_type="Fastfood")
r2 = Restaurant(name="McDonalds", phone="514-444-4444", address="4301 St-Denis", city="Montreal", zipcode="H2S 1R4", cooking_type="Fastfood")
r3 = Restaurant(name="La Banquise", phone="514-444-4444", address="2167 St-Denis", city="Montreal", zipcode="H4P 2R2", cooking_type="Poutine")
r4 = Restaurant(name="Le Duc de Lorraine", phone="514-444-4444", address="2983 St-Denis", city="Montreal", zipcode="H1S 1R2", cooking_type="Gastronomie française")
r5 = Restaurant(name="La Plazza", phone="514-444-4444", address="1893 St-Denis", city="Montreal", zipcode="H4C 2R1", restaurateur=rs3, cooking_type="Plats italiens")
db.session.add(r1)
db.session.add(r2)
db.session.add(r3)
db.session.add(r4)
db.session.add(r5)
# Add menus
from webserver.models import Menu
m1 = Menu(name="Lunch", restaurant_id=1)
db.session.add(m1)
db.session.flush()
# Add dishes
from webserver.models import Dish
d1 = Dish(name="Frites", description="Avec des pomme de terre fraiche", price=4.99, menu_id=1)
d2 = Dish(name="Bigmac", description="Avec du boeuf tué la veille", price=6.99, menu_id=1)
d3 = Dish(name="Coca-Cola", description="Du vrai", price=1.99, menu_id=1)
d4 = Dish(name="Fanta", description="Du vrai", price=1.99, menu_id=1)
db.session.add(d1)
db.session.add(d2)
db.session.add(d3)
db.session.add(d4)
db.session.commit()
print("...Datas test successfully added")
def add_country():
""" Add country """
from webserver.models import Country
c1 = Country(name="Canada")
c2 = Country(name="United States")
db.session.add(c1)
db.session.add(c2)
db.session.commit()
print("...Countries successfully added")
def add_state_order():
""" Add country """
from webserver.models import StateOrder
so1 = StateOrder(name="En attente")
so2 = StateOrder(name="En préparation")
so3 = StateOrder(name="Prête")
so4 = StateOrder(name="En cours de livraison")
so5 = StateOrder(name="Livrée")
db.session.add(so1)
db.session.add(so2)
db.session.add(so3)
db.session.add(so4)
db.session.add(so5)
db.session.commit()
print("...States order successfully added")
if __name__ == "__main__":
manager.run()