-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
98 lines (87 loc) · 2.71 KB
/
manage.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
from livereload import Server
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand
from getpass import getpass
from werkzeug.security import generate_password_hash
from app import app, db
from app.models import Brand, Category, Subcategory, Product
from app.models import User
manager = Manager(app)
@manager.command
def run():
server = Server(app.wsgi_app)
server.watch('app/*.py')
server.watch('app/templates/*.html')
server.watch('app/static/css/*.css')
server.watch('app/static/js/*.js')
server.serve(host='0.0.0.0')
@manager.command
def seed():
''' Brands '''
for brand_name in [
'Dior',
'BY TERRY',
'Too Faced',
'Charlotte Tillbury'
]:
brand = Brand(name=brand_name)
db.session.add(brand)
db.session.commit()
''' Category '''
for category_name in [
'Blush',
'Bronzer',
'Concealer',
'Eyes',
'Highlighters',
'Lips',
'Palettes',
'Skincare'
]:
category = Category(name=category_name)
db.session.add(category)
db.session.commit()
''' Subcategory '''
eyes = Category.query.filter_by(name="Eyes").first()
for subcategory_name in ['Eyeliner', 'Mascara']:
subcategory = Subcategory(name=subcategory_name)
eyes.subcategories.append(subcategory)
db.session.add(subcategory)
db.session.commit()
@manager.command
def add_user():
name = raw_input("Name: ")
if User.query.filter_by(username=name).first():
print "User already exists."
return
password = ""
password_2 = ""
while not (password and password_2) or password != password_2:
password = getpass("Password: ")
password_2 = getpass("Re-enter password: ")
user = User(username=name, password=generate_password_hash(password))
db.session.add(user)
db.session.commit()
@manager.command
def reset_pw():
name = raw_input("Name: ")
user = User.query.filter_by(username=name).first()
if user:
password = ""
password_2 = ""
while not (password and password_2) or password != password_2:
password = getpass("Password: ")
password_2 = getpass("Re-enter password: ")
user.password = password=generate_password_hash(password)
db.session.add(user)
db.session.commit()
else:
print "Could not find user {}.".format(name)
return
class DB(object):
def __init__(self, metadata):
self.metadata = metadata
migrate = Migrate(app, DB(db.metadata))
manager.add_command('db', MigrateCommand)
if __name__ == "__main__":
manager.run()