1010from django .template import RequestContext
1111from django import forms
1212from django .utils .html import strip_tags
13+ from django .utils import simplejson
1314from django .conf import settings
1415
1516from ietf .utils .mail import send_mail_text , send_mail_preformatted
16- from ietf .ietfauth .decorators import group_required
17+ from ietf .ietfauth .decorators import group_required , role_required
1718from ietf .idtracker .templatetags .ietf_filters import in_group
1819from ietf .ietfauth .decorators import has_role
1920from ietf .idtracker .models import *
2728
2829from ietf .doc .models import *
2930from ietf .name .models import BallotPositionName
31+ from ietf .person .models import Person
3032
3133
3234BALLOT_CHOICES = (("yes" , "Yes" ),
@@ -215,27 +217,30 @@ class EditPositionFormREDESIGN(forms.Form):
215217 comment = forms .CharField (required = False , widget = forms .Textarea )
216218 return_to_url = forms .CharField (required = False , widget = forms .HiddenInput )
217219
220+ def __init__ (self , * args , ** kwargs ):
221+ ballot_type = kwargs .pop ("ballot_type" )
222+ super (EditPositionForm , self ).__init__ (* args , ** kwargs )
223+ self .fields ['position' ].queryset = ballot_type .positions .order_by ('order' )
224+
218225 def clean_discuss (self ):
219226 entered_discuss = self .cleaned_data ["discuss" ]
220227 entered_pos = self .cleaned_data ["position" ]
221228 if entered_pos .slug == "discuss" and not entered_discuss :
222229 raise forms .ValidationError ("You must enter a non-empty discuss" )
223230 return entered_discuss
224231
225- @group_required ( 'Area_Director ' ,'Secretariat' )
226- def edit_positionREDESIGN (request , name ):
227- """Vote and edit discuss and comment on Internet Draft as Area Director."""
232+ @role_required ( 'Area Director ' ,'Secretariat' )
233+ def edit_positionREDESIGN (request , name , ballot_id ):
234+ """Vote and edit discuss and comment on document as Area Director."""
228235 doc = get_object_or_404 (Document , docalias__name = name )
229- started_process = doc .latest_event (type = "started_iesg_process" )
230- if not doc .get_state ("draft-iesg" ) or not started_process :
231- raise Http404 ()
236+ ballot = get_object_or_404 (BallotDocEvent , type = "created_ballot" , pk = ballot_id , doc = doc )
232237
233238 ad = login = request .user .get_profile ()
234239
235240 if 'HTTP_REFERER' in request .META :
236241 return_to_url = request .META ['HTTP_REFERER' ]
237242 else :
238- return_to_url = doc .get_absolute_url ( )
243+ return_to_url = urlreverse ( "doc_ballot" , kwargs = dict ( name = doc .name , ballot = ballot_id ) )
239244
240245 # if we're in the Secretariat, we can select an AD to act as stand-in for
241246 if not has_role (request .user , "Area Director" ):
@@ -245,12 +250,11 @@ def edit_positionREDESIGN(request, name):
245250 from ietf .person .models import Person
246251 ad = get_object_or_404 (Person , pk = ad_id )
247252
248- old_pos = doc .latest_event (BallotPositionDocEvent , type = "changed_ballot_position" , ad = ad , time__gte = started_process . time )
253+ old_pos = doc .latest_event (BallotPositionDocEvent , type = "changed_ballot_position" , ad = ad , ballot = ballot )
249254
250255 if request .method == 'POST' :
251- form = EditPositionForm (request .POST )
256+ form = EditPositionForm (request .POST , ballot_type = ballot . ballot_type )
252257 if form .is_valid ():
253-
254258 # save the vote
255259 clean = form .cleaned_data
256260
@@ -259,6 +263,7 @@ def edit_positionREDESIGN(request, name):
259263
260264 pos = BallotPositionDocEvent (doc = doc , by = login )
261265 pos .type = "changed_ballot_position"
266+ pos .ballot = ballot
262267 pos .ad = ad
263268 pos .pos = clean ["position" ]
264269 pos .comment = clean ["comment" ].strip ()
@@ -269,7 +274,7 @@ def edit_positionREDESIGN(request, name):
269274 changes = []
270275 added_events = []
271276 # possibly add discuss/comment comments to history trail
272- # so it's easy to see
277+ # so it's easy to see what's happened
273278 old_comment = old_pos .comment if old_pos else ""
274279 if pos .comment != old_comment :
275280 pos .comment_time = pos .time
@@ -291,7 +296,8 @@ def edit_positionREDESIGN(request, name):
291296 e = DocEvent (doc = doc , by = login )
292297 e .by = ad # otherwise we can't see who's saying it
293298 e .type = "added_comment"
294- e .desc = "[Ballot discuss]\n " + pos .discuss
299+ e .desc = "[Ballot %s]\n " % pos .pos .name .lower ()
300+ e .desc += pos .discuss
295301 added_events .append (e )
296302
297303 # figure out a description
@@ -311,13 +317,13 @@ def edit_positionREDESIGN(request, name):
311317 pos .save ()
312318
313319 for e in added_events :
314- e .save () # save them after the position is saved to get later id
320+ e .save () # save them after the position is saved to get later id for sorting order
315321
316322 if request .POST .get ("send_mail" ):
317323 qstr = "?return_to_url=%s" % return_to_url
318324 if request .GET .get ('ad' ):
319325 qstr += "&ad=%s" % request .GET .get ('ad' )
320- return HttpResponseRedirect (urlreverse ("doc_send_ballot_comment" , kwargs = dict (name = doc .name )) + qstr )
326+ return HttpResponseRedirect (urlreverse ("doc_send_ballot_comment" , kwargs = dict (name = doc .name , ballot_id = ballot_id )) + qstr )
321327 elif request .POST .get ("Defer" ):
322328 return HttpResponseRedirect (urlreverse ("doc_defer_ballot" , kwargs = dict (name = doc )))
323329 elif request .POST .get ("Undefer" ):
@@ -334,10 +340,12 @@ def edit_positionREDESIGN(request, name):
334340 if return_to_url :
335341 initial ['return_to_url' ] = return_to_url
336342
337- form = EditPositionForm (initial = initial )
343+ form = EditPositionForm (initial = initial , ballot_type = ballot .ballot_type )
344+
345+ blocking_positions = dict ((p .pk , p .name ) for p in form .fields ["position" ].queryset .all () if p .blocking )
338346
339347 ballot_deferred = None
340- if doc .get_state_slug ("draft -iesg" ) == "defer" :
348+ if doc .get_state_slug ("%s -iesg" % doc . type_id ) == "defer" :
341349 ballot_deferred = doc .latest_event (type = "changed_document" , desc__startswith = "State changed to <b>IESG Evaluation - Defer</b>" )
342350
343351 return render_to_response ('idrfc/edit_positionREDESIGN.html' ,
@@ -347,6 +355,8 @@ def edit_positionREDESIGN(request, name):
347355 return_to_url = return_to_url ,
348356 old_pos = old_pos ,
349357 ballot_deferred = ballot_deferred ,
358+ show_discuss_text = old_pos and old_pos .pos .blocking ,
359+ blocking_positions = simplejson .dumps (blocking_positions ),
350360 ),
351361 context_instance = RequestContext (request ))
352362
@@ -427,42 +437,39 @@ def send_ballot_comment(request, name):
427437 ),
428438 context_instance = RequestContext (request ))
429439
430- @group_required ( 'Area_Director ' ,'Secretariat' )
431- def send_ballot_commentREDESIGN (request , name ):
432- """Email Internet Draft ballot discuss/comment for area director ."""
440+ @role_required ( 'Area Director ' ,'Secretariat' )
441+ def send_ballot_commentREDESIGN (request , name , ballot_id ):
442+ """Email document ballot position discuss/comment for Area Director ."""
433443 doc = get_object_or_404 (Document , docalias__name = name )
434- started_process = doc .latest_event (type = "started_iesg_process" )
435- if not started_process :
436- raise Http404 ()
444+ ballot = get_object_or_404 (BallotDocEvent , type = "created_ballot" , pk = ballot_id , doc = doc )
437445
438446 ad = login = request .user .get_profile ()
439447
440448 return_to_url = request .GET .get ('return_to_url' )
441449 if not return_to_url :
442- return_to_url = doc .get_absolute_url ( )
450+ return_to_url = urlreverse ( "doc_ballot" , kwargs = dict ( name = doc .name , ballot = ballot_id ) )
443451
444452 if 'HTTP_REFERER' in request .META :
445453 back_url = request .META ['HTTP_REFERER' ]
446454 else :
447- back_url = doc .get_absolute_url ( )
455+ back_url = urlreverse ( "doc_ballot" , kwargs = dict ( name = doc .name , ballot = ballot_id ) )
448456
449457 # if we're in the Secretariat, we can select an AD to act as stand-in for
450458 if not has_role (request .user , "Area Director" ):
451459 ad_id = request .GET .get ('ad' )
452460 if not ad_id :
453461 raise Http404 ()
454- from ietf .person .models import Person
455462 ad = get_object_or_404 (Person , pk = ad_id )
456463
457- pos = doc .latest_event (BallotPositionDocEvent , type = "changed_ballot_position" , ad = ad , time__gte = started_process . time )
464+ pos = doc .latest_event (BallotPositionDocEvent , type = "changed_ballot_position" , ad = ad , ballot = ballot )
458465 if not pos :
459466 raise Http404 ()
460467
461468 subj = []
462469 d = ""
463- if pos .pos == "discuss" and pos .discuss :
470+ if pos .pos . blocking and pos .discuss :
464471 d = pos .discuss
465- subj .append ("DISCUSS" )
472+ subj .append (pos . pos . name . upper () )
466473 c = ""
467474 if pos .comment :
468475 c = pos .comment
0 commit comments