Add an API method to get a list of commitfest patch details
authorMagnus Hagander <magnus@hagander.net>
Fri, 1 Jun 2018 21:10:38 +0000 (17:10 -0400)
committerMagnus Hagander <magnus@hagander.net>
Fri, 1 Jun 2018 21:10:38 +0000 (17:10 -0400)
Including ability to filter based on dates.

pgcommitfest/commitfest/api.py
pgcommitfest/urls.py

index ea12043060072b6272d7410f0808781c36cbd561..1c97ef126fd172d13edb45ca7f307ebbaee7f0fa 100644 (file)
@@ -4,6 +4,7 @@ from django.conf import settings
 from django.views.decorators.csrf import csrf_exempt
 from functools import wraps
 from django.utils.decorators import available_attrs
+from django.db import connection
 
 import json
 
@@ -29,3 +30,47 @@ def active_commitfests(request):
        ]
        return HttpResponse(json.dumps(res),
                                                content_type='application/json')
+
+@api_authenticate
+def commitfest(request, cfid):
+       cf = get_object_or_404(CommitFest, pk=cfid)
+
+       whereclauses = []
+       params = { 'cid': cf.id }
+       if 'since' in request.GET:
+               whereclauses.append("latestmessage > %(since)s")
+               params['since'] = request.GET['since']
+
+       if whereclauses:
+               wherestring = 'AND ({0})'.format(
+                       ' AND '.join(whereclauses)
+               )
+       else:
+               wherestring = ''
+
+       curs = connection.cursor()
+       curs.execute("""SELECT p.id, p.name, poc.status,
+ json_agg(json_build_object(
+  'msgid', mt.messageid,
+  'first', mt.firstmessage,
+  'latest', mt.latestmessage,
+  'attachments', attachments
+  )) AS threads
+FROM commitfest_patch p
+INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id=p.id
+LEFT JOIN (
+ SELECT mtp.patch_id, t.messageid, t.firstmessage, t.latestmessage,
+       json_agg(json_build_object('messageid', mta.messageid, 'attachmentid', mta.attachmentid, 'filename', mta.filename, 'time', mta.date)) AS attachments
+   FROM commitfest_mailthread_patches mtp
+   INNER JOIN commitfest_mailthread t ON t.id=mtp.mailthread_id
+   LEFT JOIN commitfest_mailthreadattachment mta ON mta.mailthread_id=t.id
+   GROUP BY mtp.patch_id, t.id
+       ) AS mt ON mt.patch_id=p.id
+WHERE poc.commitfest_id=%(cid)s {0}
+GROUP BY p.id, poc.id""".format(wherestring), params)
+
+       res = {
+               'patches': [dict(zip([col[0] for col in curs.description], row)) for row in curs.fetchall()],
+       }
+       return HttpResponse(json.dumps(res),
+                                               content_type='application/json')
index 248efb6e8a4780d257c6dfaa866a08b00604ab62..105dd5d3b7d4705b55843b2ae666e95c355c7871 100644 (file)
@@ -34,6 +34,7 @@ urlpatterns = [
     url(r'^ajax/(\w+)/$', ajax.main),
     url(r'^thread_notify/$', views.thread_notify),
     url(r'^api/active_commitfests/$', api.active_commitfests),
+    url(r'^api/commitfest/(\d+)/$', api.commitfest),
 
     url(r'^selectable/', include('selectable.urls')),