django-rest-framework/examples/views.py

33 lines
1006 B
Python
Raw Normal View History

from djangorestframework.views import View
from djangorestframework.response import Response
2012-02-10 13:05:20 +04:00
class ProxyView(View):
"""
A view that just acts as a proxy to call non-djangorestframework views, while still
displaying the browsable API interface.
"""
view_class = None
def dispatch(self, request, *args, **kwargs):
2012-02-10 13:05:20 +04:00
self.request = request = self.create_request(request)
if request.method in ['PUT', 'POST']:
self.response = self.view_class.as_view()(request, *args, **kwargs)
2012-02-10 13:05:20 +04:00
return super(ProxyView, self).dispatch(request, *args, **kwargs)
def get(self, request, *args, **kwargs):
return Response()
def put(self, request, *args, **kwargs):
return Response(self.response.content)
def post(self, request, *args, **kwargs):
return Response(self.response.content)
def get_name(self):
return self.view_class.__name__
def get_description(self, html):
return self.view_class.__doc__