# Copyright 2013 Alexandre Bulté <alexandre[at]bulte[dot]net> # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flask_superadmin import Admin, AdminIndexView from flask_superadmin.model.backends.mongoengine import ModelAdmin from flask_login import current_user from webapp import app from .models import User, DummyContent # Create customized model view class class MyModelView(ModelAdmin): def is_accessible(self): return current_user.is_authenticated() # Create customized index view class class MyAdminIndexView(AdminIndexView): def is_accessible(self): return current_user.is_authenticated() # Create admin admin = Admin(app, 'Backoffice', index_view=MyAdminIndexView()) # Add view admin.add_view(MyModelView(User)) admin.add_view(MyModelView(DummyContent))
age = models.IntegerField() def __unicode__(self): return self.name # Create tables in the database if they don't exists try: install_models(Person) except DatabaseError, e: if 'already exists' not in e.message: raise Person.objects.all().delete() view = CustomModelView(Person) admin.add_view(view) eq_(view.model, Person) eq_(view.name, 'Person') eq_(view.endpoint, 'person') eq_(view.url, '/admin/person') # Verify form with app.test_request_context(): Form = view.get_form() ok_(isinstance(Form()._fields['name'], wtforms.TextField)) ok_(isinstance(Form()._fields['age'], wtforms.IntegerField)) # Make some test clients client = app.test_client()
from flask import Flask from flask_superadmin import Admin, BaseView, expose class MyView(BaseView): @expose('/') def index(self): return self.render('index.html') app = Flask(__name__) admin = Admin(app) admin.add_view(MyView(name='Hello 1', endpoint='test1', category='Test')) admin.add_view(MyView(name='Hello 2', endpoint='test2', category='Test')) admin.add_view(MyView(name='Hello 3', endpoint='test3', category='Test')) app.run()
from flask import Flask from flask_superadmin import Admin, BaseView, expose class MyView(BaseView): @expose('/') def index(self): return self.render('index.html') app = Flask(__name__) admin = Admin(app) admin.add_view(MyView(name='Hello')) app.run()