diff options
author | Jelle van der Waa <jelle@vdwaa.nl> | 2019-06-13 14:00:19 +0200 |
---|---|---|
committer | Jelle van der Waa <jelle@vdwaa.nl> | 2019-06-13 14:13:30 +0200 |
commit | cc552c47e93eeace0278fb396fc785cbccc116fa (patch) | |
tree | b57111c50d5ce91111d4182076bfff110b0e522e | |
parent | 9be52a87b1c63168f83b07286681dccdb5e04ace (diff) | |
download | archweb-cc552c47e93eeace0278fb396fc785cbccc116fa.tar.gz archweb-cc552c47e93eeace0278fb396fc785cbccc116fa.zip |
todolist: send email when the todolist is fully complete
When a todolist item is complete ie. all TodoListPackages belonging to
the todolist are marked as COMPLETE inform the creator of the todolist
via an email.
Closes: #222
Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
-rw-r--r-- | templates/todolists/complete_email_notification.txt | 8 | ||||
-rw-r--r-- | todolists/models.py | 30 |
2 files changed, 37 insertions, 1 deletions
diff --git a/templates/todolists/complete_email_notification.txt b/templates/todolists/complete_email_notification.txt new file mode 100644 index 00000000..e8e5a90f --- /dev/null +++ b/templates/todolists/complete_email_notification.txt @@ -0,0 +1,8 @@ +{% autoescape off %}The todo list "{{ todolist.name }}" is complete. + +Todo list information: +Name: {{ todolist.name }} +URL: {{ todolist.get_full_url }} +Creator: {{ todolist.creator.get_full_name }} +Description: +{{ todolist.description|striptags|wordwrap:78 }}{% endautoescape %} diff --git a/todolists/models.py b/todolists/models.py index b219ad6d..72476b48 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -1,7 +1,9 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site +from django.core.mail import EmailMessage from django.db import models -from django.db.models.signals import pre_save +from django.db.models.signals import pre_save, post_save +from django.template import loader from main.models import Arch, Repo, Package from main.utils import set_created_field @@ -79,9 +81,35 @@ class TodolistPackage(models.Model): return self.get_status_display().lower().replace('-', '') +def check_todolist_complete(sender, instance, **kwargs): + if instance.status == instance.INCOMPLETE: + return + + query = TodolistPackage.objects.filter(todolist=instance.todolist, status__exact=instance.INCOMPLETE) + if query.count() > 0: + return + + # Send e-mail notification + subject = "The last package on the TODO list '%s' has been completed." % instance.todolist.name + tmpl = loader.get_template('todolists/complete_email_notification.txt') + toemail = [instance.todolist.creator.email] + ctx = { + 'todolist': instance.todolist, + } + msg = EmailMessage(subject, + tmpl.render(ctx), + 'Arch Website Notification <nobody@archlinux.org>', + toemail, + ) + msg.send(fail_silently=True) + + pre_save.connect(set_created_field, sender=Todolist, dispatch_uid="todolists.models") pre_save.connect(set_created_field, sender=TodolistPackage, dispatch_uid="todolists.models") +post_save.connect(check_todolist_complete, sender=TodolistPackage, + dispatch_uid='todolist.models') + # vim: set ts=4 sw=4 et: |