Push Notifications

This package contains all views related to push notifications

Push Notification Actions

integreat_cms.cms.views.push_notifications.push_notification_actions.archive_push_notification(request: HttpRequest, push_notification_id: int, region_slug: str, language_slug: str) HttpResponseRedirect[source]

Method that archives a given push notification

Parameters:
  • request (HttpRequest) – The current request

  • push_notification_id (int) – Id of the existing push notification that is supposed to be archived

  • region_slug (str) – The slug of the current region

  • language_slug (str)

Returns:

A redirection to the PushNotificationListView

Return type:

HttpResponseRedirect

integreat_cms.cms.views.push_notifications.push_notification_actions.restore_push_notification(request: HttpRequest, push_notification_id: int, region_slug: str, language_slug: str) HttpResponseRedirect[source]

Restore given push notification

Parameters:
  • request (HttpRequest) – The current request

  • push_notification_id (int) – The id of the push notification which should be restored

  • region_slug (str) – The slug of the current region

  • language_slug (str)

Returns:

A redirection to the PushNotificationListView

Return type:

HttpResponseRedirect

Push Notification Bulk Actions

class integreat_cms.cms.views.push_notifications.push_notification_bulk_actions.ArchivePushNotificationsBulkAction(**kwargs)[source]

Bases: PushNotificationBulkAction

Bulk action to archive multiple contacts at once

__init__(**kwargs)[source]

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

allow_empty = True[source]
classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

context_object_name = None[source]
delete(request, *args, **kwargs)[source]
dispatch(request, *args, **kwargs)[source]
extra_context = None[source]
get(request, *args, **kwargs)[source]
get_allow_empty()[source]

Return True if the view should display empty lists and False if a 404 should be raised instead.

get_context_data(*, object_list=None, **kwargs)[source]

Get the context for this view.

get_context_object_name(object_list)[source]

Get the name of the item to be used in the context.

get_extra_filters() Q[source]

Overwrite to filter queryset for regions since push notification can have multiple regions

Return type:

Q

get_login_url()[source]

Override this method to override the login_url attribute.

get_ordering()[source]

Return the field or fields to use for ordering the queryset.

get_paginate_by(queryset)[source]

Get the number of items to paginate by, or None for no pagination.

get_paginate_orphans()[source]

Return the maximum number of orphans extend the last page by when paginating.

get_paginator(queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs)[source]

Return an instance of the paginator for this view.

get_permission_denied_message()[source]

Override this method to override the permission_denied_message attribute.

get_permission_required() tuple[str][source]

Override this method to override the permission_required attribute.

Returns:

The permissions that are required for views inheriting from this Mixin

Return type:

tuple[str]

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_field_name()[source]

Override this method to override the redirect_field_name attribute.

get_redirect_url(*args: Any, **kwargs: Any) str[source]

Normally this function redirects to the URL namespace by getting the model name. This only works if namespace and model name are the same. It doesn’t work in this instance, because the model is called pushnotification, but the URL namespace is called push_notification. Therefore we need to overwrite this function and redirect from pushnotification to push_notification.

Parameters:
  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied keyword arguments

Returns:

url to redirect to

Return type:

str

handle_no_permission()[source]
has_permission()[source]

Override this method to customize the way permissions are checked.

head(request, *args, **kwargs)[source]
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.

http_method_not_allowed(request, *args, **kwargs)[source]
login_url = None[source]
model[source]

alias of PushNotification

options(request, *args, **kwargs)[source]

Handle responding to requests for the OPTIONS HTTP verb.

ordering = None[source]
page_kwarg = 'page'[source]
paginate_by = None[source]
paginate_orphans = 0[source]
paginate_queryset(queryset, page_size)[source]

Paginate the queryset, if needed.

paginator_class[source]

alias of Paginator

patch(request, *args, **kwargs)[source]
pattern_name = None[source]
permanent = False[source]
permission_denied_message = ''[source]
permission_required = None[source]
post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Archive multiple contacts 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

prefetch_public_translations: bool = False[source]

Whether the public translation objects should be prefetched

prefetch_translations: bool = False[source]

Whether the translation objects should be prefetched

put(request, *args, **kwargs)[source]
query_string = False[source]
queryset = None[source]
raise_exception = False[source]
redirect_field_name = 'next'[source]
require_change_permission: bool = True[source]

Whether the view requires change permissions

setup(request, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

url = None[source]
view_is_async = False[source]
class integreat_cms.cms.views.push_notifications.push_notification_bulk_actions.PushNotificationBulkAction(**kwargs)[source]

Bases: BulkActionView

View for executing contact bulk actions

__init__(**kwargs)[source]

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

allow_empty = True[source]
classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

context_object_name = None[source]
delete(request, *args, **kwargs)[source]
dispatch(request, *args, **kwargs)[source]
extra_context = None[source]
get(request, *args, **kwargs)[source]
get_allow_empty()[source]

Return True if the view should display empty lists and False if a 404 should be raised instead.

get_context_data(*, object_list=None, **kwargs)[source]

Get the context for this view.

get_context_object_name(object_list)[source]

Get the name of the item to be used in the context.

get_extra_filters() Q[source]

Overwrite to filter queryset for regions since push notification can have multiple regions

Return type:

Q

get_login_url()[source]

Override this method to override the login_url attribute.

get_ordering()[source]

Return the field or fields to use for ordering the queryset.

get_paginate_by(queryset)[source]

Get the number of items to paginate by, or None for no pagination.

get_paginate_orphans()[source]

Return the maximum number of orphans extend the last page by when paginating.

get_paginator(queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs)[source]

Return an instance of the paginator for this view.

get_permission_denied_message()[source]

Override this method to override the permission_denied_message attribute.

get_permission_required() tuple[str][source]

Override this method to override the permission_required attribute.

Returns:

The permissions that are required for views inheriting from this Mixin

Return type:

tuple[str]

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_field_name()[source]

Override this method to override the redirect_field_name attribute.

get_redirect_url(*args: Any, **kwargs: Any) str[source]

Normally this function redirects to the URL namespace by getting the model name. This only works if namespace and model name are the same. It doesn’t work in this instance, because the model is called pushnotification, but the URL namespace is called push_notification. Therefore we need to overwrite this function and redirect from pushnotification to push_notification.

Parameters:
  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied keyword arguments

Returns:

url to redirect to

Return type:

str

handle_no_permission()[source]
has_permission()[source]

Override this method to customize the way permissions are checked.

head(request, *args, **kwargs)[source]
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.

http_method_not_allowed(request, *args, **kwargs)[source]
login_url = None[source]
model[source]

The model of this BulkActionView

Parameters:
  • id (BigAutoField) – Primary key: ID

  • channel (CharField) – Channel

  • draft (BooleanField) – Draft. Whether or not the News is a draft (drafts cannot be sent)

  • sent_date (DateTimeField) –

    Sent date. The date and time when the News was sent.

    None if the push notification is not yet sent

  • created_date (DateTimeField) – Creation date

  • scheduled_send_date (DateTimeField) – Scheduled send date. The scheduled date for this News to be sent

  • mode (CharField) –

    Mode. Sets behavior for dealing with not existing News translations

    Manage choices in push_notifications

  • is_template (BooleanField) –

    News template

    Distinct functionalities for templates

  • template_name (CharField) – News template name. Provide a distinct name for the template

  • archived (BooleanField) – Archived. Whether or not the push notification is read-only and hidden in the API.

Relationship fields:

Parameters:

regions (ManyToManyField to Region) – Regions (related name: push_notifications)

Reverse relationships:

Parameters:

translations (Reverse ForeignKey from PushNotificationTranslation) – All translations of this push notification (related name of push_notification)

alias of PushNotification

options(request, *args, **kwargs)[source]

Handle responding to requests for the OPTIONS HTTP verb.

ordering = None[source]
page_kwarg = 'page'[source]
paginate_by = None[source]
paginate_orphans = 0[source]
paginate_queryset(queryset, page_size)[source]

Paginate the queryset, if needed.

paginator_class[source]

alias of Paginator

patch(request, *args, **kwargs)[source]
pattern_name = None[source]
permanent = False[source]
permission_denied_message = ''[source]
permission_required = None[source]
post(request, *args, **kwargs)[source]
prefetch_public_translations: bool = False[source]

Whether the public translation objects should be prefetched

prefetch_translations: bool = False[source]

Whether the translation objects should be prefetched

put(request, *args, **kwargs)[source]
query_string = False[source]
queryset = None[source]
raise_exception = False[source]
redirect_field_name = 'next'[source]
require_change_permission: bool = True[source]

Whether the view requires change permissions

setup(request, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

url = None[source]
view_is_async = False[source]
class integreat_cms.cms.views.push_notifications.push_notification_bulk_actions.RestorePushNotificationsBulkAction(**kwargs)[source]

Bases: PushNotificationBulkAction

Bulk action to restore multiple contacts at once

__init__(**kwargs)[source]

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

allow_empty = True[source]
classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

context_object_name = None[source]
delete(request, *args, **kwargs)[source]
dispatch(request, *args, **kwargs)[source]
extra_context = None[source]
get(request, *args, **kwargs)[source]
get_allow_empty()[source]

Return True if the view should display empty lists and False if a 404 should be raised instead.

get_context_data(*, object_list=None, **kwargs)[source]

Get the context for this view.

get_context_object_name(object_list)[source]

Get the name of the item to be used in the context.

get_extra_filters() Q[source]

Overwrite to filter queryset for regions since push notification can have multiple regions

Return type:

Q

get_login_url()[source]

Override this method to override the login_url attribute.

get_ordering()[source]

Return the field or fields to use for ordering the queryset.

get_paginate_by(queryset)[source]

Get the number of items to paginate by, or None for no pagination.

get_paginate_orphans()[source]

Return the maximum number of orphans extend the last page by when paginating.

get_paginator(queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs)[source]

Return an instance of the paginator for this view.

get_permission_denied_message()[source]

Override this method to override the permission_denied_message attribute.

get_permission_required() tuple[str][source]

Override this method to override the permission_required attribute.

Returns:

The permissions that are required for views inheriting from this Mixin

Return type:

tuple[str]

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_field_name()[source]

Override this method to override the redirect_field_name attribute.

get_redirect_url(*args: Any, **kwargs: Any) str[source]

Normally this function redirects to the URL namespace by getting the model name. This only works if namespace and model name are the same. It doesn’t work in this instance, because the model is called pushnotification, but the URL namespace is called push_notification. Therefore we need to overwrite this function and redirect from pushnotification to push_notification.

Parameters:
  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied keyword arguments

Returns:

url to redirect to

Return type:

str

handle_no_permission()[source]
has_permission()[source]

Override this method to customize the way permissions are checked.

head(request, *args, **kwargs)[source]
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.

http_method_not_allowed(request, *args, **kwargs)[source]
login_url = None[source]
model[source]

alias of PushNotification

options(request, *args, **kwargs)[source]

Handle responding to requests for the OPTIONS HTTP verb.

ordering = None[source]
page_kwarg = 'page'[source]
paginate_by = None[source]
paginate_orphans = 0[source]
paginate_queryset(queryset, page_size)[source]

Paginate the queryset, if needed.

paginator_class[source]

alias of Paginator

patch(request, *args, **kwargs)[source]
pattern_name = None[source]
permanent = False[source]
permission_denied_message = ''[source]
permission_required = None[source]
post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Function to restore multiple contacts 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

prefetch_public_translations: bool = False[source]

Whether the public translation objects should be prefetched

prefetch_translations: bool = False[source]

Whether the translation objects should be prefetched

put(request, *args, **kwargs)[source]
query_string = False[source]
queryset = None[source]
raise_exception = False[source]
redirect_field_name = 'next'[source]
require_change_permission: bool = True[source]

Whether the view requires change permissions

setup(request, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

url = None[source]
view_is_async = False[source]

Push Notification Form View

class integreat_cms.cms.views.push_notifications.push_notification_form_view.PushNotificationFormView(**kwargs)[source]

Bases: TemplateView

Class that handles HTTP POST and GET requests for editing push notifications

__init__(**kwargs)[source]

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

content_type = None[source]
dispatch(request, *args, **kwargs)[source]
extra_context = {'current_menu_item': 'push_notifications_form', 'schedule_interval': 60}[source]

The context dict passed to the template (see ContextMixin)

get(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Open form for creating or editing a push notification

Parameters:
  • request (HttpRequest) – Object representing the user call

  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied keyword arguments

Returns:

The rendered template response

Return type:

HttpResponse

get_context_data(**kwargs)[source]
get_template_names()[source]

Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden.

http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'][source]
http_method_not_allowed(request, *args, **kwargs)[source]
options(request, *args, **kwargs)[source]

Handle responding to requests for the OPTIONS HTTP verb.

post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Save and show form for creating or editing a push notification. Send push notification if asked for by user.

Parameters:
  • request (HttpRequest) – Object representing the user call

  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied keyword arguments

Raises:
Returns:

The rendered template response

Return type:

HttpResponse

render_to_response(context, **response_kwargs)[source]

Return a response, using the response_class for this view, with a template rendered with the given context.

Pass response_kwargs to the constructor of the response class.

response_class[source]

alias of TemplateResponse

setup(request, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

template_engine = None[source]
template_name = 'push_notifications/push_notification_form.html'[source]

The template to render (see TemplateResponseMixin)

view_is_async = False[source]
integreat_cms.cms.views.push_notifications.push_notification_form_view.create_from_template(request: HttpRequest, pn_form: PushNotificationForm) PushNotification | None[source]

Create a push notification from a template

Parameters:
  • request (HttpRequest) – The current request

  • pn_form (PushNotificationForm) – The push notification form

Returns:

The new created push notification object

Return type:

PushNotification | None

integreat_cms.cms.views.push_notifications.push_notification_form_view.extract_pn_details(request: HttpRequest, push_notification: PushNotification | None, sort_for_region: Region | None = None) dict[str, Any][source]

Save and show form for creating or editing a push notification. Send push notification if asked for by user.

Parameters:
  • request (HttpRequest) – Object representing the user call

  • push_notification (PushNotification | None) – The existing PushNotification or None

  • sort_for_region (Region | None) – Region for which to keep sorting order (according to language tree)

Returns:

A dict containing * all_regions, a list of all Region objects of the existing PushNotification (or the current region, if it doesn’t exist yet), * other_regions, the sublist of all_regions which the current user doesn’t have access to, * all_languages, a cumulative list of all active languages across all regions in all_regions and * disable_edit, a boolean determining whether the user should be able to edit the PushNotification given his status (superuser, staff) and the vacancy of other_regions.

Return type:

dict[str, Any]

integreat_cms.cms.views.push_notifications.push_notification_form_view.save_forms(instance: PushNotification, pn_form: PushNotificationForm, pnt_formset: Any) None[source]

Saves the forms :param instance: The push notification instance :param pn_form: The push notification form :param pnt_formset: The push notification translation formset

Parameters:
Return type:

None

integreat_cms.cms.views.push_notifications.push_notification_form_view.send_pn(request: HttpRequest, pn_form: PushNotificationForm, schedule: bool = False) bool[source]

Send (or schedule) a push notification

Parameters:
  • request (HttpRequest) – The current request

  • pn_form (PushNotificationForm) – The push notification form

  • schedule (bool) – Whether the message should be scheduled instead of sent directly

Raises:

PermissionDenied – When the user does not have the permission to send notifications

Returns:

Whether sending (or scheduling) was successful

Return type:

bool

integreat_cms.cms.views.push_notifications.push_notification_form_view.validate_forms(request: HttpRequest, details: dict, pn_form: PushNotificationForm, pnt_formset: Any) bool[source]

Validates the forms and returns True iff no errors occurred. :param request: The request :param details: The push notification details :param pn_form: The push notification form :param pnt_formset: The push notification translation formset :return: whether verification was successful

Parameters:
Return type:

bool

Push Notification List View

class integreat_cms.cms.views.push_notifications.push_notification_list_view.PushNotificationListView(**kwargs)[source]

Bases: TemplateView

Class that handles HTTP GET requests for listing push notifications

__init__(**kwargs)[source]

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

archived = False[source]
classmethod as_view(**initkwargs)[source]

Main entry point for a request-response process.

content_type = None[source]
count_archived_push_notifications(region: Region) int[source]

Counts the amount of archived push notifications

Parameters:

region (Region)

Return type:

int

dispatch(request, *args, **kwargs)[source]
extra_context = {'current_menu_item': 'push_notifications'}[source]

The context dict passed to the template (see ContextMixin)

get(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Create a list that shows existing push notifications and translations

Parameters:
  • request (HttpRequest) – Object representing the user call

  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied keyword arguments

Returns:

The rendered template response

Return type:

HttpResponse

get_context_data(**kwargs)[source]
get_template_names()[source]

Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden.

http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'][source]
http_method_not_allowed(request, *args, **kwargs)[source]
options(request, *args, **kwargs)[source]

Handle responding to requests for the OPTIONS HTTP verb.

post(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse[source]

Apply the query and filter the rendered push notifications

Parameters:
  • request (HttpRequest) – The current request

  • *args (Any) – The supplied arguments

  • **kwargs (Any) – The supplied keyword arguments

Returns:

The rendered template response

Return type:

HttpResponse

render_to_response(context, **response_kwargs)[source]

Return a response, using the response_class for this view, with a template rendered with the given context.

Pass response_kwargs to the constructor of the response class.

response_class[source]

alias of TemplateResponse

setup(request, *args, **kwargs)[source]

Initialize attributes shared by all view methods.

template = 'push_notifications/push_notification_list.html'[source]

The template to render if templates is False

template_engine = None[source]
property template_name: str[source]

Select correct HTML template, depending on templates flag (see TemplateResponseMixin)

Returns:

Path to HTML template

template_templates = 'push_notifications/push_notification_template_list.html'[source]

The template to render if templates is True

templates = False[source]

If true, shows the template push notification list

view_is_async = False[source]