apis_core.generic.views#
Module Contents#
Classes#
Verify that the current user has the required permission for this model. The model overrides the PermissionRequiredMixin.get_permission_required method to generate the required permission name on the fly, based on a verb (permission_action_required) and the model this view act upon. This allows us to set permission_action_required simply to add, or view and reuse the mixin for views that work with different models. In addition, for the views that have permission_action_required set to view, it check if there is the global setting APIS_ANON_VIEWS_ALLOWED set to True, which permits anonymouse users access to the view. |
|
A mixin providing the common functionality for all the views working with generic models - that is models that are accessed via the contenttype framework (using app_label.model). It sets the .model of the view and generates a list of possible template names (based on the MRO of the model). If the view has a permission_action_required attribute, this is used to set the permission required to access the view for this specific model. |
|
List view for a generic model. Access requires the <model>_view permission. It is based on django-filters FilterView and django-tables SingleTableMixin. The table class is overridden by the first match from the first_member_match helper. The filterset class is overridden by the first match from the first_member_match helper. The queryset is overridden by the first match from the first_member_match helper. |
|
Detail view for a generic model. Access requires the <model>_view permission. |
|
Create view for a generic model. Access requires the <model>_add permission. The form class is overridden by the first match from the first_member_match helper. |
|
Delete view for a generic model. Access requires the <model>_delete permission. |
|
Update view for a generic model. Access requires the <model>_change permission. The form class is overridden by the first match from the first_member_match helper. |
|
Autocomplete view for a generic model. Access requires the <model>_view permission. The queryset is overridden by the first match from the first_member_match helper. |
|
This view provides a simple form that allows to select other entities (also from external sources, if set up) and on form submit redirects to the Enrich view. |
|
Generic merge view. |
|
Enrich an entity with data from an external source Provides the user with a form to select the fields that should be updated. |
Data#
API#
- apis_core.generic.views.logger = 'getLogger(...)'#
- class apis_core.generic.views.Overview(**kwargs)#
Bases:
django.contrib.auth.mixins.LoginRequiredMixin,django.views.generic.base.TemplateView- template_name = 'generic/overview.html'#
- class apis_core.generic.views.GenericModelPermissionRequiredMixin#
Bases:
django.contrib.auth.mixins.PermissionRequiredMixinVerify that the current user has the required permission for this model. The model overrides the PermissionRequiredMixin.get_permission_required method to generate the required permission name on the fly, based on a verb (permission_action_required) and the model this view act upon. This allows us to set permission_action_required simply to add, or view and reuse the mixin for views that work with different models. In addition, for the views that have permission_action_required set to view, it check if there is the global setting APIS_ANON_VIEWS_ALLOWED set to True, which permits anonymouse users access to the view.
- get_permission_required()#
- class apis_core.generic.views.GenericModelMixin#
A mixin providing the common functionality for all the views working with generic models - that is models that are accessed via the contenttype framework (using app_label.model). It sets the .model of the view and generates a list of possible template names (based on the MRO of the model). If the view has a permission_action_required attribute, this is used to set the permission required to access the view for this specific model.
- setup(*args, **kwargs)#
- get_template_names()#
- class apis_core.generic.views.List(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django_tables2.export.views.ExportMixin,django_tables2.SingleTableMixin,django_filters.views.FilterViewList view for a generic model. Access requires the <model>_view permission. It is based on django-filters FilterView and django-tables SingleTableMixin. The table class is overridden by the first match from the first_member_match helper. The filterset class is overridden by the first match from the first_member_match helper. The queryset is overridden by the first match from the first_member_match helper.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- template_name_suffix = '_list'#
- permission_action_required = 'view'#
- setup(*args, **kwargs)#
- get(request, *args, **kwargs)#
- get_table_class()#
- export_formats = 'getattr(...)'#
- get_export_filename(extension)#
- get_table_kwargs()#
- get_filterset_class()#
- _get_columns_choices(columns_exclude)#
- get_filterset_kwargs(filterset_class)#
- get_filterset(filterset_class)#
We override the get_filterset method, so we can add a css class to the the selected filters
- get_queryset()#
- get_table_pagination(table)#
Override get_table_pagination from the tables2 TableMixinBase, so we can set the table_pagination value as attribute of the table.
- get_context_data(*args, **kwargs)#
- class apis_core.generic.views.Detail(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.views.generic.DetailViewDetail view for a generic model. Access requires the <model>_view permission.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- permission_action_required = 'view'#
- class apis_core.generic.views.Create(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.contrib.messages.views.SuccessMessageMixin,django.views.generic.edit.CreateViewCreate view for a generic model. Access requires the <model>_add permission. The form class is overridden by the first match from the first_member_match helper.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- template_name_suffix = '_create'#
- permission_action_required = 'add'#
- get_form_class()#
- get_success_message(cleaned_data)#
- get_success_url()#
- class apis_core.generic.views.Delete(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.views.generic.edit.DeleteViewDelete view for a generic model. Access requires the <model>_delete permission.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- permission_action_required = 'delete'#
- get_success_url()#
- class apis_core.generic.views.Update(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.contrib.messages.views.SuccessMessageMixin,django.views.generic.edit.UpdateViewUpdate view for a generic model. Access requires the <model>_change permission. The form class is overridden by the first match from the first_member_match helper.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- permission_action_required = 'change'#
- get_form_class()#
- get_success_message(cleaned_data)#
- get_success_url()#
- class apis_core.generic.views.Duplicate(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.views.View- permission_action_required = 'add'#
- get(request, *args, **kwargs)#
- class apis_core.generic.views.Autocomplete(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,dal.autocomplete.Select2QuerySetViewAutocomplete view for a generic model. Access requires the <model>_view permission. The queryset is overridden by the first match from the first_member_match helper.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- permission_action_required = 'view'#
- template_name_suffix = '_autocomplete_result'#
- setup(*args, **kwargs)#
- get_queryset()#
- get_results(context)#
- create_object(value)#
We try multiple approaches to create a model instance from a value: * we first test if the value is an URL and if so we expect it to be something that can be imported using one of the configured importers and so we pass the value to the import logic. * if the value is not a string, we try to pass it to the create_from_string method of the model, if that does exist. Its the models responsibility to implement this method and the method should somehow know how to create model instance from the value… * finally we pass the value to the create_object method from the DAL view, which tries to pass it to get_or_create which likely also fails, but this is expected and we raise a more useful exception.
- post(request, *args, **kwargs)#
- class apis_core.generic.views.Import(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.views.generic.edit.FormView- template_name_suffix = '_import'#
- permission_action_required = 'add'#
- get_form_class()#
- form_valid(form)#
- get_success_url()#
- class apis_core.generic.views.SelectMergeOrEnrich(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.views.generic.edit.FormViewThis view provides a simple form that allows to select other entities (also from external sources, if set up) and on form submit redirects to the Enrich view.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- template_name_suffix = '_selectmergeorenrich'#
- permission_action_required = 'add'#
- form_class = None#
- get_object(*args, **kwargs)#
- get_context_data(*args, **kwargs)#
- get_form_kwargs(*args, **kwargs)#
- form_valid(form)#
- class apis_core.generic.views.MergeWith(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.views.generic.edit.FormViewGeneric merge view.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- permission_action_required = 'change'#
- form_class = None#
- template_name_suffix = '_merge'#
- setup(*args, **kwargs)#
- get_context_data(**kwargs)#
The context consists of the two objects that are merged as well as a list of changes. Those changes are presented in the view as a table with diffs
- form_valid(form)#
- get_success_url()#
- class apis_core.generic.views.Enrich(**kwargs)#
Bases:
apis_core.generic.views.GenericModelMixin,apis_core.generic.views.GenericModelPermissionRequiredMixin,django.views.generic.edit.FormViewEnrich an entity with data from an external source Provides the user with a form to select the fields that should be updated.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- permission_action_required = 'change'#
- template_name_suffix = '_enrich'#
- form_class = None#
- importer_class = None#
- setup(*args, **kwargs)#
- get(*args, **kwargs)#
- get_context_data(**kwargs)#
- get_form_kwargs(*args, **kwargs)#
- form_valid(form)#
Go through all the form fields and extract the ones that start with update_ and that are set (those are the checkboxes that select which fields to update). Create a dict from those values, add the uri and pass the dict on to the models import_data method.
- get_success_url()#