Admin Bundle API¶
flask_unchained.bundles.admin
The Admin Bundle. |
flask_unchained.bundles.admin.config
Config class for the Admin bundle. |
flask_unchained.bundles.admin.extensions
The Admin extension. |
flask_unchained.bundles.admin.hooks
Registers ModelAdmins with the Admin extension. |
flask_unchained.bundles.admin.forms
Like |
|
An extension of |
flask_unchained.bundles.admin.macro
Replaces |
flask_unchained.bundles.admin.model_admin
Base class for SQLAlchemy model admins. |
flask_unchained.bundles.admin.views
Default admin dashboard view. |
|
Extends |
AdminBundle¶
-
class
flask_unchained.bundles.admin.
AdminBundle
[source]¶ The Admin Bundle.
-
name
: str = 'admin_bundle'¶ The name of the Admin Bundle.
-
after_init_app
(app: flask_unchained.flask_unchained.FlaskUnchained) → None[source]¶ Override this method to perform actions on the
FlaskUnchained
app instance after theunchained
extension has initialized the application.
-
Config¶
-
class
flask_unchained.bundles.admin.config.
Config
[source]¶ Config class for the Admin bundle. Defines which configuration values this bundle supports, and their default values.
-
ADMIN_NAME
= 'Admin'¶ The title of the admin section of the site.
-
ADMIN_BASE_URL
= '/admin'¶ Base url of the admin section of the site.
-
ADMIN_INDEX_VIEW
= <flask_unchained.bundles.admin.views.dashboard.AdminDashboardView object>¶ The
AdminIndexView
(or subclass) instance to use for the index view.
-
ADMIN_SUBDOMAIN
= None¶ Subdomain of the admin section of the site.
-
ADMIN_BASE_TEMPLATE
= 'admin/base.html'¶ Base template to use for other admin templates.
-
ADMIN_TEMPLATE_MODE
= 'bootstrap4'¶ Which version of bootstrap to use. (bootstrap2, bootstrap3, or bootstrap4)
-
ADMIN_CATEGORY_ICON_CLASSES
= {}¶ Dictionary of admin category icon classes. Keys are category names, and the values depend on which version of bootstrap you’re using.
For example, with bootstrap4:
ADMIN_CATEGORY_ICON_CLASSES = { 'Mail': 'fa fa-envelope', 'Security': 'fa fa-lock', }
-
ADMIN_ADMIN_ROLE_NAME
= 'ROLE_ADMIN'¶ The name of the Role which represents an admin.
-
ADMIN_LOGIN_ENDPOINT
= 'admin.login'¶ Name of the endpoint to use for the admin login view.
-
ADMIN_POST_LOGIN_REDIRECT_ENDPOINT
= 'admin.index'¶ Name of the endpoint to redirect to after the user logs into the admin.
-
ADMIN_LOGOUT_ENDPOINT
= 'admin.logout'¶ Name of the endpoint to use for the admin logout view.
-
ADMIN_POST_LOGOUT_REDIRECT_ENDPOINT
= 'admin.login'¶ Endpoint to redirect to after the user logs out of the admin.
-
MAPBOX_MAP_ID
= None¶
-
The Admin Extension¶
-
class
flask_unchained.bundles.admin.
Admin
(app=None, name=None, url=None, subdomain=None, index_view=None, translations_path=None, endpoint=None, static_url_path=None, base_template=None, template_mode=None, category_icon_classes=None)[source]¶ The Admin extension:
from flask_unchained.bundles.admin import admin
RegisterModelAdminsHook¶
-
class
flask_unchained.bundles.admin.hooks.
RegisterModelAdminsHook
(unchained: flask_unchained.unchained.Unchained, bundle: Optional[flask_unchained.bundles.Bundle] = None)[source]¶ Registers ModelAdmins with the Admin extension.
-
name
: str = 'admins'¶ The name of this hook.
-
bundle_module_names
: Union[List[str], Tuple[str, ...], None] = ['admins']¶ The default module this hook loads from.
Override by setting the
admins_module_names
attribute on your bundle class.
-
type_check
(obj)[source]¶ Returns True if
obj
is a subclass ofModelAdmin
.
-
Forms¶
Macro¶
-
flask_unchained.bundles.admin.
macro
(name)[source]¶ Replaces
macro()
, adding support for using macros imported from another file. For example:{# templates/admin/column_formatters.html #} {% macro email(model, column) %} {% set address = model[column] %} <a href="mailto:{{ address }}">{{ address }}</a> {% endmacro %}
class FooAdmin(ModelAdmin): column_formatters = { 'col_name': macro('column_formatters.email') }
Also required for this to work, is to add the following to the top of your master admin template:
{# templates/admin/master.html #} {% import 'admin/column_formatters.html' as column_formatters with context %}
ModelAdmin¶
-
class
flask_unchained.bundles.admin.
ModelAdmin
(model, session, name=None, category=None, endpoint=None, url=None, static_folder=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None)[source]¶ Base class for SQLAlchemy model admins. More or less the same as
ModelView
, except we set some different defaults.-
form_base_class
¶ alias of
flask_unchained.bundles.admin.forms.ReorderableForm
-
model_form_converter
¶ alias of
flask_unchained.bundles.admin.forms.AdminModelFormConverter
-
action_view
()¶ Mass-model action view.
-
ajax_update
()¶ Edits a single column of a record in list view.
-
create_view
()¶ Create model view
-
delete_view
()¶ Delete model view. Only POST method is allowed.
-
details_view
()¶ Details model view
-
edit_view
()¶ Edit model view
-
index_view
()¶ List view
-
AdminDashboardView¶
AdminSecurityController¶
-
class
flask_unchained.bundles.admin.
AdminSecurityController
[source]¶ Extends
SecurityController
, to customize the template folder to use admin-specific templates.