Add API endpoint to return list-of-lists
authorMagnus Hagander <magnus@hagander.net>
Wed, 21 Mar 2018 12:28:36 +0000 (13:28 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 21 Mar 2018 12:28:36 +0000 (13:28 +0100)
django/archives/mailarchives/api.py
django/archives/urls.py

index ffd577c53010a1b6a847d27b5b3504abaf65536e..f213caa09487c88fc5a54cb02484f9e2c952e15a 100644 (file)
@@ -8,6 +8,25 @@ from models import Message, List
 import json
 
 
+@cache(hours=4)
+def listinfo(request):
+       if not settings.PUBLIC_ARCHIVES:
+               return HttpResponseForbidden('No API access on private archives for now')
+
+       if not request.META['REMOTE_ADDR'] in settings.API_CLIENTS:
+               return HttpResponseForbidden('Invalid host')
+
+       resp = HttpResponse(content_type='application/json')
+       json.dump([{
+               'name': l.listname,
+               'shortdesc': l.shortdesc,
+               'description': l.description,
+               'active': l.active,
+               'group': l.group.groupname,
+               } for l in List.objects.select_related('group').all()], resp)
+
+       return resp
+
 @cache(hours=4)
 def latest(request, listname):
        if not settings.PUBLIC_ARCHIVES:
index 9a6d85f23ff3411b1921a193de243bbcfdf3eeb8..6b42f03af59c98334d3d47038e76323d725defdf 100644 (file)
@@ -53,6 +53,7 @@ urlpatterns = [
     # API calls
     url(r'^list/([\w-]+)/latest.json$', archives.mailarchives.api.latest),
     url(r'^message-id.json/(.+)$', archives.mailarchives.api.thread),
+    url(r'^listinfo/$', archives.mailarchives.api.listinfo),
 #    url(r'^thread/(.+)/subscribe/$', archives.mailarchives.api.thread_subscribe),
 
     # Legacy forwarding from old archives site