@@ -176,7 +176,8 @@ def save_position(form, doc, ballot, ad, login=None):
176176
177177 for e in added_events :
178178 e .save () # save them after the position is saved to get later id for sorting order
179-
179+
180+ return pos
180181
181182@role_required ('Area Director' ,'Secretariat' )
182183def edit_position (request , name , ballot_id ):
@@ -271,17 +272,53 @@ def err(code, text):
271272 return err (400 , "No open ballot found" )
272273 form = EditPositionForm (request .POST , ballot_type = ballot .ballot_type )
273274 if form .is_valid ():
274- save_position (form , doc , ballot , ad )
275+ pos = save_position (form , doc , ballot , ad )
275276 else :
276277 errors = form .errors
277278 summary = ',' .join ([ "%s: %s" % (f , striptags (errors [f ])) for f in errors ])
278279 return err (400 , "Form not valid: %s" % summary )
279280 else :
280281 return err (405 , "Method not allowed" )
281282
283+ # send position email
284+ addrs , frm , subject , body = build_position_email (ad , doc , pos )
285+ send_mail_text (request , addrs .to , frm , subject , body , cc = addrs .cc )
286+
282287 return HttpResponse ("Done" , status = 200 , content_type = 'text/plain' )
283288
284289
290+ def build_position_email (ad , doc , pos ):
291+ subj = []
292+ d = ""
293+ blocking_name = "DISCUSS"
294+ if pos .pos .blocking and pos .discuss :
295+ d = pos .discuss
296+ blocking_name = pos .pos .name .upper ()
297+ subj .append (blocking_name )
298+ c = ""
299+ if pos .comment :
300+ c = pos .comment
301+ subj .append ("COMMENT" )
302+
303+ ad_name_genitive = ad .plain_name () + "'" if ad .plain_name ().endswith ('s' ) else ad .plain_name () + "'s"
304+ subject = "%s %s on %s" % (ad_name_genitive , pos .pos .name if pos .pos else "No Position" , doc .name + "-" + doc .rev )
305+ if subj :
306+ subject += ": (with %s)" % " and " .join (subj )
307+
308+ body = render_to_string ("doc/ballot/ballot_comment_mail.txt" ,
309+ dict (discuss = d ,
310+ comment = c ,
311+ ad = ad .plain_name (),
312+ doc = doc ,
313+ pos = pos .pos ,
314+ blocking_name = blocking_name ,
315+ settings = settings ))
316+ frm = ad .role_email ("ad" ).formatted_email ()
317+
318+ addrs = gather_address_lists ('ballot_saved' ,doc = doc )
319+
320+ return addrs , frm , subject , body
321+
285322@role_required ('Area Director' ,'Secretariat' )
286323def send_ballot_comment (request , name , ballot_id ):
287324 """Email document ballot position discuss/comment for Area Director."""
@@ -311,35 +348,8 @@ def send_ballot_comment(request, name, ballot_id):
311348 if not pos :
312349 raise Http404
313350
314- subj = []
315- d = ""
316- blocking_name = "DISCUSS"
317- if pos .pos .blocking and pos .discuss :
318- d = pos .discuss
319- blocking_name = pos .pos .name .upper ()
320- subj .append (blocking_name )
321- c = ""
322- if pos .comment :
323- c = pos .comment
324- subj .append ("COMMENT" )
325-
326- ad_name_genitive = ad .plain_name () + "'" if ad .plain_name ().endswith ('s' ) else ad .plain_name () + "'s"
327- subject = "%s %s on %s" % (ad_name_genitive , pos .pos .name if pos .pos else "No Position" , doc .name + "-" + doc .rev )
328- if subj :
329- subject += ": (with %s)" % " and " .join (subj )
351+ addrs , frm , subject , body = build_position_email (ad , doc , pos )
330352
331- body = render_to_string ("doc/ballot/ballot_comment_mail.txt" ,
332- dict (discuss = d ,
333- comment = c ,
334- ad = ad .plain_name (),
335- doc = doc ,
336- pos = pos .pos ,
337- blocking_name = blocking_name ,
338- settings = settings ))
339- frm = ad .role_email ("ad" ).formatted_email ()
340-
341- addrs = gather_address_lists ('ballot_saved' ,doc = doc )
342-
343353 if request .method == 'POST' :
344354 cc = []
345355 cc_select_form = CcSelectForm (data = request .POST ,mailtrigger_slug = 'ballot_saved' ,mailtrigger_context = {'doc' :doc })
@@ -364,7 +374,6 @@ def send_ballot_comment(request, name, ballot_id):
364374 frm = frm ,
365375 to = addrs .as_strings ().to ,
366376 ad = ad ,
367- can_send = d or c ,
368377 back_url = back_url ,
369378 cc_select_form = cc_select_form ,
370379 ))
0 commit comments