db_session = db_session form_class = model_form(Group, db_session, only=['name']) class WarehouseModule(ModelAdminModule): model = Warehouse db_session = db_session class CompanyModule(ModelAdminModule): model = Company db_session = db_session form_class = model_form(Company, db_session, only=['name']) admin = Admin(app, title="my business administration") security = admin.register_node('/security', 'security', 'security management') user_module = admin.register_module(UserModule, '/users', 'users', 'users', parent=security) group_module = admin.register_module(GroupModule, '/groups', 'groups', 'groups', parent=security) company_module = admin.register_module(CompanyModule, '/companies', 'companies', 'companies') warehouse_module = admin.register_module(WarehouseModule, '/warehouses', 'warehouses', 'warehouses', parent=company_module)
#!/bin/env python # -*- coding: utf-8 -*- ######################################################################### # File Name: flask_dashed_demo.py # Author: billowqiu # mail: [email protected] # Created Time: 2016-10-22 22:30:57 # Last Changed: 2016-10-22 22:32:12 ######################################################################### from flask import Flask from flask_dashed.admin import Admin app = Flask(__name__) admin = Admin(app) if __name__ == '__main__': app.run(debug=True)
db_session = db_session form_class = model_form(Group, db_session, only=['name']) class WarehouseModule(ModelAdminModule): model = Warehouse db_session = db_session class CompanyModule(ModelAdminModule): model = Company db_session = db_session form_class = model_form(Company, db_session, only=['name']) admin = Admin(app, title="my business administration") security = admin.register_node('/security', 'security', 'security management') user_module = admin.register_module(UserModule, '/users', 'users', 'users', parent=security) group_module = admin.register_module(GroupModule, '/groups', 'groups', 'groups', parent=security)
def create_app(self): app = Flask(__name__) self.admin = Admin(app) return app
def create_app(config=Config()): """Flask application factory.""" app = Flask(__name__) if config is not None: app.config.from_object(config) # override settings by environment variables if 'DEBUG' in os.environ: app.config['DEBUG'] = os.environ['DEBUG'].lower() == 'true' if 'SECRET_KEY' in os.environ: app.config['SECRET_KEY'] = os.environ['SECRET_KEY'] if 'SSL_ENABLE_REDIRECTS' in os.environ: app.config['SSL_ENABLE_REDIRECTS'] = os.environ['SSL_ENABLE_REDIRECTS'].lower() == 'true' if 'DATABASE_URL' in os.environ: app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL'] db.init_app(app) babel = Babel(app) login_manager.setup_app(app) oid.init_app(app) DebugToolbarExtension(app) app.register_blueprint(times) admin = Admin(app, url_prefix='/admin', title='Admin') admin.add_path_security('/', secure_admin_path) admin.add_path_security('/auth', secure_admin_auth_path) auth_node = admin.register_node('/auth', 'auth', 'Authentication') time_node = admin.register_node('/time_node', 'time_node', 'Times') admin.register_module(UserAdmin, '/users', 'users', 'Users', parent=auth_node) admin.register_module(CompanyAdmin, '/companies', 'companies', 'Companies', parent=time_node) admin.register_module(ProjectAdmin, '/projects', 'projects', 'Projects', parent=time_node) admin.register_module(TaskAdmin, '/tasks', 'tasks', 'Tasks', parent=time_node) admin.register_module(WorkingUnitAdmin, '/times', 'times', 'Working Times', parent=time_node) @login_manager.user_loader def load_user(userid): return User.query.get(int(userid)) @app.context_processor def inject_context(): version = os.environ.get('VERSION', 'devel') return dict(user=current_user, now=datetime.now(), version=version) @babel.localeselector def get_locale(): if hasattr(current_user, 'locale'): return current_user.locale return request.accept_languages.best_match(['en', 'ja', 'de']) return app
return user class GroupModule(ModelAdminModule): model = Group db_session = db_session form_class = model_form(Group, db_session, only=["name"]) class CompanyModule(ModelAdminModule): model = Company db_session = db_session form_class = model_form(Company, db_session, only=["name"]) admin = Admin(app, title="my business") security = admin.register_node("/security", "security", "security management") user_module = admin.register_module(UserModule, "/users", "users", "users", parent=security) group_module = admin.register_module(GroupModule, "/groups", "groups", "groups", parent=security) company_module = admin.register_module(CompanyModule, "/companies", "companies", "companies") @app.route("/") def redirect_to_admin(): return redirect("/admin") @app.errorhandler(401) def login_require(e): """HTTP<401>.""" return redirect("%s?next=%s" % (url_for("login"), request.path))
return user class GroupModule(ModelAdminModule): model = Group db_session = db_session form_class = model_form(Group, db_session, only=['name']) class CompanyModule(ModelAdminModule): model = Company db_session = db_session form_class = model_form(Company, db_session, only=['name']) admin = Admin(app, title="my business") security = admin.register_node('/security', 'security', 'security management') user_module = admin.register_module(UserModule, '/users', 'users', 'users', parent=security) group_module = admin.register_module(GroupModule, '/groups', 'groups', 'groups', parent=security) company_module = admin.register_module(CompanyModule, '/companies', 'companies', 'companies')
return user class GroupModule(ModelAdminModule): model = Group db_session = db_session form_class = model_form(Group, db_session, only=['name']) class CompanyModule(ModelAdminModule): model = Company db_session = db_session form_class = model_form(Company, db_session, only=['name']) admin = Admin(app, title="my business") security = admin.register_node('/security', 'security', 'security management') user_module = admin.register_module(UserModule, '/users', 'users', 'users', parent=security) group_module = admin.register_module(GroupModule, '/groups', 'groups', 'groups', parent=security) company_module = admin.register_module(CompanyModule, '/companies', 'companies', 'companies') @app.route('/') def redirect_to_admin(): return redirect('/admin') @app.errorhandler(401)