Python flask_admin 模块,Admin() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用flask_admin.Admin()

项目:prayerbot    作者:c4tk    | 项目源码 | 文件源码
def create_app(sqlite_path='sqlite:///intent.db'):
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = sqlite_path
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['BASIC_AUTH_USERNAME'] = 'john'
    app.config['BASIC_AUTH_PASSWORD'] = 'matrix'
    babel = Babel(app)
    admin = Admin(app, name='PrayerBot', template_mode='bootstrap3')
    db.init_app(app)
    register_admin(admin, app)
    app.app_context().push()

    app.add_url_rule('/webhook', view_func=WebhookAPI.as_view('webhook'))
    app.add_url_rule('/privacy', view_func=PrivacyPolicy.as_view('privacy'))

    if os.environ.get('ACCESS_TOKEN'):
        utils.send_greeting_text_config()

    db.create_all()
    db.session.commit()
    db.session.autoflush = True
    db.session.autocommit = True

    return app
项目:pongr    作者:wseaton    | 项目源码 | 文件源码
def create_app(cache):
    app = Flask(__name__, static_url_path='')
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///pong.db'
    cache.init_app(app)
    compress.init_app(app)
    Bootstrap(app)

    db.init_app(app)
    with app.app_context():
        db.create_all()

        admin = Admin(app, name='pongr', template_mode='bootstrap3')
        admin.add_view(GameView(Game, db.session))
        admin.add_view(DoublesView(DoublesGame, db.session))
        admin.add_view(PlayerView(Player, db.session))
        admin.add_view(RatingsView(Ratings, db.session))

    return app, cache
项目:qpd    作者:omaciel    | 项目源码 | 文件源码
def configure_admin(app, db):
    admin.init_app(app)
    # Admin pages
    admin.add_view(
        BaseView(OperatingSystem, db.session, endpoint='operatingsystems'))
    admin.add_view(BaseView(Project, db.session, endpoint='projects'))
    admin.add_view(ReleaseView(Release, db.session, endpoint='releases'))
    admin.add_view(TestRunView(TestRun, db.session, endpoint='testruns'))

    # security
    admin.add_view(BaseView(User, db.session, endpoint='users',
                            category='Auth'))
    admin.add_view(BaseView(Role, db.session, endpoint='roles',
                            category='Auth'))

    @app.security.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
            get_url=url_for
        )
项目:cookiecutter-flask    作者:on3iro    | 项目源码 | 文件源码
def init_admin(app):
    """Adds ModelViews to flask-admin."""
    admin = Admin(
        app,
        name="{{cookiecutter.app_name}}-Admin",
        index_view=MyAdminIndexView(),
        base_template='my_master.html',
        endpoint="admin"
    )
    admin.add_view(MyModelView(Role, db.session))
    admin.add_view(UserView(User, db.session))

    return None


####################
# Helper functions #
####################
项目:quokka_ng    作者:rochacbruno    | 项目源码 | 文件源码
def create_admin(app=None):
    """Admin factory"""
    index_view = IndexView()
    return QuokkaAdmin(
        app,
        index_view=index_view,
        template_mode=app.config.get('FLASK_ADMIN_TEMPLATE_MODE')
    )
项目:quokka_ng    作者:rochacbruno    | 项目源码 | 文件源码
def configure_admin(app, admin=None):  # noqa
    """Configure admin extensions"""
    admin = admin or create_admin(app)

    custom_index = app.config.get('ADMIN_INDEX_VIEW')
    if custom_index:
        admin.index_view = import_string(custom_index)()
        if isinstance(admin._views[0], IndexView):  # noqa
            del admin._views[0]  # noqa
        admin._views.insert(0, admin.index_view)  # noqa

    admin_config = app.config.get(
        'ADMIN',
        {
            'name': 'Quokka Admin',
            'url': '/admin'
        }
    )

    for key, value in list(admin_config.items()):
        setattr(admin, key, value)

    # avoid registering twice
    if admin.app is None:
        admin.init_app(app)

    return admin
项目:flask_workshop    作者:cursodepythonoficial    | 项目源码 | 文件源码
def configure_admin(app):
    admin = Admin(app, name='Flask Workshop')

    # add views
    admin.add_view(MenuView(db.menu, 'Menu'))
    admin.add_view(ContactView(db.contact, 'Contact'))
项目:web_develop    作者:dongweiming    | 项目源码 | 文件源码
def index():
    return '<a href="/admin/">Click me to get to Admin!</a>'
项目:crm    作者:Incubaid    | 项目源码 | 文件源码
def init_admin_app(self):
        """
        Initialize admin app
        """
        admin_views = __import__(
            'crm.apps.admin.views',
            globals(),
            locals(),
            ['object']
        )

        adminindexview = getattr(
            admin_views,
            'MyAdminIndexView')

        admin = Admin(
            self._app,
            name="CRM",
            index_view=adminindexview(url='/'),
            endpoint='/',
            template_mode="bootstrap3", url="/"
        )

        all_models = {}
        for model in BaseModel.__subclasses__():
            all_models[model.__name__] = model

        with warnings.catch_warnings():
            warnings.filterwarnings(
                'ignore', 'Fields missing from ruleset', UserWarning)
            for main_model in NAV_BAR_ORDER['MAIN']:
                viewname = main_model + "ModelView"
                viewcls = getattr(admin_views, viewname)
                admin.add_view(viewcls(all_models[main_model], db.session))

            for extra_model in NAV_BAR_ORDER['EXTRA']:
                viewname = extra_model + "ModelView"
                viewcls = getattr(admin_views, viewname)
                admin.add_view(
                    viewcls(all_models[extra_model], db.session, category="Extra"))
项目:ChaosWG-Manager    作者:Obihoernchen    | 项目源码 | 文件源码
def init_admin(app):
    """
    initializes the flask-admin interface
    :param app:
    :return:
    """
    admin = Admin(app, index_view=AuthAdminIndexView(), name='ChaosWG Manager Admin',
                  template_mode='bootstrap3')
    admin.add_link(MenuLink(name='Back Home', url='/tasks'))
    admin.add_view(AuthAdminModelView(Task))
    admin.add_view(AuthAdminUserModelView(User))
    admin.add_view(AuthAdminModelView(Room))
    admin.add_view(AuthAdminModelView(History))
项目:pygameweb    作者:pygame    | 项目源码 | 文件源码
def add_admin(app):
    """ to the app.
    """
    admin = Admin(app, template_mode='bootstrap3', index_view=TheAdminIndexView())
    admin.add_view(UserAdmin(User, admin.app.scoped_session, endpoint='user_admin'))
    admin.add_view(GroupAdmin(Group, admin.app.scoped_session, endpoint='group_admin'))
    admin.add_view(NewsAdmin(News, admin.app.scoped_session, endpoint='news_admin'))
    admin.add_view(ProjectAdmin(Project, admin.app.scoped_session, endpoint='project_admin'))
    admin.add_view(ReleaseAdmin(Release, admin.app.scoped_session, endpoint='release_admin'))
    admin.add_view(PageAdmin(Page, admin.app.scoped_session, endpoint='page_admin'))
项目:flask-boilerplate    作者:ItEngine    | 项目源码 | 文件源码
def load_admin():
    """
    Configuration admin
    """
    from apps.auth.controllers import MyAdminIndexView
    admin = Admin(
        app, name='Admin', index_view=MyAdminIndexView(),
        template_mode='bootstrap3', base_template='admin_master.html',
    )

    return admin
项目:radar    作者:renalreg    | 项目源码 | 文件源码
def __init__(self):
        super(RadarAdmin, self).__init__(template_folder='admin/templates')

        self.context_processor(inject_current_user)

        admin = Admin(
            self,
            'RADAR Admin',
            index_view=AdminIndexView(),
            template_mode='bootstrap3',
            base_template='master.html',
            url='/admin'
        )

        admin.add_view(CohortView(Group, db.session, name='Cohorts', category='Groups', endpoint='cohort'))
        admin.add_view(HospitalView(Group, db.session, name='Hospitals', category='Groups', endpoint='hospital'))
        admin.add_view(GroupView(Group, db.session, name='Groups', category='Groups'))
        admin.add_view(GroupConsultantView(GroupConsultant, db.session, name='Consultants', category='Groups'))
        admin.add_view(GroupDiagnosisView(GroupDiagnosis, db.session, name='Diagnoses', category='Groups'))
        admin.add_view(GroupFormView(GroupForm, db.session, name='Forms', category='Groups'))
        admin.add_view(GroupObservationView(GroupObservation, db.session, name='Observations', category='Groups'))
        admin.add_view(GroupPageView(GroupPage, db.session, name='Pages', category='Groups'))
        admin.add_view(GroupQuestionnaireView(GroupQuestionnaire, db.session, name='Questionnaires', category='Groups'))

        admin.add_view(CodeView(Code, db.session, name='Codes', category='Codes'))
        admin.add_view(CountryView(Country, db.session, name='Countries', category='Codes'))
        admin.add_view(EthnicityView(Ethnicity, db.session, name='Ethnicities', category='Codes'))
        admin.add_view(NationalityView(Nationality, db.session, name='Nationalities', category='Codes'))
        admin.add_view(CountryEthnicityView(CountryEthnicity, db.session, name='Country ethnicities', category='Codes'))
        admin.add_view(
            CountryNationalityView(
                CountryNationality,
                db.session,
                name='Country nationalities',
                category='Codes'
            )
        )

        admin.add_view(ConsultantView(Consultant, db.session, name='Consultants', category='Consultants'))
        admin.add_view(SpecialtyView(Specialty, db.session, 'Specialties', category='Consultants'))

        admin.add_view(DiagnosisView(Diagnosis, db.session, name='Diagnoses', category='Diagnoses'))
        admin.add_view(DiagnosisCodeView(DiagnosisCode, db.session, name='Codes', category='Diagnoses'))

        admin.add_view(DrugView(Drug, db.session, 'Drugs', category='Drugs'))
        admin.add_view(DrugGroupView(DrugGroup, db.session, 'Groups', category='Drugs'))

        admin.add_view(ConsentView(Consent, db.session, 'Consents', category='Other'))

        admin.add_view(FormView(Form, db.session, 'Forms', category='Other'))

        admin.add_view(ObservationView(Observation, db.session, 'Observations', category='Other'))

        admin.add_view(ExportView(name='Exports', endpoint='exports', category='Other'))