@@ -19,7 +19,7 @@ class ChangeStateForm(forms.Form):
1919 state = forms .ModelChoiceField (IDState .objects .all (), empty_label = None , required = True )
2020 substate = forms .ModelChoiceField (IDSubState .objects .all (), required = False )
2121
22- def add_document_comment (request , doc , text , include_by = True ):
22+ def add_document_comment (request , doc , text , include_by = True , ballot = None ):
2323 login = IESGLogin .objects .get (login_name = request .user .username )
2424 if include_by :
2525 text += " by %s" % login
@@ -30,6 +30,8 @@ def add_document_comment(request, doc, text, include_by=True):
3030 c .version = doc .revision_display ()
3131 c .comment_text = text
3232 c .created_by = login
33+ if ballot :
34+ c .ballot = ballot
3335 c .rfc_flag = doc .idinternal .rfc_flag
3436 c .save ()
3537
@@ -368,16 +370,28 @@ def edit_position(request, name):
368370
369371 login = IESGLogin .objects .get (login_name = request .user .username )
370372
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 ]
383+
371384 if request .method == 'POST' :
372385 form = EditPositionForm (request .POST )
373386 if form .is_valid ():
374- vote = form .cleaned_data ['position' ]
375- try :
376- pos = Position .objects .get (ballot = doc .idinternal .ballot , ad = login )
387+ # save the vote
388+ clean = form .cleaned_data
389+ vote = clean ['position' ]
390+ if pos :
377391 # mark discuss as cleared (quirk from old system)
378392 if pos .discuss :
379393 pos .discuss = - 1
380- except Position . DoesNotExist :
394+ else :
381395 pos = Position (ballot = doc .idinternal .ballot , ad = login )
382396 pos .discuss = 0
383397
@@ -389,28 +403,64 @@ def edit_position(request, name):
389403
390404 if pos .id :
391405 pos .save ()
392- add_document_comment (request , doc , "[Ballot Position Update] Position for %s has been changed to %s from %s" % (pos .ad , position_label (vote ), position_label (old_vote )))
406+ if vote != old_vote :
407+ add_document_comment (request , doc , "[Ballot Position Update] Position for %s has been changed to %s from %s" % (pos .ad , position_label (vote ), position_label (old_vote )))
393408 elif vote :
394409 pos .save ()
395410 add_document_comment (request , doc , "[Ballot Position Update] New position, %s, has been recorded" % position_label (vote ))
396411
397- IESGDiscuss .objects .filter (ballot = doc .idinternal .ballot , ad = pos .ad ).update (active = False )
412+ # save discuss
413+ if (discuss and clean ['discuss_text' ] != discuss .text ) or (clean ['discuss_text' ] and not discuss ):
414+ if not discuss :
415+ discuss = IESGDiscuss (ballot = doc .idinternal .ballot , ad = login )
416+
417+ discuss .text = clean ['discuss_text' ]
418+ discuss .date = date .today ()
419+ discuss .revision = doc .revision_display ()
420+ discuss .active = True
421+ discuss .save ()
422+
423+ if discuss .text :
424+ add_document_comment (request , doc , discuss .text , ballot = DocumentComment .BALLOT_DISCUSS )
425+
426+ if pos .discuss < 1 :
427+ IESGDiscuss .objects .filter (ballot = doc .idinternal .ballot , ad = pos .ad ).update (active = False )
428+
429+ # similar for comment
430+ if (comment and clean ['comment_text' ] != comment .text ) or (clean ['comment_text' ] and not comment ):
431+ if not comment :
432+ comment = IESGComment (ballot = doc .idinternal .ballot , ad = login )
398433
399- # FIXME: discuss and comments
434+ comment .text = clean ['comment_text' ]
435+ comment .date = date .today ()
436+ comment .revision = doc .revision_display ()
437+ comment .active = True
438+ comment .save ()
439+
440+ if comment .text :
441+ add_document_comment (request , doc , comment .text , ballot = DocumentComment .BALLOT_COMMENT )
442+
400443
401444 #email_owner(request, doc, doc.idinternal.job_owner, login, "A new comment added by %s" % login)
402445 doc .idinternal .event_date = date .today ()
403446 doc .idinternal .save ()
404447 return HttpResponseRedirect (doc .idinternal .get_absolute_url ())
405448 else :
406449 initial = {}
407- pos = Position .objects .filter (ballot = doc .idinternal .ballot , ad = login )
408450 if pos :
409- initial ['position' ] = position_to_ballot_choice (pos [0 ])
451+ initial ['position' ] = position_to_ballot_choice (pos )
452+
453+ if discuss :
454+ initial ['discuss_text' ] = discuss .text
455+
456+ if comment :
457+ initial ['comment_text' ] = comment .text
410458
411459 form = EditPositionForm (initial = initial )
412460
413461 return render_to_response ('idrfc/edit_position.html' ,
414462 dict (doc = doc ,
415- form = form ),
463+ form = form ,
464+ discuss = discuss ,
465+ comment = comment ),
416466 context_instance = RequestContext (request ))
0 commit comments