Notification emails #80

Merged
Oleg-Komarov merged 31 commits from notifications into main 2024-04-18 16:11:20 +02:00
4 changed files with 23 additions and 1 deletions
Showing only changes of commit 402bfd8cdc - Show all commits

View File

@ -397,6 +397,9 @@ class DraftExtensionView(
add_preview_formset.save() add_preview_formset.save()
form.save() form.save()
if 'submit_draft' in self.request.POST: if 'submit_draft' in self.request.POST:
# in the signal context we won't know the real user doing that,
# so keeping this in the view code for now
# alternatively (TODO?) this could be turned into an ApprovalActivity record
action.send( action.send(
self.request.user, self.request.user,
verb=Verb.SUBMITTED_FOR_REVIEW, verb=Verb.SUBMITTED_FOR_REVIEW,

View File

@ -22,6 +22,9 @@ class Notification(models.Model):
processed_by_mailer_at = models.DateTimeField(default=None, null=True) processed_by_mailer_at = models.DateTimeField(default=None, null=True)
sent = models.BooleanField(default=False, null=False) sent = models.BooleanField(default=False, null=False)
class Meta:
unique_together = ['recipient', 'action']
def format_email_txt(self): def format_email_txt(self):
url = self.get_absolute_url() url = self.get_absolute_url()
# TODO construct a proper phrase, depending on the verb, maybe use a template # TODO construct a proper phrase, depending on the verb, maybe use a template

View File

@ -28,7 +28,7 @@ class Command(BaseCommand):
# TODO check some form of recipient.is_subscribed(n): # TODO check some form of recipient.is_subscribed(n):
n.sent = True n.sent = True
to_send.append(n) to_send.append(n)
# first mark, then send: to avoid spamming in case of a crash-loop # first mark as processed, then send: avoid spamming in case of a crash-loop
Notification.objects.bulk_update(batch, ['processed_by_mailer_at', 'sent']) Notification.objects.bulk_update(batch, ['processed_by_mailer_at', 'sent'])
if len(to_send) > 0: if len(to_send) > 0:
logger.info(f'sending an email to {recipient} about {len(to_send)} notifications') logger.info(f'sending an email to {recipient} about {len(to_send)} notifications')

View File

@ -0,0 +1,16 @@
# Generated by Django 4.2.11 on 2024-04-12 18:09
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0003_notification'),
]
operations = [
migrations.DeleteModel(
name='Notification',
),
]