summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-04 12:39:53 -0600
committerDan McGee <dan@archlinux.org>2011-03-04 12:39:56 -0600
commit65e965c8f76677904f5d98965e13bf89726247d4 (patch)
tree28a847d789286be076091387898f43f95080ebb0
parent9d12c0fac5c0580b30c6bf8f578a358dc22afdff (diff)
Send only one email per todolistrelease_2011-03-07
Customize each email on a per-maintainer basis and list all the relevant packages inside, rather than spamming people. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--templates/packages/outofdate.txt4
-rw-r--r--templates/todolists/email_notification.txt13
-rw-r--r--todolists/views.py54
3 files changed, 33 insertions, 38 deletions
diff --git a/templates/packages/outofdate.txt b/templates/packages/outofdate.txt
index d8b74005..93abea03 100644
--- a/templates/packages/outofdate.txt
+++ b/templates/packages/outofdate.txt
@@ -1,6 +1,4 @@
-{% autoescape off %}* Note: this is an automated message
-
-{{ email }} wants to notify you that the following package may be out-of-date:
+{% autoescape off %}{{ email }} wants to notify you that the following package may be out-of-date:
Package Name: {{ pkg.pkgname }}
Architecture: {{ pkg.arch.name }}
diff --git a/templates/todolists/email_notification.txt b/templates/todolists/email_notification.txt
index abe1dbf3..1825912c 100644
--- a/templates/todolists/email_notification.txt
+++ b/templates/todolists/email_notification.txt
@@ -1,14 +1,9 @@
-{% autoescape off %}* Note: this is an automated message
+{% autoescape off %}The todo list {{ todolist.name }} has had the following packages added to it for which you are a maintainer:
-The following package:
-
- Package Name: {{ pkg.pkgname }}
- Architecture: {{ pkg.arch.name }}
- Repository: {{ pkg.repo.name }}
- ({{ weburl }})
-
-has been added to this todo list:
+{% for tpkg in todo_packages %}
+{{ tpkg.pkg.repo.name|lower }}/{{ tpkg.pkg.pkgname }} ({{ tpkg.pkg.arch.name }}) - {{ tpkg.pkg.get_full_url }}{% endfor %}
+Todo list information:
Creator: {{todolist.creator.get_full_name}}
Name: {{todolist.name}}
Description:
diff --git a/todolists/views.py b/todolists/views.py
index 337fd0d6..6bd456ae 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -75,9 +75,7 @@ def add(request):
form = TodoListForm(request.POST)
if form.is_valid():
new_packages = create_todolist_packages(form, creator=request.user)
- for new_package in new_packages:
- send_newlist_email(new_package)
-
+ send_todolist_emails(form.instance, new_packages)
return redirect(form.instance)
else:
form = TodoListForm()
@@ -98,10 +96,7 @@ def edit(request, list_id):
form = TodoListForm(request.POST, instance=todo_list)
if form.is_valid():
new_packages = create_todolist_packages(form)
-
- for new_package in new_packages:
- send_todolist_email(new_package)
-
+ send_todolist_emails(todo_list, new_packages)
return redirect(todo_list)
else:
form = TodoListForm(instance=todo_list,
@@ -152,25 +147,32 @@ def create_todolist_packages(form, creator=None):
return todo_pkgs
-def send_todolist_email(todo):
- '''Sends an e-mail to the maintainer of a package notifying them that the
- package has been added to a todo list'''
- maints = todo.pkg.maintainers.values_list('email', flat=True)
- if not maints:
- return
-
- page_dict = {
- 'pkg': todo.pkg,
- 'todolist': todo.list,
- 'weburl': todo.pkg.get_full_url()
- }
- t = loader.get_template('todolists/email_notification.txt')
- c = Context(page_dict)
- send_mail('arch: Package [%s] added to Todolist' % todo.pkg.pkgname,
- t.render(c),
- 'Arch Website Notification <nobody@archlinux.org>',
- maints,
- fail_silently=True)
+def send_todolist_emails(todo_list, new_packages):
+ '''Sends emails to package maintainers notifying them that packages have
+ been added to a todo list.'''
+ # start by flipping the incoming list on its head: we want a list of
+ # involved maintainers and the packages they need to be notified about.
+ orphan_packages = []
+ maint_packages = {}
+ for todo_package in new_packages:
+ maints = todo_package.pkg.maintainers.values_list('email', flat=True)
+ if not maints:
+ orphan_packages.append(todo_package)
+ else:
+ for maint in maints:
+ maint_packages.setdefault(maint, []).append(todo_package)
+
+ for maint, packages in maint_packages.iteritems():
+ c = Context({
+ 'todo_packages': sorted(packages),
+ 'todolist': todo_list,
+ })
+ t = loader.get_template('todolists/email_notification.txt')
+ send_mail('Packages added to todo list \'%s\'' % todo_list.name,
+ t.render(c),
+ 'Arch Website Notification <nobody@archlinux.org>',
+ [maint],
+ fail_silently=True)
def public_list(request):
todo_lists = Todolist.objects.incomplete()