diff options
author | Magnus Hagander | 2018-06-01 21:10:38 +0000 |
---|---|---|
committer | Magnus Hagander | 2018-06-01 21:10:38 +0000 |
commit | c3efa9432615e4ef17d7bf01b310ea09aa9d8f99 (patch) | |
tree | f76076518085defc47128f3c421d6ebabbe67b12 | |
parent | 1efc44dd93094ae556f340fbffe92a150c4a7439 (diff) |
Add an API method to get a list of commitfest patch details
Including ability to filter based on dates.
-rw-r--r-- | pgcommitfest/commitfest/api.py | 45 | ||||
-rw-r--r-- | pgcommitfest/urls.py | 1 |
2 files changed, 46 insertions, 0 deletions
diff --git a/pgcommitfest/commitfest/api.py b/pgcommitfest/commitfest/api.py index ea12043..1c97ef1 100644 --- a/pgcommitfest/commitfest/api.py +++ b/pgcommitfest/commitfest/api.py @@ -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') diff --git a/pgcommitfest/urls.py b/pgcommitfest/urls.py index 248efb6..105dd5d 100644 --- a/pgcommitfest/urls.py +++ b/pgcommitfest/urls.py @@ -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')), |