-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
69 lines (52 loc) · 2.18 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
# -*- coding: utf-8 -*-
import os
from flask.ext.script import Manager, Server, Command, prompt
from flask.ext.collect import Collect
from flask.ext.security.utils import encrypt_password
from app import app
class Setup(Command):
def _create_role(self, name, description=None):
return app.user_datastore.find_or_create_role(name=name, description=description)
def _create_super_user(self):
admin_role = self._create_role('admin', 'Admin role')
username = prompt('Admin username')
email = prompt('Admin email')
while app.user_datastore.find_user(email=email) is not None:
print 'Admin with email %s already exists' % email
email = prompt('Admin email')
password = prompt('Admin password')
app.user_datastore.create_user(name=username,
email=email,
password=encrypt_password(password),
roles=[admin_role])
def run(self):
self._create_super_user()
class ClearDB(Command):
def run(self):
from modules.catalog.models import Offer, Vendor, Category
from modules.dispatcher.models import Dispatcher
from modules.apishop.models import ApishopOffer, ApishopCategory, ApishopConfig
from utils.filesys import delete_file_by_path, check_file_exists
for model in (Offer, Vendor, Category, Dispatcher,
ApishopConfig, ApishopOffer, ApishopCategory):
model.objects.delete()
import shutil
if check_file_exists('media', relative=True):
path = os.path.join(app.config['BASE_DIR'], 'media')
shutil.rmtree(path)
if check_file_exists('data', relative=True):
path = os.path.join(app.config['BASE_DIR'], 'data')
shutil.rmtree(path)
print 'Database cleared'
manager = Manager(app)
manager.add_command('server', Server(
use_reloader = True,
use_debugger = True
))
manager.add_command('setup', Setup())
manager.add_command('cleardb', ClearDB())
collect = Collect()
collect.init_app(app)
collect.init_script(manager)
if __name__ == '__main__':
manager.run()