Skip to content

Commit 837d9f6

Browse files
committed
Notify by email of state/tag updates. Fixes ietf-tools#568
- Legacy-Id: 2747
1 parent 75e33a6 commit 837d9f6

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

ietf/ietfworkflows/utils.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import copy
22
import datetime
33

4+
from django.conf import settings
45
from django.contrib.contenttypes.models import ContentType
6+
from django.core.mail import EmailMessage
7+
from django.template.loader import render_to_string
58

69
from workflows.models import State
710
from workflows.utils import (get_workflow_for_object, set_workflow_for_object,
@@ -126,7 +129,38 @@ def reset_tag_by_name(obj, tag_name):
126129
return False
127130

128131

129-
def update_tags(obj, comment, person, set_tags=[], reset_tags=[]):
132+
def notify_entry(entry, template, extra_notify=[]):
133+
doc = entry.content
134+
wg = doc.group.ietfwg
135+
mail_list = set(['%s <%s>' % i.person.email() for i in wg.wgchair_set.all() if i.person.email()])
136+
mail_list = mail_list.union(['%s <%s>' % i.person.email() for i in wg.wgdelegate_set.all() if i.person.email()])
137+
mail_list = mail_list.union(extra_notify)
138+
mail_list = list(mail_list)
139+
140+
subject = 'Annotation tags have changed for draft %s' % doc
141+
body = render_to_string(template, {'doc': doc,
142+
'entry': entry,
143+
})
144+
mail = EmailMessage(subject=subject,
145+
body=body,
146+
to=mail_list,
147+
from_email=settings.DEFAULT_FROM_EMAIL)
148+
# Only send emails if we are not debug mode
149+
print body
150+
if not settings.DEBUG:
151+
mail.send()
152+
return mail
153+
154+
155+
def notify_tag_entry(entry, extra_notify=[]):
156+
return notify_entry(entry, 'ietfworkflows/annotation_tags_updated_mail.txt', extra_notify)
157+
158+
159+
def notify_state_entry(entry, extra_notify=[]):
160+
return notify_entry(entry, 'ietfworkflows/state_updated_mail.txt', extra_notify)
161+
162+
163+
def update_tags(obj, comment, person, set_tags=[], reset_tags=[], extra_notify=[]):
130164
ctype = ContentType.objects.get_for_model(obj)
131165
setted = []
132166
resetted = []
@@ -136,11 +170,12 @@ def update_tags(obj, comment, person, set_tags=[], reset_tags=[]):
136170
for name in reset_tags:
137171
if reset_tag_by_name(obj, name):
138172
resetted.append(name)
139-
ObjectAnnotationTagHistoryEntry.objects.create(
173+
entry = ObjectAnnotationTagHistoryEntry.objects.create(
140174
content_type=ctype,
141175
content_id=obj.pk,
142176
setted = ','.join(setted),
143177
unsetted = ','.join(resetted),
144178
change_date = datetime.datetime.now(),
145179
comment = comment,
146180
person=person)
181+
notify_tag_entry(entry, extra_notify)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The annotation tags of document {{ doc }} have been updated. See more information below.
2+
3+
Annotation tags set: {{ entry.setted }}
4+
Annotation tags reset: {{ entry.unsetted }}
5+
Date of the change: {{ entry.change_date }}
6+
Author of the change: {{ entry.person }}
7+
8+
Comment:
9+
{{ entry.comment }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The state of document {{ doc }} has been updated. See more information below.
2+
3+
Previous state: {{ entry.from_state }}
4+
Current state: {{ entry.to_state }}
5+
Transition date: {{ entry.transition_date }}
6+
Author of the change: {{ entry.person }}
7+
8+
Comment:
9+
{{ entry.comment }}

0 commit comments

Comments
 (0)