2012-01-25 02:11:54 +04:00
|
|
|
from djangorestframework.compat import View
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
|
|
|
|
from djangorestframework.mixins import RequestMixin
|
|
|
|
from djangorestframework.views import View as DRFView
|
|
|
|
from djangorestframework import parsers
|
2012-02-07 18:52:15 +04:00
|
|
|
from djangorestframework.response import Response
|
2012-01-25 02:11:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
class RequestExampleView(DRFView):
|
|
|
|
"""
|
|
|
|
A container view for request examples.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get(self, request):
|
2012-02-07 18:52:15 +04:00
|
|
|
return Response([{'name': 'request.DATA Example', 'url': reverse('request-content')},])
|
2012-01-25 02:11:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
class MyBaseViewUsingEnhancedRequest(RequestMixin, View):
|
|
|
|
"""
|
|
|
|
Base view enabling the usage of enhanced requests with user defined views.
|
|
|
|
"""
|
|
|
|
|
2012-02-07 18:22:14 +04:00
|
|
|
parser_classes = parsers.DEFAULT_PARSERS
|
2012-01-25 02:11:54 +04:00
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
2012-02-10 13:05:20 +04:00
|
|
|
self.request = request = self.create_request(request)
|
2012-01-25 02:11:54 +04:00
|
|
|
return super(MyBaseViewUsingEnhancedRequest, self).dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class EchoRequestContentView(MyBaseViewUsingEnhancedRequest):
|
|
|
|
"""
|
|
|
|
A view that just reads the items in `request.DATA` and echoes them back.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
return HttpResponse(("Found %s in request.DATA, content : %s" %
|
|
|
|
(type(request.DATA), request.DATA)))
|
|
|
|
|
|
|
|
def put(self, request, *args, **kwargs):
|
|
|
|
return HttpResponse(("Found %s in request.DATA, content : %s" %
|
|
|
|
(type(request.DATA), request.DATA)))
|
|
|
|
|