22from datetime import datetime , date , time , timedelta
33from django .http import HttpResponse , HttpResponseRedirect , Http404
44from django .shortcuts import render_to_response , get_object_or_404
5+ from django .core .urlresolvers import reverse as urlreverse
56from django .template .loader import render_to_string
67from django .template import RequestContext
78from django import forms
89from django .utils .html import strip_tags
910
11+ from ietf .utils .mail import send_mail_text
1012from ietf .ietfauth .decorators import group_required
1113from ietf .idtracker .templatetags .ietf_filters import in_group
1214from ietf .idtracker .models import *
@@ -356,7 +358,16 @@ def position_to_ballot_choice(position):
356358
357359def position_label (position_value ):
358360 return dict (BALLOT_CHOICES ).get (position_value , "" )
359-
361+
362+ def get_ballot_info (ballot , area_director ):
363+ pos = Position .objects .filter (ballot = ballot , ad = area_director )
364+ pos = pos [0 ] if pos else None
365+ discuss = IESGDiscuss .objects .filter (ballot = ballot , ad = area_director )
366+ discuss = discuss [0 ] if discuss else None
367+ comment = IESGComment .objects .filter (ballot = ballot , ad = area_director )
368+ comment = comment [0 ] if comment else None
369+ return (pos , discuss , comment )
370+
360371class EditPositionForm (forms .Form ):
361372 position = forms .ChoiceField (choices = BALLOT_CHOICES , widget = forms .RadioSelect )
362373 discuss_text = forms .CharField (required = False , widget = forms .Textarea )
@@ -370,16 +381,7 @@ def edit_position(request, name):
370381
371382 login = IESGLogin .objects .get (login_name = request .user .username )
372383
373- pos = Position .objects .filter (ballot = doc .idinternal .ballot , ad = login )
374- if pos :
375- pos = pos [0 ]
376-
377- discuss = IESGDiscuss .objects .filter (ballot = doc .idinternal .ballot , ad = login )
378- if discuss :
379- discuss = discuss [0 ]
380- comment = IESGComment .objects .filter (ballot = doc .idinternal .ballot , ad = login )
381- if comment :
382- comment = comment [0 ]
384+ pos , discuss , comment = get_ballot_info (doc .idinternal .ballot , login )
383385
384386 if request .method == 'POST' :
385387 form = EditPositionForm (request .POST )
@@ -440,11 +442,12 @@ def edit_position(request, name):
440442 if comment .text :
441443 add_document_comment (request , doc , comment .text , ballot = DocumentComment .BALLOT_COMMENT )
442444
443-
444- #email_owner(request, doc, doc.idinternal.job_owner, login, "A new comment added by %s" % login)
445445 doc .idinternal .event_date = date .today ()
446446 doc .idinternal .save ()
447- return HttpResponseRedirect (doc .idinternal .get_absolute_url ())
447+ if request .POST .get ("send_mail" ):
448+ return HttpResponseRedirect (urlreverse ("doc_send_ballot_comment" , kwargs = dict (name = doc .filename )))
449+ else :
450+ return HttpResponseRedirect (doc .idinternal .get_absolute_url ())
448451 else :
449452 initial = {}
450453 if pos :
@@ -464,3 +467,48 @@ def edit_position(request, name):
464467 discuss = discuss ,
465468 comment = comment ),
466469 context_instance = RequestContext (request ))
470+
471+ @group_required ('Area_Director' ,'Secretariat' )
472+ def send_ballot_comment (request , name ):
473+ doc = get_object_or_404 (InternetDraft , filename = name )
474+ if not doc .idinternal :
475+ raise Http404 ()
476+
477+ login = IESGLogin .objects .get (login_name = request .user .username )
478+ pos , discuss , comment = get_ballot_info (doc .idinternal .ballot , login )
479+
480+ subj = []
481+ d = ""
482+ if pos and pos .discuss == 1 and discuss and discuss .text :
483+ d = discuss .text
484+ subj .append ("DISCUSS" )
485+ c = ""
486+ if comment and comment .text :
487+ c = comment .text
488+ subj .append ("COMMENT" )
489+
490+ subject = "%s: %s" % (" and " .join (subj ), doc .file_tag ())
491+ body = render_to_string ("idrfc/ballot_comment_mail.txt" ,
492+ dict (discuss = d , comment = c ))
493+ frm = u"%s <%s>" % login .person .email ()
494+ to = "iesg@iesg.org"
495+
496+ if request .method == 'POST' :
497+ cc = [x .strip () for x in request .POST .get ("cc" , "" ).split (',' ) if x .strip ()]
498+ if request .POST .get ("cc_state_change" ) and doc .idinternal .state_change_notice_to :
499+ cc .extend (doc .idinternal .state_change_notice_to .split (',' ))
500+
501+ send_mail_text (request , to , frm , subject , body , cc = ", " .join (cc ))
502+
503+ return HttpResponseRedirect (doc .idinternal .get_absolute_url ())
504+
505+ return render_to_response ('idrfc/send_ballot_comment.html' ,
506+ dict (doc = doc ,
507+ subject = subject ,
508+ body = body ,
509+ frm = frm ,
510+ to = to ,
511+ can_send = d or c ),
512+ context_instance = RequestContext (request ))
513+
514+
0 commit comments