-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
executable file
·62 lines (46 loc) · 1.36 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
#!/usr/bin/env python
from flask.ext.script import Manager, Shell, Server, prompt_bool
from diary import app, db, models
manager = Manager(app)
manager.add_command("runserver", Server())
manager.add_command("shell", Shell())
@manager.command
def drop():
"Drops database tables"
if prompt_bool("Are you sure you want to lose all your data"):
db.drop_all()
@manager.command
def create():
"Creates database tables from sqlalchemy models"
db.create_all()
@manager.command
def recreate():
"Recreates database tables (same as issuing 'drop' and then 'create')"
drop()
create()
populate()
@manager.command
def populate():
"Populate database with default data"
user1 = models.User("Jelle", "de Jong", "jelle@hoest.nl", "123")
user2 = models.User("Suzanne", "Beugelaar", "suzanne@hoest.nl", "123")
db.session.add(user1)
db.session.add(user2)
db.session.commit()
diary = models.Diary("Mijn dagboek")
diary.owner_id = user1.id
diary.users.append(user1)
diary.users.append(user2)
db.session.add(diary)
diary = models.Diary("Suus d'r dagboek")
diary.owner_id = user2.id
diary.users.append(user2)
db.session.add(diary)
db.session.commit()
for i in range(1, 25, 1):
post = models.Post(diary.id, "Bericht %s" % i)
post.user_id = user1.id
post.body = "Bericht %s" % i
db.session.add(post)
db.session.commit()
manager.run()