fixing the db script
This commit is contained in:
parent
8a975d5d44
commit
e1b35de786
3 changed files with 67 additions and 34 deletions
|
@ -2,21 +2,23 @@ from models import *
|
||||||
from app import db
|
from app import db
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
db.drop_all()
|
|
||||||
db.create_all()
|
|
||||||
|
|
||||||
feli = User()
|
def recreate_db():
|
||||||
feli.configure("feliciaan", True, 0)
|
db.drop_all()
|
||||||
db.session.add(feli)
|
db.create_all()
|
||||||
|
|
||||||
destro = User()
|
feli = User()
|
||||||
destro.configure('destro', True, 0)
|
feli.configure("feliciaan", True, 0)
|
||||||
db.session.add(destro)
|
db.session.add(feli)
|
||||||
|
|
||||||
iepoev = User()
|
destro = User()
|
||||||
iepoev.configure('iepoev', True, 1)
|
destro.configure('destro', True, 0)
|
||||||
db.session.add(iepoev)
|
db.session.add(destro)
|
||||||
# To future developers, add yourself here
|
|
||||||
|
iepoev = User()
|
||||||
|
iepoev.configure('iepoev', True, 1)
|
||||||
|
db.session.add(iepoev)
|
||||||
|
# To future developers, add yourself here
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# Chinees autogenerate #
|
# Chinees autogenerate #
|
||||||
|
@ -28,21 +30,23 @@ sauzen = ["Balisaus", "Yu siang saus", "Gon boa saus", "Curry saus", "Oestersaus
|
||||||
specials = ["Kippenbolletjes zoetzuur", "varkenbolletjes zoetzuur", "Nazi Babi Pangang", "Bami Babi Pangang",
|
specials = ["Kippenbolletjes zoetzuur", "varkenbolletjes zoetzuur", "Nazi Babi Pangang", "Bami Babi Pangang",
|
||||||
"Diverse groenten met bami(Vegetarisch)", "Diverse groenten met nazi(Vegetarisch)"]
|
"Diverse groenten met bami(Vegetarisch)", "Diverse groenten met nazi(Vegetarisch)"]
|
||||||
|
|
||||||
chinees = Location()
|
|
||||||
chinees.configure("Oceans's Garden", "Zwijnaardsesteenweg 399 9000 Gent, tel: 09/222.72.74", "http://oceangarden.byethost3.com/studentenmenus.html")
|
|
||||||
db.session.add(chinees)
|
|
||||||
|
|
||||||
def chinees_create_entry(zetmeel, vlees="", saus=""):
|
def add_chinees():
|
||||||
entry = Product()
|
chinees = Location()
|
||||||
entry.configure(chinees, "{} {} {}".format(zetmeel, vlees, saus).rstrip(), 550)
|
chinees.configure("Oceans's Garden", "Zwijnaardsesteenweg 399 9000 Gent, tel: 09/222.72.74", "http://oceangarden.byethost3.com/studentenmenus.html")
|
||||||
db.session.add(entry)
|
db.session.add(chinees)
|
||||||
|
|
||||||
|
def chinees_create_entry(zetmeel, vlees="", saus=""):
|
||||||
|
entry = Product()
|
||||||
|
entry.configure(chinees, "{} {} {}".format(zetmeel, vlees, saus).rstrip(), 550)
|
||||||
|
db.session.add(entry)
|
||||||
|
|
||||||
for zetmeel, vlees, saus in product(zetmelen, vlezen, sauzen):
|
for zetmeel, vlees, saus in product(zetmelen, vlezen, sauzen):
|
||||||
chinees_create_entry(zetmeel, vlees, saus)
|
chinees_create_entry(zetmeel, vlees, saus)
|
||||||
|
|
||||||
|
for special in specials:
|
||||||
|
chinees_create_entry(special)
|
||||||
|
|
||||||
for special in specials:
|
|
||||||
chinees_create_entry(special)
|
|
||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
|
@ -53,14 +57,42 @@ pizzas = ['Bolognese de luxe', 'Hawaï', 'Popeye', 'Pepperoni', 'Seafood', 'Hot
|
||||||
'Green fiësta', 'Chicken bbq', 'Funky chicken', 'Veggie', 'Meat lovers', 'Scampi mampi', 'Tabasco',
|
'Green fiësta', 'Chicken bbq', 'Funky chicken', 'Veggie', 'Meat lovers', 'Scampi mampi', 'Tabasco',
|
||||||
'Chicken time', 'Meatballs', 'Tuna', 'Anchovy', 'Calzone', 'Bbq meatballs', 'Creamy chicken', 'Hot bolognese']
|
'Chicken time', 'Meatballs', 'Tuna', 'Anchovy', 'Calzone', 'Bbq meatballs', 'Creamy chicken', 'Hot bolognese']
|
||||||
|
|
||||||
simpizza = Location()
|
|
||||||
simpizza.configure("Sim-pizza", "De Pintelaan 252 9000 Gent, tel: 09/321.02.00", "http://simpizza.be")
|
|
||||||
db.session.add(simpizza)
|
|
||||||
|
|
||||||
for pizza in pizzas:
|
def add_simpizza():
|
||||||
entry = Product()
|
simpizza = Location()
|
||||||
entry.configure(simpizza, pizza, 1195)
|
simpizza.configure("Sim-pizza", "De Pintelaan 252 9000 Gent, tel: 09/321.02.00", "http://simpizza.be")
|
||||||
db.session.add(entry)
|
db.session.add(simpizza)
|
||||||
|
|
||||||
# commit all the things
|
for pizza in pizzas:
|
||||||
db.session.commit()
|
entry = Product()
|
||||||
|
entry.configure(simpizza, pizza, 1195)
|
||||||
|
db.session.add(entry)
|
||||||
|
|
||||||
|
|
||||||
|
def commit():
|
||||||
|
# commit all the things
|
||||||
|
db.session.commit()
|
||||||
|
print("Committing successful")
|
||||||
|
|
||||||
|
locations = {'Ocean\'s Garden': add_chinees, 'Sim-pizza': add_simpizza}
|
||||||
|
|
||||||
|
print('Create database script!')
|
||||||
|
print('=======================\n\n')
|
||||||
|
|
||||||
|
db_key = 'recreate this database now!'
|
||||||
|
input_db = input("To recreate the db type: '" + db_key + "'")
|
||||||
|
if db_key in input_db:
|
||||||
|
print("recreating the database!")
|
||||||
|
recreate_db()
|
||||||
|
for location in locations.values():
|
||||||
|
location()
|
||||||
|
commit()
|
||||||
|
else:
|
||||||
|
print("not recreating the database!")
|
||||||
|
# DID NOT RECREATE ASK IF YOU WANT TO RECREATE THE NEXT ONES
|
||||||
|
for name, function in locations.items():
|
||||||
|
add_location = input("Do you want to add " + name + "? Press: 'Y'")
|
||||||
|
print("Adding " + name)
|
||||||
|
if add_location.lower() in ['y', 'yes']:
|
||||||
|
function()
|
||||||
|
commit()
|
|
@ -7,7 +7,7 @@ from app import db
|
||||||
# Create database models
|
# Create database models
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
username = db.Column(db.String(80), unique=True)
|
username = db.Column(db.String(80), unique=True, nullable=False)
|
||||||
admin = db.Column(db.Boolean)
|
admin = db.Column(db.Boolean)
|
||||||
bias = db.Column(db.Integer)
|
bias = db.Column(db.Integer)
|
||||||
runs = db.relationship('Order', backref='courrier', lazy='dynamic')
|
runs = db.relationship('Order', backref='courrier', lazy='dynamic')
|
||||||
|
@ -124,7 +124,7 @@ class Order(db.Model):
|
||||||
class OrderItem(db.Model):
|
class OrderItem(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
||||||
order_id = db.Column(db.Integer, db.ForeignKey('order.id'))
|
order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False)
|
||||||
product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
|
product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
|
||||||
name = db.Column(db.String(120))
|
name = db.Column(db.String(120))
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ def handle404(e):
|
||||||
def handle401(e):
|
def handle401(e):
|
||||||
return render_template('errors/401.html'), 401
|
return render_template('errors/401.html'), 401
|
||||||
|
|
||||||
|
‡
|
||||||
class AnonymouseUser:
|
class AnonymouseUser:
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in a new issue