1717from ietf .nomcom .models import NomCom , Nomination , Nominee , NomineePosition , \
1818 Position , Feedback
1919from ietf .nomcom .utils import QUESTIONNAIRE_TEMPLATE , NOMINATION_EMAIL_TEMPLATE , \
20- INEXISTENT_PERSON_TEMPLATE , NOMINEE_EMAIL_TEMPLATE
20+ INEXISTENT_PERSON_TEMPLATE , NOMINEE_EMAIL_TEMPLATE , \
21+ get_user_email
2122from ietf .nomcom .decorators import member_required
2223
2324ROLODEX_URL = getattr (settings , 'ROLODEX_URL' , None )
@@ -186,18 +187,30 @@ def __init__(self, *args, **kwargs):
186187class NominateForm (BaseNomcomForm , forms .ModelForm ):
187188 comments = forms .CharField (label = 'Comments' , widget = forms .Textarea ())
188189
189- fieldsets = [('Candidate Nomination' , ('position' , 'candidate_name' , 'candidate_email' , 'candidate_phone' , 'comments' ))]
190+ fieldsets = [('Candidate Nomination' , ('position' , 'candidate_name' ,
191+ 'candidate_email' , 'candidate_phone' , 'comments' ))]
190192
191193 def __init__ (self , * args , ** kwargs ):
192194 self .nomcom = kwargs .pop ('nomcom' , None )
193195 self .user = kwargs .pop ('user' , None )
196+ self .public = kwargs .pop ('public' , None )
197+
194198 super (NominateForm , self ).__init__ (* args , ** kwargs )
195199 if self .nomcom :
196200 self .fields ['position' ].queryset = Position .objects .filter (nomcom = self .nomcom )
201+ if not self .public :
202+ author = get_user_email (self .user )
203+ if author :
204+ self .fields ['nominator_email' ].initial = author .address
205+ self .fieldsets = [('Candidate Nomination' , ('position' ,
206+ 'nominator_email' , 'candidate_name' ,
207+ 'candidate_email' , 'candidate_phone' ,
208+ 'comments' ))]
197209
198210 def save (self , commit = True ):
199211 # Create nomination
200212 nomination = super (NominateForm , self ).save (commit = False )
213+ nominator_email = self .cleaned_data .get ('nominator_email' , None )
201214 candidate_email = self .cleaned_data ['candidate_email' ]
202215 candidate_name = self .cleaned_data ['candidate_name' ]
203216 position = self .cleaned_data ['position' ]
@@ -219,12 +232,18 @@ def save(self, commit=True):
219232 nominee_position , nominee_position_created = NomineePosition .objects .get_or_create (position = position , nominee = nominee )
220233
221234 # Complete nomination data
222- author_emails = Email .objects .filter (person__user = self .user )
223- author = author_emails and author_emails [0 ] or None
224235 feedback = Feedback .objects .create (position = position ,
225236 nominee = nominee ,
226237 comments = comments ,
227238 type = FeedbackType .objects .get (slug = 'nomina' ))
239+ author = None
240+ if self .public :
241+ author = get_user_email (self .user )
242+ else :
243+ if nominator_email :
244+ emails = Email .objects .filter (address = nominator_email )
245+ author = emails and emails [0 ] or None
246+
228247 if author :
229248 nomination .nominator_email = author .address
230249 feedback .author = author
@@ -287,7 +306,7 @@ def save(self, commit=True):
287306
288307 class Meta :
289308 model = Nomination
290- fields = ('position' , 'candidate_name' , 'candidate_email' , 'candidate_phone' )
309+ fields = ('position' , 'nominator_email' , ' candidate_name' , 'candidate_email' , 'candidate_phone' )
291310
292311 class Media :
293312 js = ("/js/jquery-1.5.1.min.js" ,
0 commit comments