forked from dcrasch/react-flask-shop-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
76 lines (61 loc) · 1.93 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
# -*- coding: utf-8 -*-
import sys
import os
from flask import url_for
from flask.ext.script import Manager
from rfs.app import create_app
app = create_app(config=os.environ.get('APP_CONFIG', 'rfs.config.DevelopmentConfig'))
manager = Manager(app)
@manager.command
def create_all():
from rfs.app import db
db.create_all()
@manager.command
def create_data():
from rfs.app import db
from rfs.products.models import Product, ProductVariant
product = Product()
product.title = "Product 1"
product.description = "Product 1 description"
productvariant = ProductVariant()
productvariant.title="ProductVariant 1"
productvariant.description="ProductVariant 1 description"
productvariant.price = 100
productvariant.sku = "sku 1"
productvariant.inventory= 10
productvariant.mainproduct=product
db.session.add(product)
db.session.add(productvariant)
db.session.commit()
@manager.command
def run():
"""
Run the application. If the environment variable `APP_CONFIG` is not set,
then the default development config `flaskplate.config.DevelopmentConfig`
will be used.
To set the path to a different development config:
export APP_CONFIG=python.path.to.my.ConfigClass
python manage.py run
"""
app.run()
@manager.command
def assets():
from flask.ext.assets import ManageAssets
from rfs.app import assets
ManageAssets(assets)
@manager.command
def list_routes():
import urllib
output = []
for rule in app.url_map.iter_rules():
options = {}
for arg in rule.arguments:
options[arg] = "[{0}]".format(arg)
methods = ','.join(rule.methods)
url = url_for(rule.endpoint, **options)
line = urllib.parse.unquote("{:50s} {:20s} {}".format(rule.endpoint, methods, url))
output.append(line)
for line in sorted(output):
print(line)
if __name__ == "__main__":
manager.run()