-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
51 lines (43 loc) · 1.43 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
# manage.py
# Jake Malley
# Uses flask-script to provide a management script.
# Flask Imports
from flask.ext.script import Manager
from flask.ext.script import Server
from flask.ext.migrate import Migrate
from flask.ext.migrate import MigrateCommand
# Application Imports
from peri2organise import app
from peri2organise import db
from peri2organise.models import User, Parent, Lesson, Room, Instrument, UserLessonAssociation
# Create a Manager object.
manager = Manager(app)
# Create a Migration object.
migrate = Migrate(app,db)
# Check to see if configuration has been set for development server.
try:
DEVELOPMENT_SERVER_HOST = app.config['DEVELOPMENT_SERVER_HOST']
except KeyError:
DEVELOPMENT_SERVER_HOST = '127.0.0.1'
try:
DEVELOPMENT_SERVER_PORT = app.config['DEVELOPMENT_SERVER_PORT']
except KeyError:
DEVELOPMENT_SERVER_PORT = 5000
# Create a Server object.
server = Server(host=DEVELOPMENT_SERVER_HOST, port=DEVELOPMENT_SERVER_PORT)
# Add command for running the server.
manager.add_command('runserver', server)
# Add migrate command to the manager.
manager.add_command('db', MigrateCommand)
# Command to create the database.
@manager.command
def create_db():
"""
Command to create the database.
Use this command to create the all the tables from the models in models.py.
(Alternatively Flask-Migrate can be used.)
"""
db.create_all()
if __name__ == '__main__':
# Run the manager.
manager.run()