1
Fork 0

Added core functionality

This commit is contained in:
Jake Howard 2015-12-10 14:02:38 +00:00
parent 29a2ba8f4a
commit 44bfa68abf
4 changed files with 15 additions and 5 deletions

View file

@ -0,0 +1,5 @@
from rest_framework import serializers
class ReverserInputSerializer(serializers.Serializer):
ident = serializers.CharField(allow_blank=False)

View file

@ -2,5 +2,5 @@ from django.conf.urls import url
from django_client_reverse.views import Reverser
urlpatterns = [
url(r'^$', Reverser.as_view(), name="reverser")
url(r'^$', Reverser.as_view(), name="root")
]

View file

@ -7,5 +7,5 @@ class ReverserTestCase(APITestCase):
super().setUp()
def test_thing(self):
response = self.client.get(reverse('reverser'))
print(response)
response = self.client.post(reverse('reverser'), data={'ident': 'tests:root'})
self.assertEqual(response.data, '/tests/')

View file

@ -1,10 +1,15 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from django.core.urlresolvers import reverse
from .serializers import ReverserInputSerializer
class Reverser(APIView):
renderer_classes = (JSONRenderer,)
def get(self, request, format=None):
return Response("Response")
def post(self, request, format=None):
input_serializer = ReverserInputSerializer(data=request.data)
input_serializer.is_valid(raise_exception=True)
url = reverse(input_serializer.validated_data['ident'])
return Response(url)