Skip to content

Commit 53cde27

Browse files
committed
Add send mails fuctions about nominations.
See ietf-tools#913 - Legacy-Id: 5140
1 parent eb8b6af commit 53cde27

4 files changed

Lines changed: 75 additions & 14 deletions

File tree

ietf/dbtemplate/fixtures/nomcom_templates.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,31 @@ Please, check if there is some more action nedeed.</field>
3232
<field type="TextField" name="variables">$nominee: Full name of the nominee
3333
$position: Name of the position</field>
3434
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
35-
<field type="TextField" name="content">Hello $nominee.
35+
<field type="TextField" name="content">Hi,
3636

37-
You have been nominated for $position.</field>
37+
You have been nominated for the position of $position.
38+
39+
The NomCom would appreciate receiving an indication of whether or not you accept this nomination to stand for consideration as a candidate for this position.
40+
41+
If you accept, you will need to fill out a questionnaire. You will receive the questionnaire by email.
42+
43+
Best regards,
44+
</field>
3845
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
3946
</object>
4047
<object pk="4" model="dbtemplate.dbtemplate">
4148
<field type="CharField" name="path">/nomcom/defaults/email/new_nomination.txt</field>
4249
<field type="CharField" name="title">Email sent to nominators and secretariat when the nominators make the nominations</field>
4350
<field type="TextField" name="variables">$nominator: Full name of the nominator
44-
$email: Email of the nominator
51+
$nominator_email: Email of the nominator
4552
$nominee: Full name of the nominee
4653
$nominee_email: Email of the nominee
4754
$position: Nomination position</field>
4855
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
4956
<field type="TextField" name="content">A new nomination have been received.
5057

51-
Nominator: $nominator &lt;$email&gt;
52-
Nominee: $nominee &lt;$email&gt;
58+
Nominator: $nominator <$nominator_email>
59+
Nominee: $nominee <$nominee_email>
5360
Position: $position</field>
5461
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
5562
</object>
@@ -59,7 +66,7 @@ Position: $position</field>
5966
<field type="TextField" name="variables">$nominee: Full name of the nomine
6067
$position: Position</field>
6168
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
62-
<field type="TextField" name="content">Hi $nominee, please fill this questionnaire for the position $position:
69+
<field type="TextField" name="content">Hi $nominee, this is the questionnaire for the position $position:
6370

6471
Questionnaire</field>
6572
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>

ietf/nomcom/forms.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from django.conf import settings
12
from django import forms
23
from django.contrib.formtools.preview import FormPreview
34
from django.http import HttpResponseRedirect, HttpResponseForbidden
45
from django.shortcuts import get_object_or_404
56
from django.core.urlresolvers import reverse
6-
from django.conf import settings
77

88
from ietf.utils import unaccent
9+
from ietf.utils.mail import send_mail
910
from ietf.ietfauth.decorators import has_role
1011
from ietf.utils import fields as custom_fields
1112
from ietf.group.models import Group, Role
@@ -16,6 +17,10 @@
1617

1718

1819
ROLODEX_URL = getattr(settings, 'ROLODEX_URL', None)
20+
INEXISTENT_PERSON_TEMPLATE = "email/inexistent_person.txt"
21+
NOMINEE_TEMPLATE = "email/new_nominee.txt"
22+
NOMINATION_TEMPLATE = "email/new_nomination.txt"
23+
QUESTIONNAIRE_TEMPLATE = "position/questionnaire.txt"
1924

2025

2126
def get_group_or_404(year):
@@ -169,18 +174,21 @@ def save(self, commit=True):
169174
candidate_name = self.cleaned_data['candidate_name']
170175
position = self.cleaned_data['position']
171176
comments = self.cleaned_data['comments']
177+
nomcom_template_path = '/nomcom/%s/' % self.nomcom.group.acronym
178+
nomcom_chair = self.nomcom.group.get_chair()
179+
nomcom_chair_mail = nomcom_chair and nomcom_chair.email.address or None
172180

173181
# Create person and email if candidate email does't exist and send email
174-
email, created = Email.objects.get_or_create(address=candidate_email)
175-
if created:
182+
email, created_email = Email.objects.get_or_create(address=candidate_email)
183+
if created_email:
176184
email.person = Person.objects.create(name=candidate_name,
177185
ascii=unaccent.asciify(candidate_name),
178186
address=candidate_email)
179187
email.save()
180188

181189
# Add the nomination for a particular position
182190
nominee, created = Nominee.objects.get_or_create(email=email)
183-
NomineePosition.objects.get_or_create(position=position, nominee=nominee)
191+
nominee_position, nominee_position_created = NomineePosition.objects.get_or_create(position=position, nominee=nominee)
184192

185193
# Complete nomination data
186194
author_emails = Email.objects.filter(person__user=self.user)
@@ -199,8 +207,53 @@ def save(self, commit=True):
199207
if commit:
200208
nomination.save()
201209

202-
# TODO: send mail to chair and secretariat with the new person
203-
# TODO: send mails about nominations
210+
if created_email:
211+
# send email to secretariat and nomcomchair to warn about the new person
212+
subject = 'New person is created'
213+
from_email = settings.NOMCOM_FROM_EMAIL
214+
to_email = [settings.NOMCOM_ADMIN_EMAIL]
215+
context = {'email': email.address,
216+
'fullname': email.person.name,
217+
'person_id': email.person.id}
218+
path = nomcom_template_path + INEXISTENT_PERSON_TEMPLATE
219+
if nomcom_chair_mail:
220+
to_email.append(nomcom_chair_mail)
221+
send_mail(None, to_email, from_email, subject, path, context)
222+
223+
# send email to nominee
224+
if nominee_position_created:
225+
subject = 'IETF Nomination Information'
226+
from_email = settings.NOMCOM_FROM_EMAIL
227+
to_email = email.address
228+
context = {'nominee': email.person.name,
229+
'position': position}
230+
path = nomcom_template_path + NOMINEE_TEMPLATE
231+
send_mail(None, to_email, from_email, subject, path, context)
232+
233+
# send email to nominee with questionnaire
234+
if nominee_position_created:
235+
if self.nomcom.send_questionnaire:
236+
subject = '%s Questionnaire' % position
237+
from_email = settings.NOMCOM_FROM_EMAIL
238+
to_email = email.address
239+
context = {'nominee': email.person.name,
240+
'position': position}
241+
path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE)
242+
send_mail(None, to_email, from_email, subject, path, context)
243+
244+
# send emails to nomcom chair
245+
subject = 'Nomination Information'
246+
from_email = settings.NOMCOM_FROM_EMAIL
247+
to_email = nomcom_chair_mail
248+
context = {'nominee': email.person.name,
249+
'nominee_email': email.address,
250+
'position': position}
251+
if author:
252+
context.update({'nominator': author.person.name,
253+
'nominator_email': author.address})
254+
path = nomcom_template_path + NOMINATION_TEMPLATE
255+
send_mail(None, to_email, from_email, subject, path, context)
256+
204257
return nomination
205258

206259
class Meta:

ietf/nomcom/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def nominate(request, year):
4444
form = NominateForm(data=request.POST, nomcom=nomcom, user=request.user)
4545
if form.is_valid():
4646
form.save()
47-
message = ('success', 'The nomination has been successfully done')
47+
message = ('success', 'Your nomination has been registered. Thank you for the nomination.')
4848
else:
4949
form = NominateForm(nomcom=nomcom, user=request.user)
5050

ietf/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@
262262
# NomCom Tool settings
263263
ROLODEX_URL = ""
264264
PUBLIC_KEYS_URL = BASE_DIR + "/public_keys/"
265-
NOMCOM_FROM_EMAIL = ''
265+
NOMCOM_FROM_EMAIL = DEFAULT_FROM_EMAIL
266+
NOMCOM_ADMIN_EMAIL = DEFAULT_FROM_EMAIL
266267

267268
# Days from meeting to cut off dates on submit
268269
FIRST_CUTOFF_DAYS = 19

0 commit comments

Comments
 (0)