1313# Globals
1414# ---------------------------------------------
1515
16- #ANNOUNCE_FROM_GROUPS = ['ietf','rsoc','iab',current_nomcom().acronym]
16+ ANNOUNCE_FROM_GROUPS = ['ietf' ,'rsoc' ,'iab' ]
17+ if current_nomcom ():
18+ ANNOUNCE_FROM_GROUPS += [ current_nomcom ().acronym ]
1719ANNOUNCE_TO_GROUPS = ['ietf' ]
1820
1921# this list isn't currently available as a Role query so it's hardcoded
3234 'The IETF Trust <tme@multicasttech.com>' ,
3335 'RSOC Chair <rsoc-chair@iab.org>' ,
3436 'ISOC Board of Trustees <eburger@standardstrack.com>' ,
35- 'RFC Series Editor <rse@rfc-editor.org>' )
36-
37+ 'RFC Series Editor <rse@rfc-editor.org>' ,
38+ 'IAB Executive Director <execd@iab.org>' )
39+
3740TO_LIST = ('IETF Announcement List <ietf-announce@ietf.org>' ,
3841 'I-D Announcement List <i-d-announce@ietf.org>' ,
3942 'The IESG <iesg@ietf.org>' ,
@@ -51,14 +54,14 @@ def to_python(self, value):
5154 # Return an empty list if no input was given.
5255 if not value :
5356 return []
54-
57+
5558 import types
5659 if isinstance (value , types .StringTypes ):
5760 values = value .split (',' )
5861 return [ x .strip () for x in values ]
5962 else :
6063 return value
61-
64+
6265 def validate (self , value ):
6366 "Check if value consists only of valid emails."
6467
@@ -67,7 +70,7 @@ def validate(self, value):
6770
6871 for email in value :
6972 validate_email (email )
70-
73+
7174# ---------------------------------------------
7275# Helper Functions
7376# ---------------------------------------------
@@ -87,13 +90,7 @@ def get_from_choices(user):
8790 f = (FROM_LIST [6 ],)
8891 elif has_role (user ,'IAD' ):
8992 f = (FROM_LIST [9 ],)
90- # NomCom, RSOC Chair, IAOC Chair aren't supported by has_role()
91- elif Role .objects .filter (name = "chair" ,
92- group__acronym__startswith = "nomcom" ,
93- group__state = "active" ,
94- group__type = "ietf" ,
95- person = person ):
96- f = (FROM_LIST [7 ],)
93+ #RSOC Chair, IAOC Chair aren't supported by has_role()
9794 elif Role .objects .filter (person = person ,
9895 group__acronym = 'rsoc' ,
9996 name = "chair" ):
@@ -106,17 +103,33 @@ def get_from_choices(user):
106103 group__acronym = 'rse' ,
107104 name = "chair" ):
108105 f = (FROM_LIST [15 ],)
106+ elif Role .objects .filter (person = person ,
107+ group__acronym = 'iab' ,
108+ name = 'execdir' ):
109+ f = (FROM_LIST [6 ],FROM_LIST [16 ])
110+
111+ # NomCom
112+ nomcoms = Role .objects .filter (name = "chair" ,
113+ group__acronym__startswith = "nomcom" ,
114+ group__state = "active" ,
115+ group__type = "ietf" ,
116+ person = person )
117+ if nomcoms :
118+ year = nomcoms [0 ].group .acronym [- 4 :]
119+ alias = 'NomCom Chair %s <nomcom-chair-%s@ietf.org>' % (year ,year )
120+ f = (alias ,)
121+
109122 return zip (f ,f )
110-
123+
111124def get_to_choices ():
112125 #groups = Group.objects.filter(acronym__in=ANNOUNCE_TO_GROUPS)
113126 #roles = Role.objects.filter(group__in=(groups),name="Announce")
114127 #choices = [ (r.email, r.person.name) for r in roles ]
115128 #choices.append(('Other...','Other...'),)
116129 return zip (TO_LIST ,TO_LIST )
117-
130+
118131# ---------------------------------------------
119- # Select Choices
132+ # Select Choices
120133# ---------------------------------------------
121134#TO_CHOICES = tuple(AnnouncedTo.objects.values_list('announced_to_id','announced_to'))
122135TO_CHOICES = get_to_choices ()
@@ -127,34 +140,43 @@ def get_to_choices():
127140# ---------------------------------------------
128141
129142class AnnounceForm (forms .ModelForm ):
130- nomcom = forms .BooleanField (required = False )
143+ #nomcom = forms.BooleanField(required=False)
144+ nomcom = forms .ModelChoiceField (queryset = Group .objects .filter (acronym__startswith = 'nomcom' ,type = 'ietf' ,state = 'active' ),required = False )
131145 to_custom = MultiEmailField (required = False ,label = '' )
132146 #cc = MultiEmailField(required=False)
133-
147+
134148 class Meta :
135149 model = Message
136150 fields = ('nomcom' , 'to' ,'to_custom' ,'frm' ,'cc' ,'bcc' ,'reply_to' ,'subject' ,'body' )
137-
151+
138152 def __init__ (self , * args , ** kwargs ):
139153 user = kwargs .pop ('user' )
154+ person = user .get_profile ()
140155 super (AnnounceForm , self ).__init__ (* args , ** kwargs )
141156 self .fields ['to' ].widget = forms .Select (choices = TO_CHOICES )
142157 self .fields ['to' ].help_text = 'Select name OR select Other... and enter email below'
143158 self .fields ['cc' ].help_text = 'Use comma separated lists for emails (Cc, Bcc, Reply To)'
144159 self .fields ['frm' ].widget = forms .Select (choices = get_from_choices (user ))
145160 self .fields ['frm' ].label = 'From'
146- self .fields ['nomcom' ].label = 'NomCom message?'
147-
161+ self .fields ['nomcom' ].label = 'NomCom message:'
162+ nomcom_roles = person .role_set .filter (group__in = self .fields ['nomcom' ].queryset ,name = 'chair' )
163+ secr_roles = person .role_set .filter (group__acronym = 'secretariat' ,name = 'secr' )
164+ if nomcom_roles :
165+ self .initial ['nomcom' ] = nomcom_roles [0 ].group .pk
166+ if not nomcom_roles and not secr_roles :
167+ self .fields ['nomcom' ].widget = forms .HiddenInput ()
168+ self .initial ['reply_to' ] = 'ietf@ietf.org'
169+
148170 def clean (self ):
149171 super (AnnounceForm , self ).clean ()
150172 data = self .cleaned_data
151173 if self .errors :
152174 return self .cleaned_data
153175 if data ['to' ] == 'Other...' and not data ['to_custom' ]:
154176 raise forms .ValidationError ('You must enter a "To" email address' )
155-
177+
156178 return data
157-
179+
158180 def save (self , * args , ** kwargs ):
159181 user = kwargs .pop ('user' )
160182 message = super (AnnounceForm , self ).save (commit = False )
@@ -163,10 +185,10 @@ def save(self, *args, **kwargs):
163185 message .to = self .cleaned_data ['to_custom' ]
164186 if kwargs ['commit' ]:
165187 message .save ()
166-
167- # add nomcom to related groups if checked
168- if self .cleaned_data .get ('nomcom' , False ):
169- nomcom = current_nomcom ()
188+
189+ # handle nomcom message
190+ nomcom = self .cleaned_data .get ('nomcom' ,False )
191+ if nomcom :
170192 message .related_groups .add (nomcom )
171-
193+
172194 return message
0 commit comments