コード例 #1
0
ファイル: testUser.py プロジェクト: nerostamas/python-flask
 def setUp(self):
     app.config.update({
         "TESTING": True,
         "TEMP_DB": True,
         "WTF_CSRF_ENABLED": False,
         "DEBUG": False
     })
     self.app = app.test_client()
     self.assertEqual(app.debug, False)
     db.disconnect()
     db.connect('sample_test')
     User.drop_collection()
     app.register_blueprint(auth_api, url_prefix='/api/auth')
     app.register_blueprint(user_api, url_prefix='/api/user')
     self.supporter = User(username="******",
                           password="******",
                           role="SUPPORTER")
     self.supporter.hash_password()
     self.supporter.save()
     self.user = User(username="******", password="******", role="USER")
     self.user.hash_password()
     self.user.save()
コード例 #2
0
from flask import redirect, url_for, render_template
from app.config import app
from app.controllers.main import main
from app.controllers.div import div

# =================== Blueprints ===================
app.register_blueprint(main)
app.register_blueprint(div)


# ======================== PAGES =========================
@app.route('/')
def start():
    return redirect(url_for('main.signup'))


@app.errorhandler(403)
def page_403(err):
    return render_template('/errors/403.html'), 403


@app.errorhandler(404)
def page_404(err):
    return render_template('/errors/404.html'), 404


@app.errorhandler(500)
def page_505(err):
    return render_template('/errors/500.html'), 500
コード例 #3
0
ファイル: run.py プロジェクト: zcs-seu/wxnacy.github.io
views_path = '{}/app/views/'.format(os.getcwd())
logger.debug(views_path)
views_files = list(
    filter(
        lambda x: not x.startswith('__') and '.swp' not in x and '.swo' not in
        x, os.listdir(views_path)))
for path in views_files:
    module_name = 'app.views.{}'.format(path[0:-3])
    views_module = importlib.import_module(module_name)
    for name, obj in inspect.getmembers(views_module):
        if obj.__class__.__name__ == 'Blueprint':
            url_prefix = '/api/v1'
            if name == 'admin_bp':
                url_prefix = '/admin'
            app.register_blueprint(obj, url_prefix=url_prefix)

# restless
manager = APIManager(app, flask_sqlalchemy_db=db)
restful_params = dict(methods=['GET'],
                      results_per_page=10,
                      allow_functions=True,
                      url_prefix='/api/restless')

for name, obj in inspect.getmembers(models):
    if inspect.isclass(obj) and '__tablename__' in dir(obj):
        manager.create_api(obj, **restful_params)
''' for graphql'''
app.add_url_rule('/api/graphql',
                 view_func=GraphQLView.as_view('graphql',
                                               schema=schema,
コード例 #4
0
from app.models import db
from app.config import app

from app.controller_api.Users import app_users
from app.controller_api.Goods import app_goods
from app.controller_api.HistoryOrders import app_history_orders
from app.controller_api.OnSales import app_on_sales
from app.controller_api.PurchaseOrders import app_purchase_orders
from app.controller_api.Stocks import app_stocks
from app.controller_api.Suppliers import app_suppliers
from app.controller_api.Statistic import app_statistic

app.register_blueprint(app_users, url_prefix="/Users")
app.register_blueprint(app_goods, url_prefix="/Goods")
app.register_blueprint(app_history_orders, url_prefix="/HistoryOrders")
app.register_blueprint(app_on_sales, url_prefix="/OnSales")
app.register_blueprint(app_purchase_orders, url_prefix="/PurchaseOrders")
app.register_blueprint(app_stocks, url_prefix="/Stocks")
app.register_blueprint(app_suppliers, url_prefix="/Suppliers")
app.register_blueprint(app_statistic, url_prefix="/Statistic")
コード例 #5
0
ファイル: run.py プロジェクト: zuowei593/study
import traceback
import inspect
import importlib
import os

'''=================== for blueprint ============================='''
views_path = '{}/app/views/'.format(os.getcwd())
views_files = list(filter(lambda x: not x.startswith('__'),
    os.listdir(views_path)))
for path in views_files:
    module_name = 'app.views.{}'.format(path[0:-3])
    print(module_name)
    views_module = importlib.import_module(module_name)
    for name, obj in inspect.getmembers(views_module):
        if obj.__class__.__name__ == 'Blueprint':
            app.register_blueprint(obj, url_prefix = '/api')

'''=================== for restless ============================='''
manager = APIManager(app, flask_sqlalchemy_db=db)
screen_api_params = dict(
    methods=['GET'],
    results_per_page=10,
    allow_functions=True,
    url_prefix = '/restless'
)

for name, obj in inspect.getmembers(models):
    if inspect.isclass(obj) and hasattr(obj, '__tablename__'):
        manager.create_api(obj, **screen_api_params)

コード例 #6
0
ファイル: run.py プロジェクト: nerostamas/python-flask
import os

from flask import send_from_directory

from app.config import app

# router
from controllers.authentication import auth_api
from controllers.ticket import ticket_api
from controllers.users import user_api
from controllers.comment import comment_api

# register router
app.register_blueprint(auth_api, url_prefix='/api/auth')
app.register_blueprint(user_api, url_prefix='/api/users')
app.register_blueprint(ticket_api, url_prefix='/api/ticket')
app.register_blueprint(comment_api, url_prefix='/api/comment')


@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def serve(path):
    if path != "" and os.path.exists(app.static_folder + '/' + path):
        return send_from_directory(app.static_folder, path)
    else:
        return send_from_directory(app.static_folder, 'index.html')


if __name__ == '__main__':
    app.run()