notifications package

Provides functions for notifications sending and takes care of user’s preferences. You can use this functions to add notifications functionality to your app.

Subpackages

Submodules

notifications.notify module

Functions for dealing with messages.

They take care of different notification providers, user’s notifications settings, staff groups...

Currently only functions for vk.com are implemented, other are represented by skeletons

VK Api (v5.46) is actively used.

notifications.notify._notify_email(user: django.contrib.auth.models.User, text, title=None)[source]

Skeleton for internal function which sends email notifications

notifications.notify._notify_telegram(user: django.contrib.auth.models.User, text, title=None)[source]

Skeleton for internal function which sends telegram notifications

notifications.notify._notify_vk(user: django.contrib.auth.models.User, text, title=None)[source]

Private finction, sends vk notifications

notifications.notify.get_email(user: django.contrib.auth.models.User)[source]

Skeleton for function, retrieving user’s email for notifications

notifications.notify.get_telegram_uid(user: django.contrib.auth.models.User)[source]

Skeleton for function retrieving user’s telegram uid

notifications.notify.get_vk_uid(user: django.contrib.auth.models.User)[source]

Get user’s vk uid or None

If user logged not through vk, tries to find his vk profile in profiles.models.StudentInfo UID needed (formerly?) for sendind messages, displaying beautiful links in VK messages and, maybe, some other staff

Safe, as long as user is valid django.contrib.auth.models.User instance, no additional checks are needed.

notifications.notify.message_int_hash(text)[source]

Generate hash by message text. Different mesasages get different hashes

Used in vk api to prevent sending duplicate messages

notifications.notify.notify(user: django.contrib.auth.models.User, text, title=None)[source]

Main function for sending notifications.

Aggregates internal functions for managing different providers and, according to notifications.models.UserNotificationsSettings, sends messages.

“Safe and simple”: no checks on user are required, just pass user and proper text. You don’t have to worry if user has email of allowed messages from vk

notifications.notify.notify_group(group, text, title=None)[source]

Function for notifying whole department about some event.

Based on notifications.notify.notify(). You only have to provide group (name or Group instance) and message text.

Get code displaying html link to user’s profile.

If it’s impossible to find user’s vk, return user’s name without a link.

Safe, as long as user is valid django.contrib.auth.models.User instance, no additional checks are needed.

Get code displaying internal link to user’s profile for embedding into vk messages.

If it’s impossible to find user’s vk, return user’s name without a link.

Safe, as long as user is valid django.contrib.auth.models.User instance, no additional checks are needed.

notifications.notify.vk_messages_allowed(user)[source]

Returns True if user allowed vk notifications from our community or we can’t find user’s vk

Useg, eg, to remind user allow messages:)

notifications.models module

class notifications.models.Notification(*args, **kwargs)[source]

Bases: django.db.models.base.Model

All sent notifications

METHODS = [(1, 'e-mail'), (2, 'Вконтакте'), (3, 'telegram')]

List of all available notifications providers.

method

Notifications provider. Choices are stored in METHODS

result

Provider’s response to message sending attempt. VK returns message_id if success or error message when smth goes wrong

send_dttm

Added automatically

text

Notification text. No escaping & so on is provided!

user

OneToOne link to django.contrib.auth.models.User instance

class notifications.models.UserNotificationsSettings(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Model for storing user’s notifications preferences.

Currently profiles.views.change_subscribing_status() changes profiles.models.UserProfile, that triggers notifications.signals.user_create() signal, which updates UserNotificationsSettings.

allow_email

Boolean field

allow_telegram

Boolean field

allow_vk

Boolean field

last_allow_vk_reminder

Date & time of last reminder (message on site) to allow vk messages. Used by notifications.signals.allow_vk_messages()

Maybe such reminders should be stored in table like Notifications?

user

OneToOne link to django.contrib.auth.models.user instance

notifications.admin module

Super obvious admin module

notifications.app module

class notifications.app.NotificationsConfig(app_name, app_module)[source]

Bases: django.apps.config.AppConfig

Configuration class for notifications module

ready()[source]

Connect notifications.signals

notifications.signals module

Todo

Currently used to send notifications from apps like fin_aid and cycle_storage. It’ll be better

to move this functionality directly to that apps. Maybe create submodule notifications.py in every package?

notifications.signals.aidrequest_save_notify(sender, instance, created, **kwargs)[source]

Receives post_save signal from fin_aid.models.AidRequest.

Depending on new aid request status, sends notifictions to treasurers or users.

notifications.signals.bicycle_save_notify(sender, instance, created, **kwargs)[source]

Receives post_save signal from fin_aid.models.AidRequest.

Depending on new bicycle storage request status, sends notifictions to staff or users.

notifications.signals.remind_to_allow_messages(sender, request, **kwargs)[source]

After user logs in, displays reminder to allow vk notifications.

notifications.signals.user_create(sender, instance, created, **kwargs)[source]

Receives post_save signal from profiles.models.UserProfile.

Used to update/create notifications.models.UserNotificationsSettings when profiles.models.UserProfile is changes or created.

notifications.templates module

Functions generating text for notifications.

notifications.templates.bicycle_new_request(bicycle)[source]

Message notifying staff about new cycle storage request

notifications.templates.bicycle_request_status_change(bicycle)[source]

Message notifying user about examination of his bicycle storage request

notifications.templates.fin_aid_new_request(aid_request)[source]

Message notifying treasurers about new aid requests

notifications.templates.fin_aid_received(user)[source]

Skeleton for message notifying student about aid received this month. SHould be send at time when scholarship is received

notifications.templates.fin_aid_request_status_change(aid_request)[source]

Message notifying student about examination of fin_aid.models.AidRequest

notifications.templates.get_abs_url(loc_url)[source]

Get absolute (including domain name) url based on loc_url provided.

Should be moved to core app.

notifications.templates.poll_available(poll)[source]

Message notifying user about available poll

notifications.tests module

Module contents