Skip to content

Commit 8680c99

Browse files
committed
Send liaison by email. See ietf-tools#342
- Legacy-Id: 2462
1 parent 7e1bf17 commit 8680c99

6 files changed

Lines changed: 102 additions & 9 deletions

File tree

ietf/liaisons/forms.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ def get_cc(self, from_entity, to_entity):
140140
return ', '.join(['%s <%s>' % i.email() for i in persons])
141141

142142
def save(self, *args, **kwargs):
143-
now = datetime.datetime.now()
144143
liaison = super(LiaisonForm, self).save(*args, **kwargs)
144+
self.save_extra_fields(liaison)
145+
self.save_attachments(liaison)
146+
return liaison
147+
148+
def save_extra_fields(self, liaison):
149+
now = datetime.datetime.now()
145150
liaison.submitted_date = now
146151
liaison.last_modified_date = now
147152
from_entity = self.get_from_entity()
@@ -152,8 +157,6 @@ def save(self, *args, **kwargs):
152157
liaison.submitter_name, liaison.submitter_email = self.person.email()
153158
liaison.cc1 = self.get_cc(from_entity, organization)
154159
liaison.save()
155-
self.save_attachments(liaison)
156-
return liaison
157160

158161
def save_attachments(self, instance):
159162
for key in self.files.keys():
@@ -225,8 +228,8 @@ def reset_required_fields(self):
225228
def get_poc(self, organization):
226229
return self.cleaned_data['to_poc']
227230

228-
def save(self, *args, **kwargs):
229-
liaison = super(OutgoingLiaisonForm, self).save(*args, **kwargs)
231+
def save_extra_fields(self, liaison):
232+
super(OutgoingLiaisonForm, self).save_extra_fields(liaison)
230233
from_entity = self.get_from_entity()
231234
needs_approval = from_entity.needs_approval(self.person)
232235
if not needs_approval or self.cleaned_data.get('approved', False):

ietf/liaisons/models.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Copyright The IETF Trust 2007, All Rights Reserved
22

3+
from django.conf import settings
4+
from django.core.exceptions import ObjectDoesNotExist
35
from django.db import models
6+
from django.template.loader import render_to_string
7+
48
from ietf.idtracker.models import Acronym,PersonOrOrgInfo
5-
from django.core.exceptions import ObjectDoesNotExist
9+
from ietf.liaisons.mail import IETFEmailMessage
610

711
class LiaisonPurpose(models.Model):
812
purpose_id = models.AutoField(primary_key=True)
@@ -110,6 +114,30 @@ def get_absolute_url(self):
110114
class Meta:
111115
db_table = 'liaison_detail'
112116

117+
def send_by_email(self, fake=False):
118+
subject = 'New Liaison Statement, "%s"' % (self.title)
119+
from_email = settings.LIAISON_UNIVERSAL_FROM
120+
to_email = self.to_poc.split(',')
121+
cc = self.cc1.split(',')
122+
if self.technical_contact:
123+
cc += self.technical_contact.split(',')
124+
if self.response_contact:
125+
cc += self.response_contact.split(',')
126+
bcc = ['statements@ietf.org']
127+
body = render_to_string('liaisons/liaison_mail.txt',
128+
{'liaison': self,
129+
})
130+
mail = IETFEmailMessage(subject=subject,
131+
to=to_email,
132+
from_email=from_email,
133+
cc = cc,
134+
bcc = bcc,
135+
body = body)
136+
if not fake:
137+
mail.send()
138+
return mail
139+
140+
113141
class SDOs(models.Model):
114142
sdo_id = models.AutoField(primary_key=True)
115143
sdo_name = models.CharField(blank=True, max_length=255)

ietf/liaisons/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# there's an opportunity for date-based filtering.
1212
urlpatterns = patterns('django.views.generic.list_detail',
1313
url(r'^$', 'object_list', info_dict, name='liaison_list'),
14-
(r'^(?P<object_id>\d+)/$', 'object_detail', info_dict),
14+
url(r'^(?P<object_id>\d+)/$', 'object_detail', info_dict, name='liaison_detail'),
1515
)
1616

1717
urlpatterns += patterns('django.views.generic.simple',

ietf/liaisons/views.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Copyright The IETF Trust 2007, All Rights Reserved
2-
from django.shortcuts import render_to_response
2+
from django.conf import settings
33
from django.core.urlresolvers import reverse
44
from django.http import HttpResponse, HttpResponseRedirect
5+
from django.shortcuts import render_to_response
56
from django.template import RequestContext
67
from django.utils import simplejson
78

@@ -18,7 +19,16 @@ def add_liaison(request):
1819
form = liaison_form_factory(request, data=request.POST.copy(),
1920
files = request.FILES)
2021
if form.is_valid():
21-
form.save()
22+
liaison = form.save()
23+
if not settings.DEBUG:
24+
liaison.send_by_mail()
25+
else:
26+
mail = liaison.send_by_email(fake=True)
27+
return render_to_response('liaisons/liaison_mail_detail.html',
28+
{'mail': mail,
29+
'message': mail.message(),
30+
'liaison': liaison},
31+
context_instance=RequestContext(request))
2232
return HttpResponseRedirect(reverse('liaison_list'))
2333
else:
2434
form = liaison_form_factory(request)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Title: {{ liaison.title }}
2+
Submission Date: {{ liaison.submitted_date }}
3+
URL of the IETF Web page: {% url liaison_detail object_id=liaison.pk %}
4+
{% if liaison.deadline_date %}Please reply by {{ liaison.deadline_date }}{% endif %}
5+
From: {{ liaison.from_body }} ({{ liaison.person }} &lt;{{ liaison.replyto|default:liaison.from_email|fix_ampersands }}&gt;)
6+
To: {{ liaison.to_body }} ({{ liaison.to_poc }})
7+
Cc: {{ liaison.cc1 }}
8+
Reponse Contact: {{ liaison.response_contact }}
9+
Technical Contact: {{ liaison.technical_contact }}
10+
Purpose: {% if liaison.purpose_text %}{{ liaison.purpose_text }}{% else %}{{ liaison.purpose.purpose_text }}{% endif %}
11+
Body: {{ liaison.body }}
12+
Attachment(s):
13+
{% for file in liaison.uploads_set.all %}
14+
{{ file.file_title }} https://datatracker.ietf.org/documents/LIAISON/file{{ file.file_id }}{{ file.file_extension }}
15+
{% empty %}
16+
No document has been attached
17+
{% endfor %}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{% extends "base.html" %}
2+
{# Copyright The IETF Trust 2007, All Rights Reserved #}
3+
{% load ietf_filters %}
4+
{% block title %}{{ liaison.title }}{% endblock %}
5+
6+
{% block pagehead %}
7+
{{ form.media }}
8+
{% endblock %}
9+
10+
{% block content %}
11+
<h1>Simulated Mail for Liaison Statement</h1>
12+
13+
<p>
14+
Demo version of this tool does NOT actually send the liaison statement to the recipients.
15+
</p>
16+
<p>
17+
Rather, the actual email body (including mail header) is displayed below.
18+
</p>
19+
<p>
20+
In production mode, you will not see this screen.
21+
</p>
22+
23+
<pre>
24+
From: {{ message.From }}
25+
To: {{ message.To }}
26+
Cc: {{ message.Cc }}
27+
Bcc: {{ message.Bcc }}
28+
Subject: {{ message.Subject }}
29+
30+
{{ mail.body }}
31+
</pre>
32+
33+
<a href="{% url liaison_list %}">Return to liaison list</a>
34+
35+
{% endblock %}

0 commit comments

Comments
 (0)