Views
This package contains all views for the cms. Use Class-based views whenever possible. Before writing a view completely from scratch, have a look at the Built-in class-based views API and check whether anything meets your requirements.
Bulk Action Views
This module contains the base view for bulk actions
Warning
Any action modifying the database with treebeard should use @tree_mutex(MODEL_NAME)
from integreat_cms.cms.utils.tree_mutex
as a decorator instead of @transaction.atomic
to force treebeard to actually use transactions.
Otherwise, the data WILL get corrupted during concurrent treebeard calls!
- class integreat_cms.cms.views.bulk_action_views.BulkActionView(**kwargs)[source]
Bases:
PermissionRequiredMixin
,MultipleObjectMixin
,RedirectView
View for executing a bulk action and redirect to a given location
- get_extra_filters() Q [source]
Get extra filters for get_queryset(). Overwrite this method to specify needed filters e.g. as in ~integreat_cms.cms.views.contact.contact_bulk_actions
- Returns:
Q Object to be used as filter argument
- Return type:
Q
- get_permission_required() tuple[str] [source]
Override this method to override the permission_required attribute.
- get_queryset() Any [source]
Get the queryset of selected items for this bulk action
- Raises:
Http404 – HTTP status 404 if no objects with the given ids exist
- Returns:
The QuerySet of the filtered links
- Return type:
Any
- get_redirect_url(*args: Any, **kwargs: Any) str [source]
Retrieve url for redirection
- Parameters:
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Returns:
url to redirect to
- Return type:
- http_method_names: list[str] = ['post'][source]
The list of HTTP method names that this view will accept. The bulk action form uses only POST as submission method.
- class integreat_cms.cms.views.bulk_action_views.BulkArchiveView(**kwargs)[source]
Bases:
BulkActionView
Bulk action for restoring multiple objects at once
- post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponseRedirect [source]
Archive multiple objects
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Returns:
The redirect
- Return type:
HttpResponseRedirect
- class integreat_cms.cms.views.bulk_action_views.BulkDraftingView(**kwargs)[source]
Bases:
BulkActionView
Bulk action to draft multiple pages at once
- post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse [source]
Function to change the translation status to draft of multiple pages at once
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Returns:
The redirect
- Return type:
HttpResponse
- class integreat_cms.cms.views.bulk_action_views.BulkMachineTranslationView(**kwargs)[source]
Bases:
BulkActionView
Bulk action for automatically translating multiple objects
- post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponseRedirect [source]
Translate multiple objects automatically
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Returns:
The redirect
- Return type:
HttpResponseRedirect
- class integreat_cms.cms.views.bulk_action_views.BulkPublishingView(**kwargs)[source]
Bases:
BulkActionView
Bulk action to publish multiple pages at once
- post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse [source]
Function to change the translation status to publish of multiple pages at once
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Returns:
The redirect
- Return type:
HttpResponse
- class integreat_cms.cms.views.bulk_action_views.BulkRestoreView(**kwargs)[source]
Bases:
BulkActionView
Bulk action for restoring multiple objects at once
- post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponseRedirect [source]
Restore multiple objects
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Returns:
The redirect
- Return type:
HttpResponseRedirect
- class integreat_cms.cms.views.bulk_action_views.BulkUpdateBooleanFieldView(**kwargs)[source]
Bases:
BulkActionView
Bulk action for toggling boolean fields of multiple objects at once
- property action: str[source]
Called when the bulk action is performed and the
action
attribute was not overwritten- Raises:
NotImplementedError – If the
action
attribute is not implemented in the subclass
- property field_name: str[source]
Called when the bulk action is performed and the
field_name
attribute was not overwritten- Raises:
NotImplementedError – If the
field_name
attribute is not implemented in the subclass
- post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponseRedirect [source]
Update the fields of the selected objects and redirect
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Returns:
The redirect
- Return type:
HttpResponseRedirect
Content Version View
- class integreat_cms.cms.views.content_version_view.ContentVersionView(**kwargs)[source]
Bases:
PermissionRequiredMixin
,SingleObjectMixin
,TemplateView
View for browsing the content versions and restoring old content versions
- back_to_form_label: Promise = 'Back to the form'[source]
The label of the “back to form” button
- dispatch(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponseRedirect | TemplateResponse [source]
Validate the versions view
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Raises:
PermissionDenied – If user does not have the permission to edit the specific page
- Returns:
The rendered template response
- Return type:
HttpResponseRedirect | TemplateResponse
- get_queryset()[source]
Filter the content objects by the current region
- Raises:
Http404 – HTTP status 404 if the content is not found
- Returns:
The rendered template response
- Return type:
- has_change_permission() bool [source]
Whether the user has the permission to change objects
- Returns:
Whether the user can change objects
- Return type:
- has_permission() bool [source]
Override
django.contrib.auth.mixins.PermissionRequiredMixin.has_permission()
- Returns:
Whether the current user can access this view
- Return type:
- has_publish_permission() bool [source]
Whether the user has the permission to publish objects
- Returns:
Whether the user can publish objects
- Return type:
- has_view_permission() bool [source]
Whether the user has the permission to change objects
- Returns:
Whether the user can change objects
- Return type:
- model: ModelBase | None = None[source]
The current content model (see
SingleObjectMixin
)
- object: AbstractContentModel | None = None[source]
The current content object (see
SingleObjectMixin
)
- property pk_url_kwarg: str[source]
The name of the URLConf keyword argument that contains the primary key. By default, pk_url_kwarg is ‘pk’. See
django.views.generic.detail.SingleObjectMixin.pk_url_kwarg
.- Returns:
The name of URL kwarg of the id
- post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponseRedirect [source]
Restore a previous revision of a page translation
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Raises:
PermissionDenied – If user does not have the permission to edit the specific page
- Returns:
The rendered template response
- Return type:
HttpResponseRedirect
- restore_version(restored_version: Any) None [source]
Restore the given version
- Parameters:
restored_version (Any) – The version which should be restored
- Return type:
None
- selected_version: AbstractContentTranslation | None = None[source]
The currently selected translation version
- template_name: str = 'content_versions.html'[source]
The template to render (see
TemplateResponseMixin
)
- translations: list[AbstractContentTranslation] = [][source]
All translations of the content object in the current language
Delete Views
This module contains deletion views for our models that don’t need custom handling.
- class integreat_cms.cms.views.delete_views.CustomDeleteView(*args, **kwargs)[source]
Bases:
CustomModelDeleteMixin
,DeleteView
View for deleting an object retrieved with self.get_object()
- class integreat_cms.cms.views.delete_views.CustomModelDeleteMixin[source]
Bases:
PermissionRequiredMixin
This mixin handles error messages in form views of subclasses of
CustomModelForm
- delete(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse [source]
Call the delete() method on the fetched object and then redirect to the success URL.
- Parameters:
request (HttpRequest) – The current request
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Raises:
django.db.IntegrityError – If the object has many to many relationships that prevent deletion
- Returns:
A redirection to the
success_url
- Return type:
HttpResponse
- get_permission_required() tuple[str, ...] [source]
Override this method to override the permission_required attribute.
Form Views
This module contains form views for our models that don’t need custom handling.
- class integreat_cms.cms.views.form_views.CustomCreateView(**kwargs)[source]
Bases:
CustomModelFormMixin
,BaseCreateView
A view that displays a form for creating a region object, redisplaying the form with validation errors (if there are any) and saving the object.
- class integreat_cms.cms.views.form_views.CustomModelFormMixin[source]
Bases:
PermissionRequiredMixin
,ModelTemplateResponseMixin
,ModelFormMixin
,ModelConfirmationContextMixin
,MediaContextMixin
This mixin handles error messages in form views of subclasses of
CustomModelForm
- form_invalid(form: CustomModelForm) HttpResponse [source]
Renders a response, providing the invalid form as context.
- Parameters:
form (CustomModelForm) – The invalid form instance
- Returns:
The rendered invalid form
- Return type:
HttpResponse
- form_valid(form: CustomModelForm) HttpResponseRedirect [source]
Saves the form instance, sets the current object for the view, and redirects to
get_success_url()
.- Parameters:
form (CustomModelForm) – The valid form instance
- Returns:
A redirection to the success url
- Return type:
HttpResponseRedirect
- get_context_data(**kwargs: Any) dict[str, Any] [source]
Returns a dictionary representing the template context (see
get_context_data()
).
- get_permission_required() tuple[str] [source]
Override this method to override the permission_required attribute.
- get_success_url() str [source]
Determine the URL to redirect to when the form is successfully validated
- Returns:
The url to redirect on success
- Return type:
- property model: ModelBase[source]
Return the model class of this form mixin
- Returns:
The corresponding Django model
- class integreat_cms.cms.views.form_views.CustomUpdateView(**kwargs)[source]
Bases:
CustomModelFormMixin
,BaseUpdateView
A view that displays a form for editing an existing region object, redisplaying the form with validation errors (if there are any) and saving changes to the object. This uses a form automatically generated from the object’s model class (unless a form class is manually specified).
List Views
This module contains list views for our models that don’t need custom handling.
- class integreat_cms.cms.views.list_views.ModelListView(**kwargs)[source]
Bases:
PermissionRequiredMixin
,ModelTemplateResponseMixin
,ModelConfirmationContextMixin
,ListView
Render some list of objects, set by
self.model
orself.queryset
.- property context_object_name: str[source]
Designates the name of the variable to use in the context (see
MultipleObjectMixin
).- Returns:
The name of the objects in this list view
- get_context_data(**kwargs: Any) dict[str, Any] [source]
Returns a dictionary representing the template context (see
get_context_data()
).
- get_permission_required() tuple[str] [source]
Override this method to override the permission_required attribute.
- get_queryset() QuerySet [source]
Get the model’s queryset (optionally filtered by the current region)
- Returns:
The queryset of the current list view
- Return type:
QuerySet
- property model: ModelBase[source]
Return the model class of this list view.
- Returns:
The corresponding Django model
- property paginate_by: int | None[source]
An integer specifying how many objects should be displayed per page. This either returns the current
size
GET parameter or the value defined inPER_PAGE
. (seeMultipleObjectMixin
)- Returns:
The page size
Mixins
This module contains mixins for our views
- class integreat_cms.cms.views.mixins.ContentEditLockMixin[source]
Bases:
ContextMixin
A mixin that provides some variables required for the content edit lock
- class integreat_cms.cms.views.mixins.MachineTranslationContextMixin[source]
Bases:
ContextMixin
This mixin provides extra context for machine translation options
- class integreat_cms.cms.views.mixins.ModelConfirmationContextMixin[source]
Bases:
ContextMixin
A mixin that can be used to inject confirmation text into a template of a model (e.g. list or form)
- class integreat_cms.cms.views.mixins.ModelTemplateResponseMixin[source]
Bases:
TemplateResponseMixin
A mixin that can be used to render a template of a model (e.g. list or form)
- class integreat_cms.cms.views.mixins.RegionPermissionRequiredMixing[source]
Bases:
UserPassesTestMixin
A mixin that can be used for class-based views that require that the user is has access to the current region of this request