Make it possible to change the status when commenting on a patch
authorMagnus Hagander <magnus@hagander.net>
Wed, 23 Apr 2014 15:34:52 +0000 (17:34 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 23 Apr 2014 15:34:52 +0000 (17:34 +0200)
pgcommitfest/commitfest/forms.py
pgcommitfest/commitfest/models.py
pgcommitfest/commitfest/views.py

index 8c67d895db2e3ae021265908ce7728f5cf930b8d..a083588d1ae983759ce78ff55b99af50941f7ebe 100644 (file)
@@ -82,12 +82,14 @@ class CommentForm(forms.Form):
        review_doc = reviewfield('Documentation')
 
        message = forms.CharField(required=True, widget=forms.Textarea)
+       newstatus = forms.ChoiceField(choices=PatchOnCommitFest.OPEN_STATUS_CHOICES, label='New status')
 
-       def __init__(self, patch, is_review, *args, **kwargs):
+       def __init__(self, patch, poc, is_review, *args, **kwargs):
                super(CommentForm, self).__init__(*args, **kwargs)
                self.is_review = is_review
 
                self.fields['responseto'].choices = _fetch_thread_choices(patch)
+               self.fields['newstatus'].initial = poc.status
                if not is_review:
                        del self.fields['review_installcheck']
                        del self.fields['review_implements']
index f8ea8628b6fb1ec2581edaa32a4333cda44ffcf3..76c582d048fce8df2225683824af694494468aa8 100644 (file)
@@ -145,6 +145,7 @@ class PatchOnCommitFest(models.Model):
                (STATUS_REJECTED, 'Rejected'),
        )
        OPEN_STATUSES=(STATUS_REVIEW, STATUS_AUTHOR, STATUS_COMMITTER)
+       OPEN_STATUS_CHOICES=[x for x in _STATUS_CHOICES if x[0] in OPEN_STATUSES]
 
        patch = models.ForeignKey(Patch, blank=False, null=False)
        commitfest = models.ForeignKey(CommitFest, blank=False, null=False)
index f502f3864f8b157e3a55c2856b55758591cb1a3c..ff8ff0d0c8d0927e93a539d5c5cca9d271cfc524 100644 (file)
@@ -222,11 +222,16 @@ def _review_status_string(reviewstatus):
 def comment(request, cfid, patchid, what):
        cf = get_object_or_404(CommitFest, pk=cfid)
        patch = get_object_or_404(Patch, pk=patchid)
+       poc = get_object_or_404(PatchOnCommitFest, patch=patch, commitfest=cf)
        is_review = (what=='review')
 
+       if poc.is_closed:
+               messages.add_message(request, messages.INFO, "The status of this patch cannot be changed in this commitfest. You must modify it in the one where it's open!")
+               return HttpResponseRedirect('..')
+
        if request.method == 'POST':
                try:
-                       form = CommentForm(patch, is_review, data=request.POST)
+                       form = CommentForm(patch, poc, is_review, data=request.POST)
                except Exception, e:
                        messages.add_message(request, messages.ERROR, "Failed to build list of response options from the archives: %s" % e)
                        return HttpResponseRedirect('/%s/%s/' % (cf.id, patch.id))
@@ -237,9 +242,17 @@ def comment(request, cfid, patchid, what):
                                        "\n".join(["%-25s %s" % (f.label + ':', _review_status_string(form.cleaned_data[fn])) for (fn, f) in form.fields.items() if fn.startswith('review_')]),
                                        form.cleaned_data['message']
                                )
-                               msg = MIMEText(txt, _charset='utf-8')
                        else:
-                               msg = MIMEText(form.cleaned_data['message'], _charset='utf-8')
+                               txt = form.cleaned_data['message']
+
+                       if int(form.cleaned_data['newstatus']) != poc.status:
+                               poc.status = int(form.cleaned_data['newstatus'])
+                               poc.save()
+                               PatchHistory(patch=poc.patch, by=request.user, what='New status: %s' % poc.statusstring).save()
+                               txt += "\n\nThe new status of this patch is: %s\n" % poc.statusstring
+
+                       msg = MIMEText(txt, _charset='utf-8')
+
                        if form.thread.subject.startswith('Re:'):
                                msg['Subject'] = form.thread.subject
                        else:
@@ -264,7 +277,7 @@ def comment(request, cfid, patchid, what):
                        return HttpResponseRedirect('/%s/%s/' % (cf.id, patch.id))
        else:
                try:
-                       form = CommentForm(patch, is_review)
+                       form = CommentForm(patch, poc, is_review)
                except Exception, e:
                        messages.add_message(request, messages.ERROR, "Failed to build list of response options from the archives: %s" % e)
                        return HttpResponseRedirect('/%s/%s/' % (cf.id, patch.id))