Beispiel #1
0
def create_app():
    #APP init
    app = Flask(__name__)
    app.config.from_object('config.DevelopmentConfig')
    #THEMES init
    Themes(app, app_identifier='app')
    #MAIL init
    from flask_mail import Mail
    mail = Mail(app)
    #DATABASE init
    from models import db
    db.init_app(app)
    #MIGRATIONS init
    migrate = Migrate(app, db)
    with app.app_context():
        #User init
        from flask_user import SQLAlchemyAdapter, UserManager
        from users import User
        db_adapter = SQLAlchemyAdapter(db, User)
        user_manager = UserManager(db_adapter, app)
        #db finalization
        db.create_all()
    #API - is for IOT, or mobile
    from models import DummyObject, DummyFile
    manager = flask_restless.APIManager(app, flask_sqlalchemy_db=db)
    manager.create_api(DummyObject)
    manager.create_api(DummyFile)
    #ADMIN - is for basic crud for trained users
    from admin import admin
    admin.init_app(app)
    #MEMBER VIEWS
    from member import MemberView
    MemberView.register(app)
    #upload example
    from flask_admin.contrib.fileadmin import FileAdmin
    path = os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'])
    admin.add_view(FileAdmin(path, '/uploads/', name='Uploads'))
    #sqlmodel example
    from flask_admin.contrib.sqla import ModelView
    admin.add_view(ModelView(DummyObject, db.session))
    #DASHBOARD - is for customer login pages
    #I'll have to make that custom
    return app, migrate
Beispiel #2
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

    from admin import admin
    from .admin.views import MyModelView,MyAdminIndexView
    from .models import Role, User, Post, Category, Tag
    admin.init_app(app, index_view=MyAdminIndexView())
    admin.add_view(MyModelView(Role, db.session))
    admin.add_view(MyModelView(User, db.session))
    admin.add_view(MyModelView(Post, db.session))
    admin.add_view(MyModelView(Category, db.session))
    admin.add_view(MyModelView(Tag, db.session))

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    return app
Beispiel #3
0
from admin import admin
from db import db
from models.user import User

nse = Nse()

app = Flask(__name__)

app.config.from_pyfile('configs.py')

admin.init_app(app)

db.init_app(app)


admin.add_view(ModelView(User, db.session))


def user_search():
    found = User.query.filter(
        User.id == request.form['user_id'],
        User.pw == request.form['user_pw'],
    ).first()
    if found:
        return found
    else:
        return None


def cookie():
    have_cookie = request.cookies
Beispiel #4
0
from config import config
from werkzeug.utils import import_string
from apps.models import db, Demo
from flask_babelex import Babel
from admin import admin, AdminUser, login, limiter
from apps.view import DemoView
from production import *

try:
    from local_settings import *
except Exception:
    pass

blueprints = ['routes:uploadApi']

admin.add_view(DemoView(name=u"测试demo"))


# 初始化app
def create_app(config_name):
    app = Flask(config_name)
    app.config.from_object(config[config_name])

    # 全局响应头
    @app.after_request
    def after_request(response):
        if "Access-Control-Allow-Origin" not in response.headers.keys():
            response.headers['Access-Control-Allow-Origin'] = '*'
        if request.method == 'OPTIONS':
            response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
Beispiel #5
0
from wechat.models import *
from flask_babelex import Babel
from admin import admin, MyModelView, AdminUser, login, limiter
from flask_admin.contrib.mongoengine import ModelView
from homework.view import ActModelView, StudentModelView
from wechat.view import OauthModelView
from production import *
from rsync_tasks import celery, redis
try:
    from local_settings import *
except Exception:
    pass

blueprints = ['routes:uploadApi']

admin.add_view(StudentModelView(name="APP合作"))
admin.add_view(ModelView(Consultation, name="官网首页"))
admin.add_view(ModelView(ClassInfo, name="学生预约课"))
admin.add_view(ActModelView(name="作业帮活动"))
admin.add_view(OauthModelView(name="微信多平台"))
admin.add_view(ModelView(Operation, name="访客记录"))


# 初始化app
def create_app(config_name):
    app = Flask(config_name)
    app.config.from_object(config[config_name])

    # 全局响应头
    @app.after_request
    def after_request(response):
Beispiel #6
0
    DROPZONE_MAX_FILES=1,
    DROPZONE_REDIRECT_VIEW='result',
    DROPZONE_PARALLEL_UPLOADS=1,
    DROPZONE_TIMEOUT=5 * 60 * 1000)
dropzone.init_app(app)
db.init_app(app)
model = None

# admin custom Modelview
table_list = [Herb, Location, Category, SimilarityGroup, News, Journal]
view_list = [
    HerbView, LocationView, CategoryView, SimilarityGroupView, NewsView,
    JournalView
]
for table, view in zip(table_list, view_list):
    admin.add_view(view(table, db.session))


@app.before_first_request
def load_model():
    model_name = './models/maybe_best_model.h5'
    global model
    if model is None:
        model = tasks.load_model(model_name)
    return 'Model loaded'


@app.route('/', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        if session.get('id') is None:
Beispiel #7
0
import flask

from config import Config

app = flask.Flask(__name__)

app.config.from_object(Config)

from database import User
from admin import admin, UserAdminView

admin.add_view(UserAdminView(User))

from bot_handlers import *

from web_hook_views import *