Added core functionality
This commit is contained in:
parent
29a2ba8f4a
commit
44bfa68abf
4 changed files with 15 additions and 5 deletions
5
django_client_reverse/serializers.py
Normal file
5
django_client_reverse/serializers.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
|
||||||
|
class ReverserInputSerializer(serializers.Serializer):
|
||||||
|
ident = serializers.CharField(allow_blank=False)
|
|
@ -2,5 +2,5 @@ from django.conf.urls import url
|
||||||
from django_client_reverse.views import Reverser
|
from django_client_reverse.views import Reverser
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', Reverser.as_view(), name="reverser")
|
url(r'^$', Reverser.as_view(), name="root")
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,5 +7,5 @@ class ReverserTestCase(APITestCase):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
def test_thing(self):
|
def test_thing(self):
|
||||||
response = self.client.get(reverse('reverser'))
|
response = self.client.post(reverse('reverser'), data={'ident': 'tests:root'})
|
||||||
print(response)
|
self.assertEqual(response.data, '/tests/')
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.renderers import JSONRenderer
|
from rest_framework.renderers import JSONRenderer
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
from .serializers import ReverserInputSerializer
|
||||||
|
|
||||||
|
|
||||||
class Reverser(APIView):
|
class Reverser(APIView):
|
||||||
renderer_classes = (JSONRenderer,)
|
renderer_classes = (JSONRenderer,)
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def post(self, request, format=None):
|
||||||
return Response("Response")
|
input_serializer = ReverserInputSerializer(data=request.data)
|
||||||
|
input_serializer.is_valid(raise_exception=True)
|
||||||
|
url = reverse(input_serializer.validated_data['ident'])
|
||||||
|
return Response(url)
|
||||||
|
|
Reference in a new issue