Add support for claiming and unclaiming as committer
authorMagnus Hagander <magnus@hagander.net>
Tue, 22 Apr 2014 11:59:12 +0000 (13:59 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 22 Apr 2014 11:59:12 +0000 (13:59 +0200)
pgcommitfest/commitfest/models.py
pgcommitfest/commitfest/templates/patch.html
pgcommitfest/commitfest/views.py
pgcommitfest/urls.py

index 75078a0824b68cab12fc2c36a0f8fdee024d2766..f8ea8628b6fb1ec2581edaa32a4333cda44ffcf3 100644 (file)
@@ -15,6 +15,9 @@ class Committer(models.Model):
        def __unicode__(self):
                return unicode(self.user)
 
+       @property
+       def fullname(self):
+               return "%s %s (%s)" % (self.user.first_name, self.user.last_name, self.user.username)
 
 class CommitFest(models.Model):
        STATUS_FUTURE=1
index a0a3b321e57741c90c32c7336d495020bc925dfc..23976eee9bf08c52a0ea9d4b4370fe1b4c1a1cfd 100644 (file)
@@ -43,7 +43,9 @@
     </tr>
     <tr>
       <th>Committer</th>
-      <td>{%if patch.committer%}{{patch.committer.first_name}} {{patch.committer.last_name}} ({{patch.committer.username}}){%endif%}</td>
+      <td>{%if patch.committer%}{{patch.committer.fullname}}{%endif%}
+{%if is_committer%}<a href="committer/{{is_this_committer|yesno:"remove,become"}}/" class="btn pull-right">{{is_this_committer|yesno:"Unclaim as committer,Claim as committer"}}</a>{%endif%}
+      </td>
     </tr>
     <tr>
       <th>Links</th>
index b66e37face9b120876f3e117a7d26eb6c052b732..f502f3864f8b157e3a55c2856b55758591cb1a3c 100644 (file)
@@ -1,5 +1,5 @@
 from django.shortcuts import render_to_response, get_object_or_404
-from django.http import HttpResponseRedirect, Http404
+from django.http import HttpResponseRedirect, Http404, HttpResponseForbidden
 from django.template import RequestContext
 from django.db import transaction
 from django.db.models import Q
@@ -111,11 +111,18 @@ def patch(request, cfid, patchid):
        #XXX: this creates a session, so find a smarter way. Probably handle
        #it in the callback and just ask the user then?
        if request.user.is_authenticated():
-               is_committer = Committer.objects.filter(user=request.user).exists()
+               committer = list(Committer.objects.filter(user=request.user, active=True))
+               if len(committer) > 0:
+                       is_committer=  True
+                       is_this_committer = committer[0] == patch.committer
+               else:
+                       is_committer = is_this_committer = False
+
                is_reviewer = request.user in patch.reviewers.all()
 #              is_reviewer = len([x for x in patch.reviewers.all() if x==request.user]) > 0
        else:
                is_committer = False
+               is_this_committer = False
                is_reviewer = False
 
        return render_to_response('patch.html', {
@@ -123,6 +130,7 @@ def patch(request, cfid, patchid):
                'patch': patch,
                'patch_commitfests': patch_commitfests,
                'is_committer': is_committer,
+               'is_this_committer': is_this_committer,
                'is_reviewer': is_reviewer,
                'title': 'View patch',
                'breadcrumbs': [{'title': cf.name, 'href': '/%s/' % cf.pk},],
@@ -368,3 +376,27 @@ def reviewer(request, cfid, patchid, status):
                patch.set_modified()
                PatchHistory(patch=patch, by=request.user, what='Removed self from reviewers').save()
        return HttpResponseRedirect('../../')
+
+@login_required
+@transaction.commit_on_success
+def committer(request, cfid, patchid, status):
+       get_object_or_404(CommitFest, pk=cfid)
+       patch = get_object_or_404(Patch, pk=patchid)
+
+       committer = list(Committer.objects.filter(user=request.user, active=True))
+       if len(committer) == 0:
+               return HttpResponseForbidden('Only committers can do that!')
+       committer = committer[0]
+
+       is_committer = committer == patch.committer
+
+       if status=='become' and not is_committer:
+               patch.committer = committer
+               patch.set_modified()
+               PatchHistory(patch=patch, by=request.user, what='Added self as committer').save()
+       elif status=='remove' and is_committer:
+               patch.committer = None
+               patch.set_modified()
+               PatchHistory(patch=patch, by=request.user, what='Removed self from committers').save()
+       patch.save()
+       return HttpResponseRedirect('../../')
index 7eb3576523f007ae4ed9be133f1304128004cbc7..488041d7ede3c0bbf663a9b8d00cd9f5da19939c 100644 (file)
@@ -14,6 +14,7 @@ urlpatterns = patterns('',
     url(r'^(\d+)/(\d+)/status/(review|author|committer)/$', 'commitfest.views.status'),
     url(r'^(\d+)/(\d+)/close/(reject|feedback|committed)/$', 'commitfest.views.close'),
     url(r'^(\d+)/(\d+)/reviewer/(become|remove)/$', 'commitfest.views.reviewer'),
+    url(r'^(\d+)/(\d+)/committer/(become|remove)/$', 'commitfest.views.committer'),
     url(r'^(\d+)/(\d+)/(comment|review)/', 'commitfest.views.comment'),
     url(r'^ajax/(\w+)/$', 'commitfest.ajax.main'),