intranet.apps.notifications package¶
Submodules¶
intranet.apps.notifications.emails module¶
- intranet.apps.notifications.emails.email_send(text_template: str, html_template: str, data: Mapping[str, object], subject: str, emails: Collection[str], headers: Optional[Mapping[str, str]] = None, bcc: bool = False, *, custom_logger: Optional[Logger] = None) EmailMultiAlternatives [source]¶
Send an HTML/Plaintext email with the following fields. If we are not in production and settings.FORCE_EMAIL_SEND is not set, does not actually send the email
- Parameters:
text_template – URL to a Django template for the text email’s contents
html_template – URL to a Django template for the HTML email’s contents
data – The context to pass to the templates
subject – The subject of the email
emails – The addresses to send the email to
headers – A dict of additional headers to send to the message
custom_logger – An optional logger to use instead of the Django logger
- Returns:
The email object that was created (and sent if we’re in production or settings.FORCE_EMAIL_SEND is set)
intranet.apps.notifications.models module¶
- class intranet.apps.notifications.models.GCMNotification(id, multicast_id, num_success, num_failure, sent_data, time, user)[source]¶
Bases:
Model
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- property data¶
- get_next_by_time(*, field=<django.db.models.fields.DateTimeField: time>, is_next=True, **kwargs)¶
- get_previous_by_time(*, field=<django.db.models.fields.DateTimeField: time>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- multicast_id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- num_failure¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- num_success¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- sent_data¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- sent_to¶
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings
andTopping.pizzas
areManyToManyDescriptor
instances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- time¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- user¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- user_id¶
- class intranet.apps.notifications.models.GCMNotification_sent_to(id, gcmnotification, notificationconfig)¶
Bases:
Model
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- gcmnotification¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- gcmnotification_id¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- notificationconfig¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- notificationconfig_id¶
- objects = <django.db.models.manager.Manager object>¶
- class intranet.apps.notifications.models.NotificationConfig(id, user, gcm_token, gcm_time, gcm_optout, android_gcm_rand)[source]¶
Bases:
Model
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- android_gcm_rand¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- gcm_optout¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- gcm_time¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- gcm_token¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property gcm_token_sha256¶
- gcmnotification_set¶
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings
andTopping.pizzas
areManyToManyDescriptor
instances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- user¶
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- user_id¶
intranet.apps.notifications.tasks module¶
intranet.apps.notifications.urls module¶
intranet.apps.notifications.views module¶
- intranet.apps.notifications.views.android_setup_view(request)[source]¶
Set up a GCM session. This does not require a valid login session. Instead, a token from the client session is sent to the Android backend, which queries a POST request to this view.
The “android_gcm_rand” is randomly set when the Android app is detected through the user agent. If it has the same value, it is assumed to be correct.
- intranet.apps.notifications.views.chrome_getdata_view(request)[source]¶
Get the data of the last notification sent to the current user.
This is needed because Chrome, as of version 44, doesn’t support sending a data payload to a notification. Thus, information on what the notification is actually for must be manually fetched.