2121 Position , Feedback
2222from ietf .nomcom .utils import QUESTIONNAIRE_TEMPLATE , NOMINATION_EMAIL_TEMPLATE , \
2323 INEXISTENT_PERSON_TEMPLATE , NOMINEE_EMAIL_TEMPLATE , \
24- NOMINATION_RECEIPT_TEMPLATE , get_user_email
24+ NOMINATION_RECEIPT_TEMPLATE , FEEDBACK_RECEIPT_TEMPLATE , \
25+ get_user_email
2526from ietf .nomcom .decorators import member_required
2627
2728ROLODEX_URL = getattr (settings , 'ROLODEX_URL' , None )
@@ -288,7 +289,7 @@ class NominateForm(BaseNomcomForm, forms.ModelForm):
288289 widget = forms .Textarea ())
289290 confirmation = forms .BooleanField (label = 'Email comments back to me as confirmation' ,
290291 help_text = "If you want to get a confirmation mail containing your feedback in cleartext, \
291- please check the 'email comments back to me as confirmation' box below. " ,
292+ please check the 'email comments back to me as confirmation'" ,
292293 required = False )
293294
294295 fieldsets = [('Candidate Nomination' , ('position' , 'candidate_name' ,
@@ -300,8 +301,16 @@ def __init__(self, *args, **kwargs):
300301 self .public = kwargs .pop ('public' , None )
301302
302303 super (NominateForm , self ).__init__ (* args , ** kwargs )
304+
305+ fieldset = ['nominator_email' ,
306+ 'position' ,
307+ 'candidate_name' ,
308+ 'candidate_email' , 'candidate_phone' ,
309+ 'comments' ]
310+
303311 if self .nomcom :
304- self .fields ['position' ].queryset = Position .objects .filter (nomcom = self .nomcom )
312+ self .fields ['position' ].queryset = Position .objects .get_by_nomcom (self .nomcom ).opened ()
313+
305314 if not self .public :
306315 author = get_user_email (self .user )
307316 if author :
@@ -310,11 +319,10 @@ def __init__(self, *args, **kwargs):
310319 nomination wishes to be anonymous. The confirmation email will be sent to the address given here,
311320 and the address will also be captured as part of the registered nomination.)"""
312321 self .fields ['nominator_email' ].help_text = help_text
313- self .fieldsets = [('Candidate Nomination' , ('nominator_email' ,
314- 'position' ,
315- 'candidate_name' ,
316- 'candidate_email' , 'candidate_phone' ,
317- 'comments' ))]
322+ else :
323+ fieldset .append ('confirmation' )
324+
325+ self .fieldsets = [('Candidate Nomination' , fieldset )]
318326
319327 def save (self , commit = True ):
320328 # Create nomination
@@ -413,6 +421,7 @@ def save(self, commit=True):
413421 path = nomcom_template_path + NOMINATION_EMAIL_TEMPLATE
414422 send_mail (None , to_email , from_email , subject , path , context )
415423
424+ # send receipt email to nominator
416425 if confirmation or not self .public :
417426 if author :
418427 subject = 'Nomination Receipt'
@@ -437,39 +446,130 @@ class Media:
437446
438447
439448class FeedbackForm (BaseNomcomForm , forms .ModelForm ):
440- position = forms .CharField (label = 'position' )
441- nominee_name = forms .CharField (label = 'nominee name' )
442- nominee_email = forms .CharField (label = 'nominee email' )
449+ position_name = forms .CharField (label = 'position' ,
450+ widget = forms .TextInput (attrs = {'size' : '40' }))
451+ nominee_name = forms .CharField (label = 'your name' ,
452+ widget = forms .TextInput (attrs = {'size' : '40' }))
453+ nominee_email = forms .CharField (label = 'your email' ,
454+ widget = forms .TextInput (attrs = {'size' : '40' }))
443455 nominator_name = forms .CharField (label = 'nominator name' )
444456 nominator_email = forms .CharField (label = 'nominator email' )
445457
446- comments = forms .CharField (label = 'Comments on this candidate' , widget = forms .Textarea ())
447-
448- fieldsets = [('Provide comments' , ('position' ,
449- 'nominee_name' ,
450- 'nominee_email' ,
451- 'nominator_name' ,
452- 'nominator_email' ,
453- 'comments' ))]
458+ comments = forms .CharField (label = 'Comments on this candidate' ,
459+ widget = forms .Textarea ())
460+ confirmation = forms .BooleanField (label = 'Email comments back to me as confirmation' ,
461+ help_text = "If you want to get a confirmation mail containing your feedback in cleartext, \
462+ please check the 'email comments back to me as confirmation'" ,
463+ required = False )
454464
455465 def __init__ (self , * args , ** kwargs ):
456466 self .nomcom = kwargs .pop ('nomcom' , None )
457467 self .user = kwargs .pop ('user' , None )
458468 self .public = kwargs .pop ('public' , None )
469+ self .position = kwargs .pop ('position' , None )
470+ self .nominee = kwargs .pop ('nominee' , None )
459471
460472 super (FeedbackForm , self ).__init__ (* args , ** kwargs )
461473
474+ readonly_fields = ['position_name' ,
475+ 'nominee_name' ,
476+ 'nominee_email' ]
477+
478+ fieldset = ['position_name' ,
479+ 'nominee_name' ,
480+ 'nominee_email' ,
481+ 'nominator_name' ,
482+ 'nominator_email' ,
483+ 'comments' ,
484+ 'position' ,
485+ 'type' ,
486+ 'nominee' ]
487+
488+ if self .public :
489+ readonly_fields += ['nominator_name' , 'nominator_email' ]
490+ fieldset .append ('confirmation' )
491+ else :
492+ help_text = """(Nomcom Chair/Member: please fill this in. Use your own email address if the person making the
493+ comments wishes to be anonymous. The confirmation email will be sent to the address given here,
494+ and the address will also be captured as part of the registered nomination.)"""
495+ self .fields ['nominator_email' ].help_text = help_text
496+
497+ hidden_fields = ['position' , 'type' , 'nominee' ]
498+
499+ author = get_user_email (self .user )
500+ if author :
501+ self .fields ['nominator_email' ].initial = author .address
502+ self .fields ['nominator_name' ].initial = author .person .name
503+
504+ if self .position and self .nominee :
505+ self .fields ['type' ].initial = "comment"
506+ self .fields ['position' ].initial = self .position
507+ self .fields ['position_name' ].initial = self .position .name
508+ self .fields ['nominee' ].initial = self .nominee
509+ self .fields ['nominee_name' ].initial = self .nominee .email .person .name
510+ self .fields ['nominee_email' ].initial = self .nominee .email .address
511+ else :
512+ help_text = "Please pick a name on the nominees list"
513+ self .fields ['position_name' ].initial = help_text
514+ self .fields ['nominee_name' ].initial = help_text
515+ self .fields ['nominee_email' ].initial = help_text
516+ self .fields ['comments' ].initial = help_text
517+ readonly_fields += ['comments' ]
518+ self .fields ['confirmation' ].widget .attrs ['disabled' ] = "disabled"
519+
520+ for field in readonly_fields :
521+ self .fields [field ].widget .attrs ['readonly' ] = True
522+
523+ for field in hidden_fields :
524+ self .fields [field ].widget = forms .HiddenInput ()
525+
526+ self .fieldsets = [('Provide comments' , fieldset )]
527+
462528 def save (self , commit = True ):
463- pass
529+ feedback = super (FeedbackForm , self ).save (commit = False )
530+ confirmation = self .cleaned_data ['confirmation' ]
531+ nominee = self .cleaned_data ['nominee' ]
532+ position = self .cleaned_data ['position' ]
533+ comments = self .cleaned_data ['comments' ]
534+ nominator_email = self .cleaned_data ['nominator_email' ]
535+ nomcom_template_path = '/nomcom/%s/' % self .nomcom .group .acronym
536+
537+ author = None
538+ if self .public :
539+ author = get_user_email (self .user )
540+ else :
541+ if nominator_email :
542+ emails = Email .objects .filter (address = nominator_email )
543+ author = emails and emails [0 ] or None
544+
545+ if author :
546+ feedback .author = author
547+ feedback .save ()
548+
549+ # send receipt email to feedback author
550+ if confirmation or not self .public :
551+ if author :
552+ subject = "NomCom comment confirmation"
553+ from_email = settings .NOMCOM_FROM_EMAIL
554+ to_email = author .address
555+ context = {'nominee' : nominee .email .person .name ,
556+ 'comments' : comments ,
557+ 'position' : position .name }
558+ path = nomcom_template_path + FEEDBACK_RECEIPT_TEMPLATE
559+ send_mail (None , to_email , from_email , subject , path , context )
464560
465561 class Meta :
466562 model = Feedback
467- fields = ('position' ,
563+ fields = ('author' ,
564+ 'position' ,
565+ 'nominee' ,
468566 'nominee_name' ,
469567 'nominee_email' ,
470568 'nominator_name' ,
471569 'nominator_email' ,
472- 'comments' )
570+ 'confirmation' ,
571+ 'comments' ,
572+ 'type' )
473573
474574 class Media :
475575 js = ("/js/jquery-1.5.1.min.js" ,
0 commit comments