@@ -64,7 +64,7 @@ def __init__(self, user, *args, **kwargs):
6464 def __unicode__ (self ):
6565 return self .as_div ()
6666
67- def set_purpose_required_fields (self ):
67+ def set_required_fields (self ):
6868 purpose = self .data .get ('purpose' , None )
6969 if purpose == '5' :
7070 self .fields ['purpose_text' ].required = True
@@ -75,7 +75,7 @@ def set_purpose_required_fields(self):
7575 else :
7676 self .fields ['deadline_date' ].required = False
7777
78- def reset_purpose_required_fields (self ):
78+ def reset_required_fields (self ):
7979 self .fields ['purpose_text' ].required = True
8080 self .fields ['deadline_date' ].required = True
8181
@@ -107,9 +107,9 @@ def get_fieldsets(self):
107107 yield fieldset_dict
108108
109109 def full_clean (self ):
110- self .set_purpose_required_fields ()
110+ self .set_required_fields ()
111111 super (LiaisonForm , self ).full_clean ()
112- self .reset_purpose_required_fields ()
112+ self .reset_required_fields ()
113113
114114 def has_attachments (self ):
115115 for key in self .files .keys ():
@@ -129,23 +129,28 @@ def get_from_entity(self):
129129
130130 def get_to_entity (self ):
131131 organization_key = self .cleaned_data .get ('organization' )
132- organization = self .hm .get_entity_by_key (organization_key )
133- if not organization and self .cleaned_data .get ('other_organization' , None ):
134- return self .cleaned_data .get ('other_organization' )
135- return organization
132+ return self .hm .get_entity_by_key (organization_key )
133+
134+ def get_poc (self , organization ):
135+ return ', ' .join ([i .email ()[1 ] for i in organization .get_poc ()])
136+
137+ def get_cc (self , from_entity , to_entity ):
138+ persons = to_entity .get_cc (self .person )
139+ persons += from_entity .get_from_cc (self .person )
140+ return ', ' .join (['%s <%s>' % i .email () for i in persons ])
136141
137142 def save (self , * args , ** kwargs ):
138143 now = datetime .datetime .now ()
139144 liaison = super (LiaisonForm , self ).save (* args , ** kwargs )
140145 liaison .submitted_date = now
141146 liaison .last_modified_date = now
142- from_entity = self .get_from_entity ()
147+ from_entity = self .get_from_entity ()
143148 liaison .from_raw_body = from_entity .name
144- organization = self .get_to_entity ()
149+ organization = self .get_to_entity ()
145150 liaison .to_body = organization .name
146- liaison .to_poc = ', ' . join ([ i . email ()[ 1 ] for i in organization . get_poc ()] )
151+ liaison .to_poc = self . get_poc (organization )
147152 liaison .submitter_name , liaison .submitter_email = self .person .email ()
148- liaison .cc1 = ', ' . join ([ '%s <%s>' % i . email () for i in organization . get_cc ()] )
153+ liaison .cc1 = self . get_cc ( from_entity , organization )
149154 liaison .save ()
150155 self .save_attachments (liaison )
151156
@@ -165,7 +170,7 @@ def save_attachments(self, instance):
165170 file_title = self .data .get (title_key ),
166171 person = self .person ,
167172 detail = instance ,
168- file_extension = extension
173+ file_extension = extension ,
169174 )
170175
171176
@@ -187,6 +192,13 @@ class OutgoingLiaisonForm(LiaisonForm):
187192 to_poc = forms .CharField (label = "POC" , required = True )
188193 other_organization = forms .CharField (label = "Other SDO" , required = True )
189194
195+ def get_to_entity (self ):
196+ organization_key = self .cleaned_data .get ('organization' )
197+ organization = self .hm .get_entity_by_key (organization_key )
198+ if organization_key == 'othersdo' and self .cleaned_data .get ('other_organization' , None ):
199+ organization .name = self .cleaned_data ['other_organization' ]
200+ return organization
201+
190202 def set_from_field (self ):
191203 self .fields ['from_field' ].choices = self .hm .get_entities_for_person (self .person )
192204 self .fields ['from_field' ].widget .submitter = unicode (self .person )
@@ -195,6 +207,21 @@ def set_organization_field(self):
195207 self .fields ['organization' ].choices = self .hm .get_all_outgoing_entities ()
196208 self .fieldsets [1 ] = ('To' , ('organization' , 'other_organization' , 'to_poc' ))
197209
210+ def set_required_fields (self ):
211+ super (OutgoingLiaisonForm , self ).set_required_fields ()
212+ organization = self .data .get ('organization' , None )
213+ if organization == 'othersdo' :
214+ self .fields ['other_organization' ].required = True
215+ else :
216+ self .fields ['other_organization' ].required = False
217+
218+ def reset_required_fields (self ):
219+ super (OutgoingLiaisonForm , self ).reset_required_fields ()
220+ self .fields ['other_organization' ].required = True
221+
222+ def get_poc (self , organization ):
223+ return self .cleaned_data ['to_poc' ]
224+
198225
199226def liaison_form_factory (request , ** kwargs ):
200227 user = request .user
0 commit comments