Add content type list API view to the common app.
This commit is contained in:
16
mayan/apps/common/api_views.py
Normal file
16
mayan/apps/common/api_views.py
Normal file
@@ -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')
|
||||
@@ -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.
|
||||
|
||||
11
mayan/apps/common/serializers.py
Normal file
11
mayan/apps/common/serializers.py
Normal file
@@ -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
|
||||
11
mayan/apps/common/tests/test_api.py
Normal file
11
mayan/apps/common/tests/test_api.py
Normal file
@@ -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)
|
||||
@@ -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'),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user