notifications.views package

Contents

notifications.views package#

Submodules#

notifications.views.admin module#

notifications.views.admin.admin_send_email_copy_to_admin(request, email_id)[source]#

Send a copy of an email to an admin so they can see it fully rendered

With using templates for Django post office emails and render_on_delivery, we no longer have a copy of the email. We can regenerate it though by sending to someone else.

notifications.views.admin.admin_view_all_emails(request)[source]#

Show email notifications for administrators

notifications.views.admin.admin_view_email(request, email_id)[source]#

Show single email for administrators

notifications.views.admin.admin_view_email_by_batch(request, batch_id)[source]#

Show an email from a batch

notifications.views.admin.notifications_status_summary()[source]#

Used by utils status to get a status of notifications

notifications.views.aws module#

notifications.views.aws.admin_aws_suppression(request)[source]#

Manage AWS Email Suppression Lists. An email address gets put on a suppression list by AWS but we can remove it.

This relies on the AWS CLI being installed which is done by .platform/hooks/rebuild/02_yum.sh

In a development environment, you need to install this manually.

To test any of this you need an environment with the notification playpen turned off so you can generate the entry on the suppression list in the first place. Note that if you use a different environment to do this then the reset will not occur there and you will not be able to generate further blocks.

BE CAREFUL: We do not have separate AWS email environments. Test changes will impact production data.

notifications.views.aws.debug(request)[source]#

notifications.views.core module#

notifications.views.core.add_in_app_notification(member, msg, link=None)[source]#

Add a notification to the menu bar telling a user they have a message

notifications.views.core.batch_queue_progress_htmx(request, batch_id_id)[source]#

Return an HTML fragment with the batches queuing progress

notifications.views.core.check_club_and_batch_access()[source]#

Decorator to check club and batch email access rights when editing batches

Expects a request, club_id and batch_id_id. Passes request, club and batch to the called function

Modelled on organisations/decorators.py/check_club_menu_access

notifications.views.core.check_user_has_batch_access(user, batch)[source]#

Check whether the user has the appropriate RBAC role for the batch

Returns a tuple of boolean successs and the role checked (None if invalid batch type)

notifications.views.core.club_default_template(club)[source]#

Determine a reasonable default email template for the club, or None

This uses the following rules: 0. If there are no club templates return None 1. If there is only one club template, regardless of name, use it (ie could be “Results”) 2. If there is one called “Default” use it, regardless of what others exist 3. If there is no “Default”, but “Results” and one other, use the other 4. If there is more than one and no “Default” (and not case 3) return None

notifications.views.core.compose_club_email(request, club_id)[source]#

Entry point for starting a new club batch email

Just create the batchId and then start the composition flow

notifications.views.core.compose_email_content(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_content_attachment_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_content_include_attachment_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_content_included_attachments_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_content_preview_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_content_remove_attachment_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_content_send_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_content_upload_new_email_attachment_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_multi_clear_date_range_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_multi_select(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_multi_select_by_date(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_options(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_options_from_and_reply_to_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_add_congress_email(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_add_member(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_add_self(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_add_tadmins(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_add_tag(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_deselect_all(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_member_search_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_remove_tag(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_remove_unselected_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_select_all(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_tags_pane_htmx(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.compose_email_recipients_toggle_recipient_htmx(request, recipient_id)[source]#

Toggle the include state of the recipient

notifications.views.core.contact_member(member, msg, contact_type='Email', link=None, link_text='View', html_msg=None, subject=None, batch_id=None)[source]#

Contact member using email or SMS. In practice, always Email.

This is for simple cases:

It uses the default template with a link. If you don’t provide the link it will lookCommon function for contacting users silly. msg = short description to go on the in-app notification subject is also used as the title (inside body of email)

batch_id is an option BatchID object for use when sending entry related emails

notifications.views.core.create_rbac_batch_id(rbac_role: str, batch_id: BatchID = None, user: User = None, organisation: Organisation = None, batch_type: str = 'UNK', batch_size: int = 0, description: str = None, complete: bool = False)[source]#

Create a new EmailBatchRBAC object to allow an RBAC role to access a batch of emails

Updated in sprint-48 to add type and description

Parameters:
  • rbac_role (str) – the RBAC role to allow. e.g. “org.orgs.34.view”

  • batch_id (BatchID) – batch ID, if None a new batch Id will be created

  • organisation – Org responsible for sending this

  • user – User responsible for sending this

  • batch_type – Type of batch (BatchID.BATCH_TYPE)

  • description – Email subject line or description

Returns: BatchID

notifications.views.core.custom_sender(from_name)[source]#

Returns a sender address string of the form “from_name<default_email_addres>” or None The default email address is picked up from settings (eg “MyABF<donotreply@myabf.com.au>”)

notifications.views.core.delete_email_batch(request, club_id, batch_id_id, *args, **kwargs)[source]#
notifications.views.core.email_contact(request, member_id, event_id)[source]#

email contact form

Event parameter added to all allow org template to be applied

notifications.views.core.get_emails_sent_to_address(email_address, club, viewing_user, slice=20)[source]#

Return a list of Post Office Email objects sent to the specified email address.

Only emails relevant to the club are returned, and only those that the viewing user has access rights to read.

Returns the most recent <slice> emails, or None

notifications.views.core.get_notifications_statistics()[source]#

get stats about notifications. Called by util statistics

notifications.views.core.initiate_admin_multi_email(request, club_id)[source]#

Entry point for multi congress / event selection view

Just create the batch record and start the composition process

notifications.views.core.remove_email_from_blocked_list(email_address)[source]#

Remove an email address from our internal list of blocked addresses

notifications.views.core.send_cobalt_bulk_email(bcc_addresses, subject, message, reply_to='')[source]#

Sends the same message to multiple people.

Parameters:
  • bcc_addresses (list) – who to send to, list of strings

  • subject (str) – subject line for email

  • message (str) – message to send in HTML or plain format

  • reply_to (str) – who to send replies to

Returns:

Nothing

notifications.views.core.send_cobalt_bulk_email_thread(bcc_addresses, subject, message, reply_to)[source]#

Send bulk emails. Asynchronous thread

Parameters:
  • bcc_addresses (list) – who to send to, list of strings

  • subject (str) – subject line for email

  • message (str) – message to send in HTML or plain format

  • reply_to (str) – who to send replies to

Returns:

Nothing

notifications.views.core.send_cobalt_bulk_notifications(msg_list, admin, description, invalid_lines=None, total_file_rows=0, sender_identification=None)[source]#

This originally sent messages over SMS, but now we only support FCM.

Parameters:
  • sender_identification (str) – e.g. Compscore licence number to identify the sender

  • msg_list (list) – list of tuples of system number and message to send (system_number, “message”)

  • admin (User) – administrator responsible for sending these messages

  • description (str) – Text description of this batch of messages

  • invalid_lines (list) – list of invalid lines in upload file

  • total_file_rows (int) – Number of rows in original file

Returns:

Who we think we sent messages to unregistered_users(list): list of users who we do not know about fcm_users(list): list of users we sent FCM messages to. Users may have multiple devices registered un_contactable_users(list): list of users who don’t have mobiles or haven’t ticked to receive SMS

Return type:

sent_users(list)

notifications.views.core.send_cobalt_email_preformatted(to_address, subject, msg, sender=None, priority='medium', batch_id=None, reply_to=None)[source]#

Queue an email that has already been formatted. Does not use a template.

Generally, you should use a template, but sometimes this is necessary.

Parameters:
  • to_address (str or list) – who to send to

  • subject (str) – subject line

  • msg (str) – HTML message

  • sender (str) – who to send from (None will use default from settings file)

  • priority (str) – Django Post Office priority

  • batch_id (BatchID) – batch_id for this batch of emails

  • reply_to (str) – email address to send replies to

Returns:

Nothing

notifications.views.core.send_cobalt_email_to_system_number(system_number, subject, message, club=None, administrator=None)[source]#

Generic function to send a simple email to a user or unregistered user

if we get a club then we will use that to look for club specific email addresses

Updated for sprint-48 to pass additional header information to BatchID Note: all emails sent via this function with a club specified are assumed to be of batch_type Admin.

notifications.views.core.send_cobalt_email_with_template(to_address, context, template='system - default flex', sender=None, priority='medium', batch_id=None, reply_to=None, attachments=None, batch_size=1, apply_default_template_for_club=None, show_club_footer=True)[source]#

Queue an email using a template and context.

Parameters:
  • to_address (str or list) – who to send to (JPG Comment - does not appear to support list)

  • context (dict) – values to substitute into email template

  • template (str or EmailTemplate instance) – it is more efficient to use an instance for multiple calls

  • sender (str) – who to send from (None will use default from settings file)

  • priority (str) – Django Post Office priority

  • batch_id (BatchID) – batch_id for this batch of emails

  • reply_to (str) – email address to send replies to

  • attachments (dict) – optional dictionary of attachments

  • apply_default_template_for_club (Organisation) – apply style settings from a default template for this club

  • show_club_footer (bool) – allows caller to hide the footer from any club template being applied

Returns:

True if the message was sent, False otherwise

Return type:

boolean

Context for the default template can have:

img_src: logo to override default MyABF logo name: Users first name title: Goes in title box email_body: main part of email additional_words: goes after main body link: link for button e.g. /dashboard link_text: words to go on link button link_colour: default, primary, warning, danger, success, info box_colour: default, primary, warning, danger, success, info

unregistered_identifier: will use alternative footer and show link to unregistered user preferences

notifications.views.core.send_cobalt_sms(phone_number, msg, from_name='My ABF', header=None, member=None)[source]#

Send single SMS. This will be replaced with a mobile app later

Parameters:
  • phone_number (str) – who to send to

  • msg (str) – message to send

  • from_name (str) – Display name of sender

  • header (RealtimeNotificationHeader) – parent for this message

  • member (User) – user for this message

Returns:

None

notifications.views.core.send_fcm_message(fcm_device, msg, admin=None, header=None, add_message_to_database=True)[source]#

Send a message to a users registered FCM device

notifications.views.core.send_test_fcm_message(request, fcm_device_id)[source]#

Send a test message to a users registered FCM device

notifications.views.core.update_context_for_club_default_template(club, context)[source]#

Update the context dictionary with club default styling

Returns the OrgEmailTemplate objected used or None

notifications.views.listeners module#

notifications.views.listeners.add_listener(member, application, event_type, topic=None, subtopic=None, notification_type='Email')[source]#

Add a user to be notified of an event

notifications.views.listeners.check_listener(member, application, event_type, topic=None, subtopic=None)[source]#

Check if a user is being notified of an event

notifications.views.listeners.create_user_notification(member, application_name, event_type, topic, subtopic=None, notification_type='Email')[source]#

create a notification record for a user

Used to programmatically create a notification record. For example Forums will call this to register a notification for comments on a users post.

Parameters:
  • member (User) – standard User object

  • application_name (str) – name of the Cobalt application to follow

  • event_type (str) – event e.g. forums.post.create

  • topic (str) – specific to the application. e.g. 5 to follow forum with pk=5

  • subtopic (str) – application specific (optional)

  • notification_type (str) – email or SMS

Returns:

Nothing

notifications.views.listeners.notify_happening(application_name, event_type, msg, context, topic, subtopic=None, link=None, user=None)[source]#

Called by Cobalt applications to tell notify they have done something.

Main entry point for general notifications of events within the system. Applications publish an event through this call and Notifications tells any member who has registered an interest in this event.

Parameters:
  • context (dict) – variables to pass to the template. See the comments on send_cobalt_email_with_template for more

  • user (User) – user who triggered this event, they won’t be notified even if they are a listener

  • application_name (str) – name of the calling app

  • event_type (str) – what event just happened

  • topic (str) – specific to the application, high level event

  • subtopic (str) – specific to the application, next level event

  • msg (str) – a brief description of the event

  • link (str) – an HTML relative link to the event (Optional)

Returns:

Nothing

notifications.views.listeners.notify_happening_forums(application_name, event_type, msg, context, topic, subtopic=None, link=None, user=None)[source]#

sub function for notify_happening() - handles Forum events Might be able to make this generic

notifications.views.listeners.remove_listener(member, application, event_type, topic=None, subtopic=None)[source]#

Remove a user from being notified of an event

notifications.views.redirect module#

notifications.views.redirect.email_click_handler(request, message_id, redirect_path)[source]#

This is the entry point for email clicks so we know who has clicked on a link in an email. Parameters are message_id (maps to Django Post Office id) and path. The path has ! instead of /

Create a link to apply to an email so that when a user clicks on it we can record the activity and redirect them to where they want to go

Parameters:
  • path (str) – relative path they are trying to get to

  • message_id (str) – Django Post Office message id

notifications.views.user module#

notifications.views.user.acknowledge_in_app_notification(id)[source]#
notifications.views.user.delete_all_in_app_notifications(request)[source]#

when a user clicks on delete all we come here. returns the homepage

notifications.views.user.delete_in_app_notification(request, id)[source]#

when a user clicks on delete we come here. returns the homepage

notifications.views.user.get_notifications_for_user(user)[source]#

Get a list of all unacklowledged notifications for a user

Returns a list of notifications for the user where the status is unacknowledged.

If the list is over 10 then the last item is a link to the notifications page to view them all.

Parameters:

user (User) – standard User object

Returns:

Count of notifications and List of notifications which themselves are tuples

Return type:

tuple

notifications.views.user.homepage(request)[source]#

homepage for notifications listings

notifications.views.user.member_to_member_email(request, member_id)[source]#

Allow one member to email another

notifications.views.user.member_to_member_email_reply(request, batch_id)[source]#

Allow one member to reply via email to another

notifications.views.user.notifications_in_english(member)[source]#

returns a list of notifications in a simple English format. This is hand coded and needs to be updated when new notifications are defined. Used by Accounts:Settings but can be used more generally.

notifications.views.user.passthrough(request, id)[source]#

passthrough function to acknowledge a message has been clicked on

notifications.views.user.watch_emails(request, batch_id)[source]#

Track progress of email by batch id

Module contents#