Skip to content

Commit d5aae59

Browse files
committed
Support for editing discuss and comment text in edit_position view
- Legacy-Id: 2276
1 parent 4127a44 commit d5aae59

4 files changed

Lines changed: 75 additions & 23 deletions

File tree

branch/iesg-tracker/ietf/idrfc/tests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,18 @@ def test_edit_position(self):
265265
self.assertTrue(not Position.objects.filter(ballot=draft.idinternal.ballot, ad__login_name="rhousley"))
266266

267267
r = self.client.post(url, dict(position="discuss",
268-
discuss="This is a discussion test.",
269-
comment="This is a test."))
268+
discuss_text="This is a discussion test.",
269+
comment_text="This is a test."))
270270
self.assertEquals(r.status_code, 302)
271271

272-
pos = Position.objects.filter(ballot=draft.idinternal.ballot, ad__login_name="rhousley")[0]
273-
#self.assertTrue("This is a discussion test." in pos.discuss) FIXME
274-
#self.assertTrue("This is a test." in pos.comment)
272+
pos = Position.objects.get(ballot=draft.idinternal.ballot, ad__login_name="rhousley")
273+
self.assertTrue("This is a discussion test." in IESGDiscuss.objects.get(ballot=draft.idinternal.ballot, ad__login_name="rhousley").text)
274+
self.assertTrue("This is a test." in IESGComment.objects.get(ballot=draft.idinternal.ballot, ad__login_name="rhousley").text)
275275
self.assertTrue(pos.discuss)
276276
self.assertTrue(not (pos.yes or pos.noobj or pos.abstain or pos.recuse))
277277

278-
self.assertEquals(draft.idinternal.comments().count(), comments_before + 1)
279-
self.assertTrue("New position" in draft.idinternal.comments()[0].comment_text)
278+
self.assertEquals(draft.idinternal.comments().count(), comments_before + 3)
279+
self.assertTrue("New position" in draft.idinternal.comments()[2].comment_text)
280280

281281
# recast vote
282282
comments_before = draft.idinternal.comments().count()

branch/iesg-tracker/ietf/idrfc/views_edit.py

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

branch/iesg-tracker/ietf/idtracker/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,11 @@ class Meta:
623623
verbose_name = 'IDTracker Draft'
624624

625625
class DocumentComment(models.Model):
626+
BALLOT_DISCUSS = 1
627+
BALLOT_COMMENT = 2
626628
BALLOT_CHOICES = (
627-
(1, 'discuss'),
628-
(2, 'comment'),
629+
(BALLOT_DISCUSS, 'discuss'),
630+
(BALLOT_COMMENT, 'comment'),
629631
)
630632
document = models.ForeignKey(IDInternal)
631633
# NOTE: This flag is often NULL, which complicates its correct use...
@@ -701,7 +703,7 @@ class IESGComment(models.Model):
701703
ad = models.ForeignKey(IESGLogin)
702704
date = models.DateField(db_column="comment_date")
703705
revision = models.CharField(max_length=2)
704-
active = models.IntegerField()
706+
active = models.IntegerField() # doesn't appear to be used
705707
text = models.TextField(blank=True, db_column="comment_text")
706708
def __str__(self):
707709
return "Comment text by %s on %s" % ( self.ad, self.ballot )

branch/iesg-tracker/ietf/templates/idrfc/edit_position.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
<form class="position-form" action="" method="POST">
1717
<div class="position">{{ form.position }}</div>
1818

19-
<div class="discuss-text">{{ form.discuss_text.label_tag }}:</div>
19+
<div class="discuss-text">{{ form.discuss_text.label_tag }}: {% if discuss %}(last edited {{ discuss.date }}){% endif %}</div>
2020
{{ form.discuss_text }}
2121

22-
<div class="comment-text">{{ form.comment_text.label_tag }}:</div>
22+
<div class="comment-text">{{ form.comment_text.label_tag }}: {% if comment %}(last edited {{ comment.date }}){% endif %}</div>
2323
<div>{{ form.comment_text }}</div>
2424

2525
<div class="actions">

0 commit comments

Comments
 (0)