diff --git a/mayan/apps/common/api_views.py b/mayan/apps/common/api_views.py new file mode 100644 index 0000000000..1a1f274996 --- /dev/null +++ b/mayan/apps/common/api_views.py @@ -0,0 +1,16 @@ +from __future__ import unicode_literals + +from django.contrib.contenttypes.models import ContentType + +from rest_framework import generics + +from .serializers import ContentTypeSerializer + + +class APIContentTypeList(generics.ListAPIView): + """ + Returns a list of all the available content types. + """ + + serializer_class = ContentTypeSerializer + queryset = ContentType.objects.order_by('app_label', 'model') diff --git a/mayan/apps/common/apps.py b/mayan/apps/common/apps.py index 457ecc2073..ace2edd1c0 100644 --- a/mayan/apps/common/apps.py +++ b/mayan/apps/common/apps.py @@ -15,6 +15,7 @@ from django.db.models.signals import post_save from django.utils.translation import ugettext_lazy as _ from mayan.celery import app +from rest_api.classes import APIEndPoint from .classes import Package from .handlers import ( @@ -74,6 +75,8 @@ class CommonApp(MayanAppConfig): def ready(self): super(CommonApp, self).ready() + APIEndPoint(app=self, version_string='1') + Package(label='Django', license_text=''' Copyright (c) Django Software Foundation and individual contributors. All rights reserved. diff --git a/mayan/apps/common/serializers.py b/mayan/apps/common/serializers.py new file mode 100644 index 0000000000..ab9520c89e --- /dev/null +++ b/mayan/apps/common/serializers.py @@ -0,0 +1,11 @@ +from __future__ import unicode_literals + +from django.contrib.contenttypes.models import ContentType + +from rest_framework import serializers + + +class ContentTypeSerializer(serializers.ModelSerializer): + class Meta: + fields = ('app_label', 'id', 'model') + model = ContentType diff --git a/mayan/apps/common/tests/test_api.py b/mayan/apps/common/tests/test_api.py new file mode 100644 index 0000000000..4b92bd8342 --- /dev/null +++ b/mayan/apps/common/tests/test_api.py @@ -0,0 +1,11 @@ +from __future__ import unicode_literals + +from django.core.urlresolvers import reverse + +from rest_framework.test import APITestCase + + +class CommonAPITestCase(APITestCase): + def test_content_type_list_view(self): + response = self.client.get(reverse('rest_api:content-type-list')) + self.assertEqual(response.status_code, 200) diff --git a/mayan/apps/common/urls.py b/mayan/apps/common/urls.py index 11b6e1acf8..2db113ce26 100644 --- a/mayan/apps/common/urls.py +++ b/mayan/apps/common/urls.py @@ -5,6 +5,7 @@ from django.contrib.staticfiles.templatetags.staticfiles import static from django.views.generic import RedirectView from django.views.i18n import javascript_catalog +from api_views import APIContentTypeList from .views import ( AboutView, CurrentUserDetailsView, CurrentUserEditView, CurrentUserLocaleProfileDetailsView, CurrentUserLocaleProfileEditView, @@ -66,3 +67,7 @@ urlpatterns += patterns( name='set_language' ), ) + +api_urls = [ + url(r'^content_types/$', APIContentTypeList.as_view(), name='content-type-list'), +]