-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanage.py
More file actions
97 lines (80 loc) · 2.57 KB
/
manage.py
File metadata and controls
97 lines (80 loc) · 2.57 KB
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
from flask_script import Manager
from flask import current_app
from flaskproject import app
from flaskproject.core import db
from flaskproject.users.models import User
from flaskproject.events.models import Category, Event, Status
from datetime import datetime, date
from sqlalchemy import exc
manager = Manager(app)
@manager.command
def hello():
print("hello")
@manager.command
def populate():
status_active = Status(name='Active', status_code=100)
status_inactive = Status(name='Inactive', status_code=200)
status_cancelled = Status(name='Cancelled', status_code=300)
status_completed = Status(name='Completed', status_code=400)
status_archived = Status(name='Archived', status_code=500)
db.session.add(status_active)
db.session.add(status_inactive)
db.session.add(status_cancelled)
db.session.add(status_completed)
db.session.add(status_archived)
db.session.commit()
@manager.command
def create_test_users():
test_user = User(
email='user@test.com',
password='123456',
active=True,
birth_date=date.today(),
last_name='Test',
first_name='User')
test_user2 = User(
email='user2@test.com',
password='123456',
active=True,
birth_date=date.today(),
last_name='Test',
first_name='User2')
test_user3 = User(
email='user3@test.com',
password='123456',
active=True,
birth_date=date.today(),
last_name='Test',
first_name='User3')
test_user4 = User(
email='user4@test.com',
password='123456',
active=True,
birth_date=date.today(),
last_name='Test',
first_name='User4')
db.session.add(test_user)
db.session.add(test_user2)
db.session.add(test_user3)
db.session.add(test_user4)
db.session.commit()
## event_status_check has been automated but will remain here for reference
@manager.command
def event_status_check():
# Check for events with status_id 100, active status.
events = Event.query.filter_by(status_id=100).all()
for event in events:
# If the event end_date has expired, change its status_id
# to 400, completed status.
if event.end_date <= datetime.utcnow():
event.status_id = 400
try:
db.session.add(event)
print('Success')
except exc.SQLAlchemyError as e:
current_app.logger.error(e)
print('Error')
# Commit the db session back.
db.session.commit()
if __name__ == "__main__":
manager.run()