Push Notifications
This package contains both data models related to push notifications:
PushNotification
and
PushNotificationTranslation
.
Push Notification
The model for the push notification
- class integreat_cms.cms.models.push_notifications.push_notification.PushNotification(*args, **kwargs)[source]
Bases:
AbstractBaseModel
Data model representing a push notification
- 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 sentcreated_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
Relationship fields:
- Parameters:
regions (
ManyToManyField
toRegion
) – Regions (related name:push_notifications
)
Reverse relationships:
- Parameters:
translations (Reverse
ForeignKey
fromPushNotificationTranslation
) – All translations of this push notification (related name ofpush_notification
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- property backend_translation: PushNotificationTranslation | None[source]
This function returns the translation of this push notification in the current backend language.
- Returns:
The backend translation of a push notification
- property best_translation: PushNotificationTranslation[source]
This function returns the translation of this push notification in the current backend language and if it doesn’t exist, it provides a fallback to the translation in the region’s default language.
- Returns:
The “best” translation of a push notification for displaying in the backend
- clean()[source]
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clean_fields(exclude=None)[source]
Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
- created_date[source]
Type:
DateTimeField
Creation date
- property default_language: Language[source]
This property returns the default language of this push notification :return: The default language of the first region
- property default_translation: PushNotificationTranslation[source]
This function returns the translation of this push notification in the region’s default language. Since a push notification can only be created by creating a translation in the default language, this is guaranteed to return a push notification translation.
- Returns:
The default translation of a push notification
- draft[source]
Type:
BooleanField
Draft. Whether or not the News is a draft (drafts cannot be sent)
- full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]
Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.
- get_channel_display(*, field=<django.db.models.CharField: channel>)[source]
Shows the label of the
channel
. Seeget_FOO_display()
for more information.
- get_mode_display(*, field=<django.db.models.CharField: mode>)[source]
Shows the label of the
mode
. Seeget_FOO_display()
for more information.
- classmethod get_model_name_plural() str [source]
Get the plural representation of this model name
- Returns:
The plural model name
- Return type:
- get_next_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=True, **kwargs)[source]
Finds next instance based on
created_date
. Seeget_next_by_FOO()
for more information.
- get_previous_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=False, **kwargs)[source]
Finds previous instance based on
created_date
. Seeget_previous_by_FOO()
for more information.
- get_repr() str [source]
This overwrites the default Django
__repr__()
method which would return<PushNotification: PushNotification object (id)>
. It is used for logging.- Returns:
The canonical string representation of the push notification
- Return type:
- id[source]
Type:
BigAutoField
Primary key: ID
- is_overdue[source]
This property returns whether the notification is overdue based on the retain time setting and scheduled_send_date. This method only works for scheduled notifications.
- Returns:
True if the message is overdue, False otherwise
- is_template[source]
Type:
BooleanField
News template
Distinct functionalities for templates
- languages[source]
This property returns a QuerySet of all
Language
objects, to which a push notification translation exists.- Returns:
QuerySet of all
Language
a push notification is translated into
- mode[source]
Type:
CharField
Mode. Sets behavior for dealing with not existing News translations
Choices:
ONLY_AVAILABLE
USE_MAIN_LANGUAGE
Manage choices in
push_notifications
- refresh_from_db(using=None, fields=None)[source]
Reload field values from the database.
By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.
Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.
When accessing deferred fields of an instance, the deferred loading of the field will call this method.
- regions[source]
Type:
ManyToManyField
toRegion
Regions (related name:
push_notifications
)
- save(force_insert=False, force_update=False, using=None, update_fields=None)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]
Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.
The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.
- scheduled_send_date[source]
Type:
DateTimeField
Scheduled send date. The scheduled date for this News to be sent
- scheduled_send_date_local[source]
Convert the scheduled send date to local time
- Returns:
The scheduled send date in local time
- sent_date[source]
Type:
DateTimeField
Sent date. The date and time when the News was sent.
None
if the push notification is not yet sent
- serializable_value(field_name)[source]
Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.
Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.
- translations[source]
Type: Reverse
ForeignKey
fromPushNotificationTranslation
All translations of this push notification (related name of
push_notification
)
Push Notification Translation
- class integreat_cms.cms.models.push_notifications.push_notification_translation.PushNotificationTranslation(*args, **kwargs)[source]
Bases:
AbstractBaseModel
Data model representing a push notification translation
- Parameters:
id (BigAutoField) – Primary key: ID
title (CharField) – Title
text (TextField) – Content
last_updated (DateTimeField) – Modification date
Relationship fields:
- Parameters:
language (
ForeignKey
toLanguage
) – Language (related name:push_notification_translations
)push_notification (
ForeignKey
toPushNotification
) – Push notification (related name:translations
)
- exception DoesNotExist[source]
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned[source]
Bases:
MultipleObjectsReturned
- clean()[source]
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clean_fields(exclude=None)[source]
Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.
- full_clean(exclude=None, validate_unique=True, validate_constraints=True)[source]
Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.
- get_absolute_url() str [source]
Generates the absolute url to a news object in the app
- Returns:
The link to the news
- Return type:
- classmethod get_model_name_plural() str [source]
Get the plural representation of this model name
- Returns:
The plural model name
- Return type:
- get_next_by_last_updated(*, field=<django.db.models.DateTimeField: last_updated>, is_next=True, **kwargs)[source]
Finds next instance based on
last_updated
. Seeget_next_by_FOO()
for more information.
- get_previous_by_last_updated(*, field=<django.db.models.DateTimeField: last_updated>, is_next=False, **kwargs)[source]
Finds previous instance based on
last_updated
. Seeget_previous_by_FOO()
for more information.
- get_repr() str [source]
This overwrites the default Django
__repr__()
method which would return<PushNotificationTranslation: PushNotificationTranslation object (id)>
. It is used for logging.- Returns:
The canonical string representation of the event
- Return type:
- get_text() str [source]
Get the text of the notification. Construct a fallback text if possible.
- Returns:
A text for the push notification
- Return type:
- get_title() str [source]
Get the title of the notification translation.
- Returns:
A title for the push notification
- Return type:
- id[source]
Type:
BigAutoField
Primary key: ID
- language[source]
Type:
ForeignKey
toLanguage
Language (related name:
push_notification_translations
)
- last_updated[source]
Type:
DateTimeField
Modification date
- push_notification[source]
Type:
ForeignKey
toPushNotification
Push notification (related name:
translations
)
- push_notification_id[source]
Internal field, use
push_notification
instead.
- refresh_from_db(using=None, fields=None)[source]
Reload field values from the database.
By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.
Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.
When accessing deferred fields of an instance, the deferred loading of the field will call this method.
- save(force_insert=False, force_update=False, using=None, update_fields=None)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)[source]
Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.
The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.
- classmethod search(region: Region, language_slug: str, query: str) QuerySet[PushNotificationTranslation] [source]
Searches for all push notifications which match the given query in their title. :param region: The current region :param language_slug: The language slug :param query: The query string used for filtering the push notifications :return: A query for all matching objects
- Parameters:
- Return type:
QuerySet[PushNotificationTranslation]
- serializable_value(field_name)[source]
Return the value of the field name for this instance. If the field is a foreign key, return the id value instead of the object. If there’s no Field object with this name on the model, return the model attribute’s value.
Used to serialize a field’s value (in the serializer, or form output, for example). Normally, you would just access the attribute directly and not use this method.