"""
Re-usable view components
"""
import functools
import json 

from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.core.serializers.json import DjangoJSONEncoder

class LoginRequiredMixin(object):
    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)

def _get_request_data(request):
    data = request.read()
    return json.loads(data)

def _build_json_response(data, status_code=200):
    response = HttpResponse()
    response['Content-Type'] = 'application/json'
    response.content = json.dumps(data, cls=DjangoJSONEncoder)
    # response.content = '<html><body>'+json.dumps(data, cls=DjangoJSONEncoder)+'</body></html>'
    response.status_code = status_code
    return response
    
def with_no_caching(view):

    @functools.wraps(view)
    def no_cache(*args, **kw):
        response = view(*args, **kw)
        response['Cache-Control'] = 'no-cache'
        response['Pragma'] = 'no-cache'
        response['Expires'] = '-1'
        return response

    return no_cache

@@ -264,16 +264,60 @@
 NEncoder
+%0Afrom rest_framework import mixins, viewsets
 %0A%0Aclass 
@@ -1227,8 +1227,172 @@
 o_cache%0A
+%0Aclass ModelViewSet(%0A        mixins.CreateModelMixin,%0A        mixins.RetrieveModelMixin,%0A        mixins.ListModelMixin,%0A        viewsets.GenericViewSet):%0A    pass%0A%0A

Add Base model API viewset