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
]
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')
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')),