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.StudentInfoUID needed (formerly?) for sendind messages, displaying beautiful links in VK messages and, maybe, some other staffSafe, as long as user is valid
django.contrib.auth.models.Userinstance, 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 orGroupinstance) and message text.
-
notifications.notify.vk_html_user_link(user)[source]¶ 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.Userinstance, no additional checks are needed.
-
notifications.notify.vk_message_user_link(user)[source]¶ 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.Userinstance, no additional checks are needed.
notifications.models module¶
-
class
notifications.models.Notification(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelAll sent notifications
-
METHODS= [(1, 'e-mail'), (2, 'Вконтакте'), (3, 'telegram')]¶ List of all available notifications providers.
-
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.Userinstance
-
-
class
notifications.models.UserNotificationsSettings(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelModel for storing user’s notifications preferences.
Currently
profiles.views.change_subscribing_status()changesprofiles.models.UserProfile, that triggersnotifications.signals.user_create()signal, which updatesUserNotificationsSettings.-
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.userinstance
-
notifications.admin module¶
Super obvious admin module
notifications.app module¶
-
class
notifications.app.NotificationsConfig(app_name, app_module)[source]¶ Bases:
django.apps.config.AppConfigConfiguration class for
notificationsmodule-
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_savesignal fromfin_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_savesignal fromfin_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_savesignal fromprofiles.models.UserProfile.Used to update/create
notifications.models.UserNotificationsSettingswhenprofiles.models.UserProfileis 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