-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
109 lines (80 loc) · 2.82 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""
tardigrade.manage
~~~~~~~~~~~~~~~~~
This script provides some easy to use commands for
creating the database and running the development server.
Just type `python manage.py` to see the full list of commands.
:copyright: (c) 2013 by the Tardigrade Team.
:license: BSD, see LICENSE for more details.
"""
import os
import datetime
from flask import current_app
from flask.ext.script import Manager, Shell, Server
from tardigrade import create_app
from tardigrade.configs.development import DevelopmentConfig
from tardigrade.extensions import db
from tardigrade.models.user import User
from tardigrade.models.blog import Post, Comment
# Use the development configuration if available
app = create_app(DevelopmentConfig)
manager = Manager(app)
# Run local server
manager.add_command("runserver", Server("localhost", port=8080))
# Add interactive project shell
def make_shell_context():
return dict(app=current_app, db=db)
manager.add_command("shell", Shell(make_context=make_shell_context))
@manager.command
def initdb():
"""
Creates the database.
"""
db.create_all()
@manager.command
def createall():
"""
Creates the database with some example content
Attention: This will delete your whole database (if one exists)
"""
# Be sure that there isn't a existing one.
db.drop_all()
db.create_all()
user1 = User(username="test1", password="test", email="test@example.org",
theme=current_app.config["DEFAULT_THEME"],
language=current_app.config["BABEL_DEFAULT_LOCALE"],
is_admin=True)
user1.save()
user2 = User(username="test2", password="test", email="test2@example.org",
theme="bootstrap2", language="de", is_admin=False)
user2.save()
post = Post(title="Example 1", content="Example Content",
date_created=datetime.datetime.utcnow())
post.save(user1)
comment = Comment(content="Test Comment",
date_created=datetime.datetime.utcnow())
comment.save(user2, post)
@manager.command
def update_translations():
"""
Updates the translations
"""
os.system("pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot .")
os.system("pybabel update -i messages.pot -d tardigrade/translations")
os.unlink("messages.pot")
@manager.command
def init_translations(translation):
"""
Adds a new language to the translations
"""
os.system("pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot .")
os.system("pybabel init -i messages.pot -d tardigrade/translations -l " + translation)
os.unlink('messages.pot')
@manager.command
def compile_translations():
"""
Compiles the translations.
"""
os.system("pybabel compile -d tardigrade/translations")
if __name__ == "__main__":
manager.run()