1+ from django .conf import settings
12from django import forms
23from django .contrib .formtools .preview import FormPreview
34from django .http import HttpResponseRedirect , HttpResponseForbidden
45from django .shortcuts import get_object_or_404
56from django .core .urlresolvers import reverse
6- from django .conf import settings
77
88from ietf .utils import unaccent
9+ from ietf .utils .mail import send_mail
910from ietf .ietfauth .decorators import has_role
1011from ietf .utils import fields as custom_fields
1112from ietf .group .models import Group , Role
1617
1718
1819ROLODEX_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
2126def 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 :
0 commit comments