55from django .utils .decorators import method_decorator
66from django .shortcuts import render_to_response
77from django .template .context import RequestContext
8+ from django .core .urlresolvers import reverse
9+ from django .utils .html import mark_safe
810
911from ietf .dbtemplate .forms import DBTemplateForm
1012from ietf .group .models import Group , Role
@@ -300,7 +302,7 @@ def save(self):
300302
301303
302304class NominateForm (forms .ModelForm ):
303- candidate = SearchableEmailField (only_users = False )
305+ searched_email = SearchableEmailField (only_users = False )
304306 qualifications = forms .CharField (label = "Candidate's qualifications for the position" ,
305307 widget = forms .Textarea ())
306308 confirmation = forms .BooleanField (label = 'Email comments back to me as confirmation.' ,
@@ -314,6 +316,9 @@ def __init__(self, *args, **kwargs):
314316
315317 super (NominateForm , self ).__init__ (* args , ** kwargs )
316318
319+ new_person_url_name = 'nomcom_%s_nominate_newperson' % ('public' if self .public else 'private' )
320+ self .fields ['searched_email' ].label = 'Candidate email'
321+ self .fields ['searched_email' ].help_text = 'Search by name or email address. Click <a href="%s">here</a> if the search does not find the candidate you want to nominate.' % reverse (new_person_url_name ,kwargs = {'year' :self .nomcom .year ()})
317322 self .fields ['nominator_email' ].label = 'Nominator email'
318323 if self .nomcom :
319324 self .fields ['position' ].queryset = Position .objects .get_by_nomcom (self .nomcom ).opened ()
@@ -339,18 +344,15 @@ def save(self, commit=True):
339344 # Create nomination
340345 nomination = super (NominateForm , self ).save (commit = False )
341346 nominator_email = self .cleaned_data .get ('nominator_email' , None )
342- ## TODO - rename this candidate_email after purging the old candidate_email
343- candidate = self .cleaned_data ['candidate' ]
344- ##candidate_email = self.cleaned_data['candidate_email']
345- ##candidate_name = self.cleaned_data['candidate_name']
347+ searched_email = self .cleaned_data ['searched_email' ]
346348 position = self .cleaned_data ['position' ]
347349 qualifications = self .cleaned_data ['qualifications' ]
348350 confirmation = self .cleaned_data .get ('confirmation' , False )
349351 share_nominator = self .cleaned_data ['share_nominator' ]
350352 nomcom_template_path = '/nomcom/%s/' % self .nomcom .group .acronym
351353
352- nomination .candidate_name = candidate .person .plain_name ()
353- nomination .candidate_email = candidate .address
354+ nomination .candidate_name = searched_email .person .plain_name ()
355+ nomination .candidate_email = searched_email .address
354356
355357 author = None
356358 if self .public :
@@ -359,8 +361,7 @@ def save(self, commit=True):
359361 if nominator_email :
360362 emails = Email .objects .filter (address = nominator_email )
361363 author = emails and emails [0 ] or None
362- ##nominee = get_or_create_nominee(self.nomcom, candidate_name, candidate_email, position, author)
363- nominee = get_or_create_nominee_by_person (self .nomcom , candidate .person , position , author )
364+ nominee = get_or_create_nominee_by_person (self .nomcom , searched_email .person , position , author )
364365
365366 # Complete nomination data
366367 feedback = Feedback .objects .create (nomcom = self .nomcom ,
@@ -399,10 +400,118 @@ def save(self, commit=True):
399400
400401 class Meta :
401402 model = Nomination
402- fields = ('share_nominator' , 'position' , 'nominator_email' , 'candidate ' ,
403+ fields = ('share_nominator' , 'position' , 'nominator_email' , 'searched_email ' ,
403404 'candidate_phone' , 'qualifications' , 'confirmation' )
404- ##fields = ('share_nominator', 'position', 'nominator_email', 'candidate', 'candidate_name',
405- ## 'candidate_email', 'candidate_phone', 'qualifications', 'confirmation')
405+
406+ class NominateNewPersonForm (forms .ModelForm ):
407+ qualifications = forms .CharField (label = "Candidate's qualifications for the position" ,
408+ widget = forms .Textarea ())
409+ confirmation = forms .BooleanField (label = 'Email comments back to me as confirmation.' ,
410+ help_text = "If you want to get a confirmation mail containing your feedback in cleartext, please check the 'email comments back to me as confirmation'." ,
411+ required = False )
412+
413+ def __init__ (self , * args , ** kwargs ):
414+ self .nomcom = kwargs .pop ('nomcom' , None )
415+ self .user = kwargs .pop ('user' , None )
416+ self .public = kwargs .pop ('public' , None )
417+
418+ super (NominateNewPersonForm , self ).__init__ (* args , ** kwargs )
419+
420+ self .fields ['nominator_email' ].label = 'Nominator email'
421+ if self .nomcom :
422+ self .fields ['position' ].queryset = Position .objects .get_by_nomcom (self .nomcom ).opened ()
423+ self .fields ['qualifications' ].help_text = self .nomcom .initial_text
424+
425+ if not self .public :
426+ self .fields .pop ('confirmation' )
427+ author = get_user_email (self .user )
428+ if author :
429+ self .fields ['nominator_email' ].initial = author .address
430+ help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
431+ nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
432+ and the address will also be captured as part of the registered nomination.)"""
433+ self .fields ['nominator_email' ].help_text = help_text
434+ self .fields ['share_nominator' ].help_text = """(Nomcom Chair/Member: Check this box if the person providing this nomination
435+ has indicated they will allow NomCom to share their name as one of the people
436+ nominating this candidate."""
437+ else :
438+ self .fields .pop ('nominator_email' )
439+
440+
441+ def clean_candidate_email (self ):
442+ candidate_email = self .cleaned_data ['candidate_email' ]
443+ if Email .objects .filter (address = candidate_email ).exists ():
444+ normal_url_name = 'nomcom_%s_nominate' % 'public' if self .public else 'private'
445+ msg = '%s is already in the datatracker. \
446+ Use the <a href="%s">normal nomination form</a> to nominate the person \
447+ with this address.\
448+ ' % (candidate_email ,reverse (normal_url_name ,kwargs = {'year' :self .nomcom .year ()}))
449+ raise forms .ValidationError (mark_safe (msg ))
450+ return candidate_email
451+
452+ def save (self , commit = True ):
453+ # Create nomination
454+ nomination = super (NominateNewPersonForm , self ).save (commit = False )
455+ nominator_email = self .cleaned_data .get ('nominator_email' , None )
456+ candidate_email = self .cleaned_data ['candidate_email' ]
457+ candidate_name = self .cleaned_data ['candidate_name' ]
458+ position = self .cleaned_data ['position' ]
459+ qualifications = self .cleaned_data ['qualifications' ]
460+ confirmation = self .cleaned_data .get ('confirmation' , False )
461+ share_nominator = self .cleaned_data ['share_nominator' ]
462+ nomcom_template_path = '/nomcom/%s/' % self .nomcom .group .acronym
463+
464+
465+ author = None
466+ if self .public :
467+ author = get_user_email (self .user )
468+ else :
469+ if nominator_email :
470+ emails = Email .objects .filter (address = nominator_email )
471+ author = emails and emails [0 ] or None
472+ ## This is where it should change - validation of the email field should fail if the email exists
473+ ## The function should become make_nominee_from_newperson)
474+ nominee = get_or_create_nominee (self .nomcom , candidate_name , candidate_email , position , author )
475+
476+ # Complete nomination data
477+ feedback = Feedback .objects .create (nomcom = self .nomcom ,
478+ comments = qualifications ,
479+ type = FeedbackTypeName .objects .get (slug = 'nomina' ),
480+ user = self .user )
481+ feedback .positions .add (position )
482+ feedback .nominees .add (nominee )
483+
484+ if author :
485+ nomination .nominator_email = author .address
486+ feedback .author = author .address
487+ feedback .save ()
488+
489+ nomination .nominee = nominee
490+ nomination .comments = feedback
491+ nomination .share_nominator = share_nominator
492+ nomination .user = self .user
493+
494+ if commit :
495+ nomination .save ()
496+
497+ # send receipt email to nominator
498+ if confirmation :
499+ if author :
500+ subject = 'Nomination receipt'
501+ from_email = settings .NOMCOM_FROM_EMAIL
502+ (to_email , cc ) = gather_address_lists ('nomination_receipt_requested' ,nominator = author .address )
503+ context = {'nominee' : nominee .email .person .name ,
504+ 'comments' : qualifications ,
505+ 'position' : position .name }
506+ path = nomcom_template_path + NOMINATION_RECEIPT_TEMPLATE
507+ send_mail (None , to_email , from_email , subject , path , context , cc = cc )
508+
509+ return nomination
510+
511+ class Meta :
512+ model = Nomination
513+ fields = ('share_nominator' , 'position' , 'nominator_email' , 'candidate_name' ,
514+ 'candidate_email' , 'candidate_phone' , 'qualifications' , 'confirmation' )
406515
407516
408517class FeedbackForm (forms .ModelForm ):
0 commit comments