flask.ext.superadmin.base

Base View

flask.ext.superadmin.base.expose(url='/', methods=('GET', ))[source]

Use this decorator to expose views in your view classes.

url
Relative URL for the view
methods
Allowed HTTP methods. By default only GET is allowed.
class flask.ext.superadmin.base.BaseView(name=None, category=None, endpoint=None, url=None, static_folder=None)[source]

Base administrative view.

Derive from this class to implement your administrative interface piece. For example:

class MyView(BaseView):
    @expose('/')
    def index(self):
        return 'Hello World!'
create_blueprint(admin)[source]

Create Flask blueprint.

is_accessible()[source]

Override this method to add permission checks.

Flask-SuperAdmin does not make any assumptions about authentication system used in your application, so it is up for you to implement it.

By default, it will allow access for the everyone.

render(template, **kwargs)[source]

Render template

template
Template path to render
kwargs
Template arguments

Default view

class flask.ext.superadmin.base.AdminIndexView(name=None, category=None, endpoint=None, url=None)[source]

Default administrative interface index page when visiting the /admin/ URL.

It can be overridden by passing your own view class to the Admin constructor:

class MyHomeView(AdminIndexView):
    @expose('/')
    def index(self):
        return render_template('adminhome.html')

admin = Admin(index_view=MyHomeView)

Default values for the index page are following:

  • If name is not provided, ‘Home’ will be used.
  • If endpoint is not provided, will use admin
  • Default URL route is /admin.
  • Automatically associates with static folder.

Admin

class flask.ext.superadmin.base.Admin(app=None, name=None, url=None, index_view=None, translations_path=None)[source]

Collection of the views. Also manages menu structure.

add_view(view)[source]

Add view to the collection.

view
View to add.
init_app(app)[source]

Register all views with Flask application.

app
Flask application instance
locale_selector(f)[source]

Installs locale selector for current Admin instance.

Example:

def admin_locale_selector():
    return request.args.get('lang', 'en')

admin = Admin(app)
admin.locale_selector(admin_locale_selector)

It is also possible to use the @admin decorator:

admin = Admin(app)

@admin.locale_selector
def admin_locale_selector():
    return request.args.get('lang', 'en')

Or by subclassing the Admin:

class MyAdmin(Admin):
    def locale_selector(self):
        return request.args.get('lang', 'en')
menu()[source]

Return menu hierarchy.

register(model, admin_class=None, *args, **kwargs)[source]

Register model to the collection.

model
Model to add.
admin_class
ModelAdmin class corresponding to model.