forked from wolfv/SilverFlask
/
manage.py
executable file
·75 lines (62 loc) · 2.17 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
#!/usr/bin/env python
import os
from flask.ext.script import Manager, Server
from flask.ext.migrate import Migrate, MigrateCommand
from silverflask import create_app, db
from silverflask.models import User, Page
# default to dev config because no one should use this in
# production anyway
env = os.environ.get('SILVERFLASK_ENV', 'dev')
app = create_app('silverflask.settings.%sConfig' % env.capitalize(), env=env)
manager = Manager(app)
manager.add_command("server", Server())
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
@manager.shell
def make_shell_context():
""" Creates a python REPL with several default imports
in the context of the app
"""
return dict(app=app, db=db, User=User)
@manager.command
def createdb():
"""
Creates a database with the defined models
and also adds the default records that are needed for the CMS:
Admin User, Admin Role, Default first page, and stuff
"""
db.create_all()
from silverflask.models import User
from silverflask.models.User import Role
if not len(Role.query.all()):
admin_role = Role("admin", "Admin has all privileges")
db.session.add(admin_role)
db.session.commit()
if not len(User.query.all()):
# create standard user
u = User("admin", "admin")
u.firstname = "Default"
u.lastname = "Admin"
u.email = "admin"
db.session.add(u)
admin_role = Role.query.filter(Role.name == "admin").first()
u.roles.append(admin_role)
db.session.commit()
from silverflask.models import SiteConfig
if not len(SiteConfig.query.all()):
sc = SiteConfig()
sc.title = "Your SilverFlask Website"
sc.tagline = "This is a default installation"
db.session.add(sc)
db.session.commit()
if not len(Page.query.all()):
page = Page()
page.content = "<p>Please proceed to the admin interface at <a href='/admin'>admin</a>!</p>"
page.name = "home"
page.urlsegment = "home"
db.session.add(page)
db.session.commit()
page.mark_as_published()
db.session.commit()
if __name__ == "__main__":
manager.run()