This repository has been archived by the owner on Dec 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
85 lines (67 loc) · 1.83 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
from flask_script import Manager, prompt, prompt_pass
from fernet import app, db
from fernet.models import Tag, User, UserTag
manager = Manager(app)
@manager.command
def create_db():
"""Create database and all tables."""
db.create_all()
@manager.command
def create_tags():
"""Create a set of standard tags."""
tags = ['Webmaster',
'Aktiv',
'Sopran 1',
'Sopran 2',
'Alt 1',
'Alt 2',
'Tenor 1',
'Tenor 2',
'Bas 1',
'Bas 2',
'Sånggrupp 1',
'Sånggrupp 2',
'Sånggrupp 3',
'Ordförande',
'Vice ordförande',
'Sekreterare',
'PRoletär',
'Kassör',
'Qlubbmästare',
'Notfisqual']
for tag_name in tags:
tag = Tag(name=tag_name)
db.session.add(tag)
db.session.commit()
@manager.command
def create_webmaster():
"""Create a user with webmaster tag.
A webmaster tag has had to be created prior to running this
command, either manually or with create_tags().
"""
user = User(
first_name = prompt('First name'),
last_name = prompt('Last name'),
email = prompt('Email'),
password = prompt_pass('Password')
)
tag = Tag.query.filter_by(name='Webmaster').one()
usertag = UserTag()
usertag.tag = tag
user.tags.append(usertag)
db.session.add(user)
db.session.commit()
@manager.command
def full_setup():
"""First time setup of database."""
print('Creating database...')
create_db()
print('Done!')
print('Creating tags...')
create_tags()
print('Done!')
print('Creating webmaster user...')
create_webmaster()
print('Done, setup complete.')
if __name__ == "__main__":
manager.run()