Python flask_admin.Admin() Examples
The following are 16
code examples of flask_admin.Admin().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_admin
, or try the search function
.
Example #1
Source File: admin.py From website with MIT License | 6 votes |
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))
Example #2
Source File: admin.py From maple-blog with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: __init__.py From gitmark with GNU General Public License v2.0 | 6 votes |
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
Example #4
Source File: server.py From app with MIT License | 5 votes |
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))
Example #5
Source File: admin.py From SmartProxyPool with MIT License | 5 votes |
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)
Example #6
Source File: app_admin.py From web_develop with GNU General Public License v3.0 | 5 votes |
def index(): return '<a href="/admin/">Click me to get to Admin!</a>'
Example #7
Source File: app.py From react-flask-shop-app with GNU General Public License v3.0 | 5 votes |
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))
Example #8
Source File: _admin.py From vulyk with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #9
Source File: server.py From spid-testenv2 with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #10
Source File: views.py From pygameweb with BSD 2-Clause "Simplified" License | 5 votes |
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'))
Example #11
Source File: admin.py From flask-restless-security with MIT License | 5 votes |
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'))
Example #12
Source File: views.py From unshred-tag with MIT License | 5 votes |
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'))
Example #13
Source File: server.py From autologin with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: demo_pythonanywhere_com.py From safrs with GNU General Public License v3.0 | 4 votes |
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}")
Example #15
Source File: __init__.py From listenbrainz-server with GNU General Public License v2.0 | 4 votes |
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
Example #16
Source File: app.py From sandman2 with Apache License 2.0 | 4 votes |
def get_app( database_uri, exclude_tables=None, user_models=None, reflect_all=True, read_only=False, schema=None): """Return an application instance connected to the database described in *database_uri*. :param str database_uri: The URI connection string for the database :param list exclude_tables: A list of tables to exclude from the API service :param list user_models: A list of user-defined models to include in the API service :param bool reflect_all: Include all database tables in the API service :param bool read_only: Only allow HTTP GET commands for all endpoints :param str schema: Use the specified named schema instead of the default """ app = Flask('sandman2') app.config['SQLALCHEMY_DATABASE_URI'] = database_uri app.config['SANDMAN2_READ_ONLY'] = read_only app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.classes = [] db.init_app(app) admin = Admin(app, base_template='layout.html', template_mode='bootstrap3') _register_error_handlers(app) if user_models: with app.app_context(): _register_user_models(user_models, admin, schema=schema) elif reflect_all: with app.app_context(): _reflect_all(exclude_tables, admin, read_only, schema=schema) @app.route('/') def index(): """Return a list of routes to the registered classes.""" routes = {} for cls in app.classes: routes[cls.__model__.__name__] = '{}{{/{}}}'.format( cls.__model__.__url__, cls.__model__.primary_key()) return jsonify(routes) return app