本文整理汇总了Python中flask_admin.Admin方法的典型用法代码示例。如果您正苦于以下问题:Python flask_admin.Admin方法的具体用法?Python flask_admin.Admin怎么用?Python flask_admin.Admin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_admin
的用法示例。
在下文中一共展示了flask_admin.Admin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_app
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def init_app(app):
admin = Admin(
app,
name="jazzband",
template_mode="bootstrap3",
index_view=JazzbandAdminIndexView(),
)
model_admins = [
(User, UserAdmin),
(OAuth, OAuthAdmin),
(EmailAddress, EmailAddressAdmin),
(Project, ProjectAdmin),
(ProjectMembership, JazzbandModelView),
(ProjectUpload, ProjectUploadAdmin),
(ProjectCredential, JazzbandModelView),
]
for model_cls, admin_cls in model_admins:
admin.add_view(admin_cls(model_cls, postgres.session))
示例2: init_app
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def init_app(app):
admin = Admin(
name=_("honmaple"),
index_view=AdminIndexView(
template="admin/index.html",
url=app.config.get("ADMIN_URL", "/"),
),
template_mode="bootstrap3")
admins = [
"maple.admin",
"maple.blog.admin",
"maple.storage.admin",
]
[import_string(i).init_admin(admin) for i in admins]
admin.init_app(app)
示例3: init_admin
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def init_admin(app):
from model_admin import GeneralAdminIndexView, register_admin_views
admin = Admin(app, name='GitMark Admin', index_view=GeneralAdminIndexView(url='/model-admin'))
register_admin_views(admin)
# def create_app():
# config_name = os.getenv('config') or 'default'
# app = Flask(__name__,
# template_folder=config[config_name].TEMPLATE_PATH, static_folder=config[config_name].STATIC_PATH)
# app.config.from_object(config[config_name])
# config[config_name].init_app(app)
# db.init_app(app)
# login_manager.init_app(app)
# principals.init_app(app)
# mail.init_app(app)
# init_admin(app)
# return app
示例4: init_admin
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def init_admin(app):
admin = Admin(name="SimpleLogin", template_mode="bootstrap3")
admin.init_app(app, index_view=SLAdminIndexView())
admin.add_view(SLModelView(User, db.session))
admin.add_view(SLModelView(Client, db.session))
admin.add_view(SLModelView(Alias, db.session))
admin.add_view(SLModelView(ClientUser, db.session))
示例5: init_app
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def init_app(app):
admin = flask_admin.Admin(app=app, name='ProxyPool Admin', base_template="admin/master_base.html", index_view=ProxyPoolAdminIndexView(), template_mode='bootstrap3')
admin.add_view(ProxyView(ProxyModel))
admin.add_view(SettingView(SettingModel))
# admin.add_view(ProxyPoolView(ProxyPoolModel))
admin.add_view(FetcherView(FetcherModel))
db = MongoEngine()
db.init_app(app)
user_datastore = MongoEngineUserDatastore(db, User, Role)
init_security(user_datastore, app, admin)
init_base_data(user_datastore, app)
示例6: index
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def index():
return '<a href="/admin/">Click me to get to Admin!</a>'
示例7: configure_admin
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def configure_admin(app,admin_models):
admin = Admin(app,name="Store backend")
for admin_view in admin_models:
admin.add_view(admin_view(Product,db.session))
示例8: init_admin
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def init_admin(app) -> admin.Admin:
adm = admin.Admin(
app,
'Vulyk: Admin',
index_view=AuthAdminIndexView(),
template_mode='bootstrap3'
)
adm.add_view(AuthModelView(User))
return adm
示例9: _setup_managers
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def _setup_managers(self):
if not self._config.database_admin_interface:
return
self.app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'
self.admin = Admin(
self.app,
name='Ambiente di test SPID - Interfaccia di amministrazione',
template_mode='bootstrap3'
)
self.user_manager.register_admin(self.admin)
if 'db' in self._config.metadata:
self.sp_metadata_manager = DatabaseSPProvider(self._config.metadata['db'])
self.sp_metadata_manager.register_admin(self.admin)
示例10: add_admin
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
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'))
示例11: init_admin
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def init_admin():
admin = Admin(app)
admin.add_view(UserModelView(User, db.session, category='Auth'))
admin.add_view(AdminModelView(Role, db.session, category='Auth'))
admin.add_view(AdminModelView(SomeStuff, db.session))
admin.add_view(LogoutView(name='Logout', endpoint='logout'))
admin.add_view(LoginView(name='Login', endpoint='login'))
示例12: admin_init
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def admin_init(app):
admin = flask_admin.Admin(app, 'Unshred', index_view=BaseAdminIndexView())
admin.add_view(UserView(User))
admin.add_view(TagsView(Tags))
admin.add_view(ClusterView(Cluster))
admin.add_view(CustomShredsView(name='Custom Shreds'))
示例13: main
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def main():
import argparse
configure_logging()
parser = argparse.ArgumentParser()
parser.add_argument('--host', default='127.0.0.1')
parser.add_argument('--port', type=int, default=8088)
parser.add_argument('--debug', action='store_true')
args = parser.parse_args()
init_db()
admin = flask_admin.Admin(app, template_mode='bootstrap3')
admin.add_view(KeychainItemAdmin(KeychainItem, db.session))
app.run(args.host, args.port, debug=args.debug, threaded=True)
示例14: start_api
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def start_api(swagger_host="0.0.0.0", PORT=None):
# Add startswith methods so we can perform lookups from the frontend
SAFRSBase.startswith = startswith
# Needed because we don't want to implicitly commit when using flask-admin
SAFRSBase.db_commit = False
with app.app_context():
db.init_app(app)
db.create_all()
# populate the database
NR_INSTANCES = 200
for i in range(NR_INSTANCES):
reader = Person(name="Reader " + str(i), email="reader@email" + str(i), password=hashlib.sha256(bytes(i)).hexdigest())
author = Person(name="Author " + str(i), email="author@email" + str(i))
book = Book(title="book_title" + str(i))
review = Review(reader_id=reader.id, book_id=book.id, review="review " + str(i))
publisher = Publisher(name="publisher" + str(i))
publisher.books.append(book)
reader.books_read.append(book)
author.books_written.append(book)
reader.friends.append(author)
author.friends.append(reader)
if i % 20 == 0:
reader.comment = ""
for obj in [reader, author, book, publisher, review]:
db.session.add(obj)
db.session.commit()
custom_swagger = {
"info": {"title": "New Title"},
"securityDefinitions": {"ApiKeyAuth": {"type": "apiKey", "in": "header", "name": "My-ApiKey"}},
} # Customized swagger will be merged
api = SAFRSAPI(
app,
host=swagger_host,
port=PORT,
prefix=API_PREFIX,
api_spec_url=API_PREFIX + "/swagger",
custom_swagger=custom_swagger,
schemes=["http", "https"],
description=description,
)
for model in [Person, Book, Review, Publisher]:
# Create an API endpoint
api.expose_object(model)
# see if we can add the flask-admin views
try:
admin = Admin(app, url="/admin")
for model in [Person, Book, Review, Publisher]:
admin.add_view(sqla.ModelView(model, db.session))
except Exception as exc:
print(f"Failed to add flask-admin view {exc}")
示例15: create_app
# 需要导入模块: import flask_admin [as 别名]
# 或者: from flask_admin import Admin [as 别名]
def create_app(config_path=None, debug=None):
app = gen_app(config_path=config_path, debug=debug)
# Static files
import listenbrainz.webserver.static_manager
static_manager.read_manifest()
app.context_processor(lambda: dict(get_static_path=static_manager.get_static_path))
app.static_folder = '/static'
_register_blueprints(app)
# Admin views
from listenbrainz import model
model.db.init_app(app)
from flask_admin import Admin
from listenbrainz.webserver.admin.views import HomeView
admin = Admin(app, index_view=HomeView(name='Home'), template_mode='bootstrap3')
from listenbrainz.model import Spotify as SpotifyModel
from listenbrainz.model import User as UserModel
from listenbrainz.model.spotify import SpotifyAdminView
from listenbrainz.model.user import UserAdminView
admin.add_view(UserAdminView(UserModel, model.db.session, endpoint='user_model'))
admin.add_view(SpotifyAdminView(SpotifyModel, model.db.session, endpoint='spotify_model'))
@app.before_request
def before_request_gdpr_check():
# skip certain pages, static content and the API
if request.path == url_for('index.gdpr_notice') \
or request.path == url_for('profile.delete') \
or request.path == url_for('profile.export_data') \
or request.path == url_for('login.logout') \
or request.path.startswith('/static') \
or request.path.startswith('/1'):
return
# otherwise if user is logged in and hasn't agreed to gdpr,
# redirect them to agree to terms page.
elif current_user.is_authenticated and current_user.gdpr_agreed is None:
return redirect(url_for('index.gdpr_notice', next=request.full_path))
return app