22
33from ietf .group .models import Group , Role
44from ietf .ietfauth .utils import has_role
5- from ietf .message .models import Message
6- from ietf .secr .utils .group import current_nomcom
5+ from ietf .message .models import Message , AnnouncementFrom
76from ietf .utils .fields import MultiEmailField
87
98# ---------------------------------------------
109# Globals
1110# ---------------------------------------------
1211
13- ANNOUNCE_FROM_GROUPS = ['ietf' ,'rsoc' ,'iab' ]
14- if current_nomcom ():
15- ANNOUNCE_FROM_GROUPS += [ current_nomcom ().acronym ]
16- ANNOUNCE_TO_GROUPS = ['ietf' ]
17-
18- # this list isn't currently available as a Role query so it's hardcoded
19- FROM_LIST = ('IETF Secretariat <ietf-secretariat@ietf.org>' ,
20- 'IESG Secretary <iesg-secretary@ietf.org>' ,
21- 'The IESG <iesg@ietf.org>' ,
22- 'Internet-Drafts Administrator <internet-drafts@ietf.org>' ,
23- 'IETF Agenda <agenda@ietf.org>' ,
24- 'IETF Chair <chair@ietf.org>' ,
25- 'IAB Chair <iab-chair@ietf.org> ' ,
26- 'NomCom Chair <nomcom-chair@ietf.org>' ,
27- 'IETF Registrar <ietf-registrar@ietf.org>' ,
28- 'IETF Administrative Director <iad@ietf.org>' ,
29- 'IETF Executive Director <exec-director@ietf.org>' ,
30- 'IAOC Chair <iaoc-chair@ietf.org>' ,
31- 'The IETF Trust <ietf-trust@ietf.org>' ,
32- 'RSOC Chair <rsoc-chair@iab.org>' ,
33- 'ISOC Board of Trustees <bob.hinden@gmail.com>' ,
34- 'RFC Series Editor <rse@rfc-editor.org>' ,
35- 'IAB Executive Administrative Manager <execd@iab.org>' ,
36- 'IETF Mentoring Program <mentoring@ietf.org>' ,
37- 'ISOC CEO <ceo@isoc.org>' )
38-
3912TO_LIST = ('IETF Announcement List <ietf-announce@ietf.org>' ,
4013 'I-D Announcement List <i-d-announce@ietf.org>' ,
4114 'The IESG <iesg@ietf.org>' ,
@@ -53,85 +26,48 @@ def get_from_choices(user):
5326 all the Announced From choices. Including
5427 leadership chairs and other entities.
5528 '''
56- person = user .person
57- f = []
29+ addresses = []
5830 if has_role (user ,'Secretariat' ):
59- f = FROM_LIST
60- elif has_role (user ,'IETF Chair' ):
61- f = (FROM_LIST [2 ],FROM_LIST [5 ])
62- elif has_role (user ,'IAB Chair' ):
63- f = (FROM_LIST [6 ],)
64- elif has_role (user ,'IAD' ):
65- f = (FROM_LIST [9 ],FROM_LIST [12 ],FROM_LIST [18 ],FROM_LIST [11 ],)
66- #RSOC Chair, IAOC Chair aren't supported by has_role()
67- elif Role .objects .filter (person = person ,
68- group__acronym = 'rsoc' ,
69- name = "chair" ):
70- f = (FROM_LIST [13 ],)
71- elif Role .objects .filter (person = person ,
72- group__acronym = 'iaoc' ,
73- name = "chair" ):
74- f = (FROM_LIST [11 ],)
75- elif Role .objects .filter (person = person ,
76- group__acronym = 'rse' ,
77- name = "chair" ):
78- f = (FROM_LIST [15 ],)
79- elif Role .objects .filter (person = person ,
80- group__acronym = 'iab' ,
81- name = 'execdir' ):
82- f = (FROM_LIST [6 ],FROM_LIST [16 ])
83- elif Role .objects .filter (person = person ,
84- group__acronym = 'mentor' ,
85- name = "chair" ):
86- f = (FROM_LIST [17 ],)
87- elif Role .objects .filter (person = person ,
88- group__acronym = 'isoc' ,
89- name = "ceo" ):
90- f = (FROM_LIST [18 ],)
91- elif Role .objects .filter (person = person ,
92- group__acronym = 'isocbot' ,
93- name = "chair" ):
94- f = (FROM_LIST [14 ],)
95- elif Role .objects .filter (person = person ,
96- group__acronym = 'ietf-trust' ,
97- name = "chair" ):
98- f = (FROM_LIST [12 ],)
99-
100- # NomCom
31+ addresses = AnnouncementFrom .objects .values_list ('address' , flat = True ).order_by ('address' ).distinct ()
32+ else :
33+ for role in user .person .role_set .all ():
34+ addresses .extend (AnnouncementFrom .objects .filter (name = role .name , group = role .group ).values_list ('address' , flat = True ).order_by ('address' ))
35+
36+ nomcom_choices = get_nomcom_choices (user )
37+ if nomcom_choices :
38+ addresses = list (addresses ) + nomcom_choices
39+
40+ return zip (addresses , addresses )
41+
42+
43+ def get_nomcom_choices (user ):
44+ '''
45+ Returns the list of nomcom email addresses for given user
46+ '''
10147 nomcoms = Role .objects .filter (name = "chair" ,
10248 group__acronym__startswith = "nomcom" ,
10349 group__state = "active" ,
10450 group__type = "nomcom" ,
105- person = person )
106- if nomcoms :
107- year = nomcoms [ 0 ]. group . acronym [ - 4 :]
108- alias = 'NomCom Chair %s < nomcom-chair-%s@ietf.org>' % ( year , year )
109- f = ( alias , )
51+ person = user . person )
52+ addresses = []
53+ for nomcom in nomcoms :
54+ year = nomcom . group . acronym [ - 4 :]
55+ addresses . append ( 'NomCom Chair %s <nomcom-chair-%s@ietf.org>' % ( year , year ) )
11056
111- return zip (f ,f )
57+ return addresses
58+
11259
11360def get_to_choices ():
114- #groups = Group.objects.filter(acronym__in=ANNOUNCE_TO_GROUPS)
115- #roles = Role.objects.filter(group__in=(groups),name="Announce")
116- #choices = [ (r.email, r.person.name) for r in roles ]
117- #choices.append(('Other...','Other...'),)
11861 return zip (TO_LIST ,TO_LIST )
11962
120- # ---------------------------------------------
121- # Select Choices
122- # ---------------------------------------------
123- TO_CHOICES = get_to_choices ()
124- #FROM_CHOICES = get_from_choices()
12563
12664# ---------------------------------------------
12765# Forms
12866# ---------------------------------------------
12967
13068class AnnounceForm (forms .ModelForm ):
131- #nomcom = forms.BooleanField(required=False)
13269 nomcom = forms .ModelChoiceField (queryset = Group .objects .filter (acronym__startswith = 'nomcom' ,type = 'nomcom' ,state = 'active' ),required = False )
13370 to_custom = MultiEmailField (required = False ,label = '' )
134- #cc = MultiEmailField(required=False)
13571
13672 class Meta :
13773 model = Message
@@ -145,7 +81,7 @@ def __init__(self, *args, **kwargs):
14581 user = kwargs .pop ('user' )
14682 person = user .person
14783 super (AnnounceForm , self ).__init__ (* args , ** kwargs )
148- self .fields ['to' ].widget = forms .Select (choices = TO_CHOICES )
84+ self .fields ['to' ].widget = forms .Select (choices = get_to_choices () )
14985 self .fields ['to' ].help_text = 'Select name OR select Other... and enter email below'
15086 self .fields ['cc' ].help_text = 'Use comma separated lists for emails (Cc, Bcc, Reply To)'
15187 self .fields ['frm' ].widget = forms .Select (choices = get_from_choices (user ))
0 commit comments