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 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

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)

exception DoesNotExist[source]

Bases: ObjectDoesNotExist

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
silent_variable_failure = True[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__(*args, **kwargs)[source]
async adelete(using=None, keep_parents=False)[source]
async arefresh_from_db(using=None, fields=None)[source]
async asave(force_insert=False, force_update=False, using=None, update_fields=None)[source]
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

channel[source]

Type: CharField

Channel

Choices:

  • news

classmethod check(**kwargs)[source]
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

date_error_message(lookup_type, field_name, unique_for)[source]
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

delete(using=None, keep_parents=False)[source]
draft[source]

Type: BooleanField

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

classmethod from_db(db, field_names, values)[source]
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. See get_FOO_display() for more information.

get_constraints()[source]
get_deferred_fields()[source]

Return a set containing names of deferred fields for this instance.

get_mode_display(*, field=<django.db.models.CharField: mode>)[source]

Shows the label of the mode. See get_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:

str

get_next_by_created_date(*, field=<django.db.models.DateTimeField: created_date>, is_next=True, **kwargs)[source]

Finds next instance based on created_date. See get_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. See get_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:

str

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

objects = <django.db.models.Manager object>[source]
property pk[source]
prepare_database_save(field)[source]
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 to Region

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.

template_name[source]

Type: CharField

News template name. Provide a distinct name for the template

translations[source]

Type: Reverse ForeignKey from PushNotificationTranslation

All translations of this push notification (related name of push_notification)

unique_error_message(model_class, unique_check)[source]
validate_constraints(exclude=None)[source]
validate_unique(exclude=None)[source]

Check unique constraints on the model and raise ValidationError if any failed.

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:

Relationship fields:

Parameters:
exception DoesNotExist[source]

Bases: ObjectDoesNotExist

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
silent_variable_failure = True[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MultipleObjectsReturned[source]

Bases: MultipleObjectsReturned

__init__(*args, **kwargs)[source]
add_note()[source]

Exception.add_note(note) – add a note to the exception

args[source]
with_traceback()[source]

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__(*args, **kwargs)[source]
async adelete(using=None, keep_parents=False)[source]
async arefresh_from_db(using=None, fields=None)[source]
async asave(force_insert=False, force_update=False, using=None, update_fields=None)[source]
classmethod check(**kwargs)[source]
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.

date_error_message(lookup_type, field_name, unique_for)[source]
delete(using=None, keep_parents=False)[source]
classmethod from_db(db, field_names, values)[source]
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:

str

get_constraints()[source]
get_deferred_fields()[source]

Return a set containing names of deferred fields for this instance.

classmethod get_model_name_plural() str[source]

Get the plural representation of this model name

Returns:

The plural model name

Return type:

str

get_next_by_last_updated(*, field=<django.db.models.DateTimeField: last_updated>, is_next=True, **kwargs)[source]

Finds next instance based on last_updated. See get_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. See get_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:

str

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:

str

get_title() str[source]

Get the title of the notification translation.

Returns:

A title for the push notification

Return type:

str

id[source]

Type: BigAutoField

Primary key: ID

language[source]

Type: ForeignKey to Language

Language (related name: push_notification_translations)

language_id[source]

Internal field, use language instead.

last_updated[source]

Type: DateTimeField

Modification date

objects = <django.db.models.Manager object>[source]
property pk[source]
prepare_database_save(field)[source]
push_notification[source]

Type: ForeignKey to PushNotification

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.

text[source]

Type: TextField

Content

title[source]

Type: CharField

Title

unique_error_message(model_class, unique_check)[source]
validate_constraints(exclude=None)[source]
validate_unique(exclude=None)[source]

Check unique constraints on the model and raise ValidationError if any failed.