geonature.core.gn_permissions.admin

Module Contents

Classes

RoleFilter

Base SQLAlchemy filter.

ModuleFilter

Base SQLAlchemy filter.

ObjectFilter

Base SQLAlchemy filter.

ActionFilter

Base SQLAlchemy filter.

ScopeFilter

Base SQLAlchemy filter.

OptionSelect2Widget

Select2 styled select widget.

OptionQuerySelectField

Overrides the QuerySelectField class from flask admin to allow

UserAjaxModelLoader

Ajax related model loader. Override this to implement custom loading behavior.

ObjectAdmin

SQLAlchemy model view

PermissionAdmin

SQLAlchemy model view

PermissionAvailableAdmin

SQLAlchemy model view

RolePermAdmin

SQLAlchemy model view

GroupPermAdmin

SQLAlchemy model view

UserPermAdmin

SQLAlchemy model view

Functions

filters_formatter(v, c, m, p)

modules_formatter(view, context, model, name)

groups_formatter(view, context, model, name)

role_formatter(view, context, model, name)

permissions_formatter(view, context, model, name)

permissions_count_formatter(view, context, model, name)

class geonature.core.gn_permissions.admin.RoleFilter(column, name, options=None, data_type=None)[source]

Bases: geonature.core.admin.utils.DynamicOptionsMixin, flask_admin.contrib.sqla.filters.FilterEqual

Base SQLAlchemy filter.

get_dynamic_options(view)[source]
class geonature.core.gn_permissions.admin.ModuleFilter(column, name, options=None, data_type=None)[source]

Bases: geonature.core.admin.utils.DynamicOptionsMixin, flask_admin.contrib.sqla.filters.FilterEqual

Base SQLAlchemy filter.

get_dynamic_options(view)[source]
class geonature.core.gn_permissions.admin.ObjectFilter(column, name, options=None, data_type=None)[source]

Bases: geonature.core.admin.utils.DynamicOptionsMixin, flask_admin.contrib.sqla.filters.FilterEqual

Base SQLAlchemy filter.

get_dynamic_options(view)[source]
class geonature.core.gn_permissions.admin.ActionFilter(column, name, options=None, data_type=None)[source]

Bases: geonature.core.admin.utils.DynamicOptionsMixin, flask_admin.contrib.sqla.filters.FilterEqual

Base SQLAlchemy filter.

get_dynamic_options(view)[source]
class geonature.core.gn_permissions.admin.ScopeFilter(column, name, options=None, data_type=None)[source]

Bases: geonature.core.admin.utils.DynamicOptionsMixin, flask_admin.contrib.sqla.filters.FilterEqual

Base SQLAlchemy filter.

apply(query, value, alias=None)[source]

Apply search criteria to the query and return new query.

Paramètres:
  • query – Query

  • value – Search criteria

get_dynamic_options(view)[source]
geonature.core.gn_permissions.admin.filters_formatter(v, c, m, p)[source]
geonature.core.gn_permissions.admin.modules_formatter(view, context, model, name)[source]
geonature.core.gn_permissions.admin.groups_formatter(view, context, model, name)[source]
geonature.core.gn_permissions.admin.role_formatter(view, context, model, name)[source]
geonature.core.gn_permissions.admin.permissions_formatter(view, context, model, name)[source]
geonature.core.gn_permissions.admin.permissions_count_formatter(view, context, model, name)[source]
class geonature.core.gn_permissions.admin.OptionSelect2Widget(multiple=False)[source]

Bases: flask_admin.form.widgets.Select2Widget

Select2 styled select widget.

You must include select2.js, form-x.x.x.js and select2 stylesheet for it to work.

classmethod render_option(value, label, options)[source]
class geonature.core.gn_permissions.admin.OptionQuerySelectField(*args, **kwargs)[source]

Bases: flask_admin.contrib.sqla.fields.QuerySelectField

Overrides the QuerySelectField class from flask admin to allow other attributes on a select option.

options_additional_values is added in form_args, it is a list of strings, each element is the name of the attribute in the model which will be added on the option

widget[source]
iter_choices()[source]

Provides data for choice widget rendering. Must return a sequence or iterable of (value, label, selected, render_kw) tuples.

class geonature.core.gn_permissions.admin.UserAjaxModelLoader(name, session, model, **options)[source]

Bases: flask_admin.contrib.sqla.ajax.QueryAjaxModelLoader

Ajax related model loader. Override this to implement custom loading behavior.

format(user)[source]

Return (id, name) tuple from the model.

get_query()[source]
class geonature.core.gn_permissions.admin.ObjectAdmin(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]

Bases: geonature.core.admin.utils.CruvedProtectedMixin, flask_admin.contrib.sqla.ModelView

SQLAlchemy model view

Usage sample:

admin = Admin()
admin.add_view(ModelView(User, db.session))
module_code = 'ADMIN'[source]
object_code = 'PERMISSIONS'[source]
can_create = False[source]
can_edit = False[source]
can_delete = False[source]
column_list = ('code_object', 'description_object', 'modules')[source]
column_labels[source]
column_default_sort = 'id_object'[source]
column_formatters[source]
class geonature.core.gn_permissions.admin.PermissionAdmin(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]

Bases: geonature.core.admin.utils.CruvedProtectedMixin, flask_admin.contrib.sqla.ModelView

SQLAlchemy model view

Usage sample:

admin = Admin()
admin.add_view(ModelView(User, db.session))
module_code = 'ADMIN'[source]
object_code = 'PERMISSIONS'[source]
column_list = ('role', 'module', 'object', 'action', 'label', 'filters')[source]
column_labels[source]
column_searchable_list = ('role.identifiant', 'role.nom_complet')[source]
column_formatters[source]
column_filters = ()[source]
named_filter_urls = True[source]
column_sortable_list = (('role', 'role.nom_complet'), ('module', 'module.module_code'), ('object',...[source]
column_default_sort = [('role.nom_complet', False), ('module.module_code', False), ('object.code_object', False),...[source]
form_columns = ('role', 'availability', 'scope', 'sensitivity_filter')[source]
form_overrides[source]
form_args[source]
create_template = 'admin/hide_select2_options_create.html'[source]
edit_template = 'admin/hide_select2_options_edit.html'[source]
form_ajax_refs[source]
render(template, **kwargs)[source]

Render template

Paramètres:
  • template – Template path to render

  • kwargs – Template arguments

create_form()[source]

Instantiate model creation form and return it.

Override to implement custom behavior.

class geonature.core.gn_permissions.admin.PermissionAvailableAdmin(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]

Bases: geonature.core.admin.utils.CruvedProtectedMixin, flask_admin.contrib.sqla.ModelView

SQLAlchemy model view

Usage sample:

admin = Admin()
admin.add_view(ModelView(User, db.session))
module_code = 'ADMIN'[source]
object_code = 'PERMISSIONS'[source]
can_create = False[source]
can_delete = False[source]
can_export = False[source]
column_labels[source]
column_formatters[source]
column_sortable_list = (('module', 'module.module_code'), ('object', 'object.code_object'), ('action', 'action.code_action'))[source]
column_filters = ()[source]
column_default_sort = [('module.module_code', False), ('object.code_object', False), ('id_action', False)][source]
form_columns = ('scope_filter', 'sensitivity_filter')[source]
class geonature.core.gn_permissions.admin.RolePermAdmin(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]

Bases: geonature.core.admin.utils.CruvedProtectedMixin, flask_admin.contrib.sqla.ModelView

SQLAlchemy model view

Usage sample:

admin = Admin()
admin.add_view(ModelView(User, db.session))
module_code = 'ADMIN'[source]
object_code = 'PERMISSIONS'[source]
can_create = False[source]
can_edit = False[source]
can_delete = False[source]
can_export = False[source]
can_view_details = True[source]
details_template = 'role_or_group_detail.html'[source]
column_labels[source]
column_searchable_list = ('identifiant', 'nom_complet')[source]
column_formatters[source]
column_formatters_detail[source]
class geonature.core.gn_permissions.admin.GroupPermAdmin(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]

Bases: RolePermAdmin

SQLAlchemy model view

Usage sample:

admin = Admin()
admin.add_view(ModelView(User, db.session))
column_list = ('nom_role', 'permissions_count')[source]
column_details_list = ('nom_role', 'permissions_count', 'permissions')[source]
get_query()[source]

Return a query for the model type.

This method can be used to set a « persistent filter » on an index_view.

Example:

class MyView(ModelView):
    def get_query(self):
        return super(MyView, self).get_query().filter(User.username == current_user.username)

If you override this method, don’t forget to also override get_count_query, for displaying the correct item count in the list view, and get_one, which is used when retrieving records for the edit view.

get_count_query()[source]

Return a the count query for the model type

A query(self.model).count() approach produces an excessive subquery, so query(func.count('*')) should be used instead.

See commit #45a2723 for details.

class geonature.core.gn_permissions.admin.UserPermAdmin(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]

Bases: RolePermAdmin

SQLAlchemy model view

Usage sample:

admin = Admin()
admin.add_view(ModelView(User, db.session))
column_list = ('identifiant', 'nom_role', 'prenom_role', 'groups', 'permissions_count')[source]
column_labels[source]
column_details_list = ('identifiant', 'nom_role', 'prenom_role', 'groups', 'permissions_count', 'permissions')[source]
get_query()[source]

Return a query for the model type.

This method can be used to set a « persistent filter » on an index_view.

Example:

class MyView(ModelView):
    def get_query(self):
        return super(MyView, self).get_query().filter(User.username == current_user.username)

If you override this method, don’t forget to also override get_count_query, for displaying the correct item count in the list view, and get_one, which is used when retrieving records for the edit view.

get_count_query()[source]

Return a the count query for the model type

A query(self.model).count() approach produces an excessive subquery, so query(func.count('*')) should be used instead.

See commit #45a2723 for details.