From a0a04dd66690bd43e03b07f80b82f7201615ae81 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Wed, 19 Jun 2013 18:28:22 +0200 Subject: Add the tags to the REST API --- hyperkitty/api.py | 17 +++++++++++++++++ hyperkitty/templates/api.html | 17 ++++++++++++++--- hyperkitty/urls.py | 4 +++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/hyperkitty/api.py b/hyperkitty/api.py index 8b00e60..9481340 100644 --- a/hyperkitty/api.py +++ b/hyperkitty/api.py @@ -22,6 +22,7 @@ from rest_framework.response import Response from rest_framework import serializers from rest_framework.exceptions import ParseError +from hyperkitty.models import Tag from hyperkitty.lib import get_store @@ -56,6 +57,11 @@ class ThreadSerializer(serializers.Serializer): email_ids = serializers.CharField() participants = serializers.CharField() +class TagSerializer(serializers.ModelSerializer): + class Meta: + model = Tag + fields = ("list_address", "threadid", "tag") + class ListResource(APIView): """ Resource used to retrieve lists from the archives using the @@ -122,3 +128,14 @@ class SearchResource(APIView): return Response(status=404) else: return Response(EmailSerializer(threads, many=True).data) + + +class TagResource(APIView): + """ + Resource used to retrieve tags from the database using the REST API. + """ + + def get(self, request): + tags = Tag.objects.all() + serializer = TagSerializer(tags, many=True) + return Response(serializer.data) diff --git a/hyperkitty/templates/api.html b/hyperkitty/templates/api.html index 750c69b..7537381 100644 --- a/hyperkitty/templates/api.html +++ b/hyperkitty/templates/api.html @@ -38,7 +38,7 @@ retrieve the information known about all the mailing-lists.

-
+

Emails /api/email/<list name>/<Message-ID>

Using the address /api/email/<list name>/<Message-ID> you will be able to @@ -49,7 +49,7 @@ retrieve the information known about a specific email on the specified mailing-l

-
+

Threads /api/thread/<list name>/<ThreadID>

Using the address /api/thread/<list name>/<Message-ID> you will be able to @@ -60,7 +60,7 @@ retrieve the all the email for a specific thread on the specified mailing-list.

-
+

Search /api/search/<list name>/<field>/<keyword>

Using the address /api/search/<list name>/<field>/<keyword> you will be able to @@ -78,4 +78,15 @@ search for all emails of the specified mailing-list containing the provided keyw

+
+

Tags /api/tag/

+

+Using the address /api/tag/ you will be able to +retrieve the list of tags. +

+

For example: + {% url 'api_tag' %} + +

+
{% endblock %} diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py index 9277922..015737b 100644 --- a/hyperkitty/urls.py +++ b/hyperkitty/urls.py @@ -22,7 +22,8 @@ from django.conf.urls import patterns, include, url from django.views.generic.base import TemplateView -from api import ListResource, EmailResource, ThreadResource, SearchResource +from hyperkitty.api import ListResource, EmailResource, ThreadResource, SearchResource +from hyperkitty.api import TagResource from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib.auth.views import logout as logout_view @@ -101,6 +102,7 @@ urlpatterns = patterns('hyperkitty.views', ThreadResource.as_view(), name="api_thread"), url(r'^api/search\/(?P[^/@]+@[^/@]+)\/(?P.*)\/(?P.*)/', SearchResource.as_view(), name="api_search"), + url(r'^api/tag\/', TagResource.as_view(), name="api_tag"), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), -- cgit