Esempio n. 1
0
def company_index(request):
	cache_key = get_cache_key(request)
	res = cache.get(cache_key)
	if res is None:
		res = serializers.get_enterprises()
		cache.set(cache_key, res, 60)
	return Response({'companies':res}, template_name = 'accounts/companies.html')
Esempio n. 2
0
 def retrieve(self, request, *args, **kwargs):
     cache_key = get_cache_key(self.request)
     result = cache.get(cache_key)
     self.object_data = None
     if result is not None:
         print 'Cache hits:%s'% cache_key
         self.object_data = result
         return Response(result)    
     self.object = self.get_object()
     fields = request.REQUEST.get('fields','')
     exclude = request.REQUEST.get('exclude', '')
     if exclude:
         exclude = exclude.split(',')
     if fields:
         fields = fields.split(',')
     serializer = self.get_serializer_class()(self.object, fields = fields, exclude = exclude)
     data = serializer.data
     cache.set(cache_key, data,30)
     return Response(data)
Esempio n. 3
0
    def list(self, request, *args, **kwargs):
        cache_key = get_cache_key(self.request)
        result = cache.get(cache_key)
        if result is not None:
            print 'Cache hits:%s'% cache_key
            return Response(result)
    
        self.object_list = self.filter_queryset(self.get_queryset())

        # Default is to allow empty querysets.  This can be altered by setting
        # `.allow_empty = False`, to raise 404 errors on empty querysets.
        if not self.allow_empty and not self.object_list:
            warnings.warn(
                'The `allow_empty` parameter is due to be deprecated. '
                'To use `allow_empty=False` style behavior, You should override '
                '`get_queryset()` and explicitly raise a 404 on empty querysets.',
                PendingDeprecationWarning
            )
            class_name = self.__class__.__name__
            error_msg = self.empty_error % {'class_name': class_name}
            raise Http404(error_msg)

        # Switch between paginated or standard style responses
        fields = request.REQUEST.get('fields')
        if fields:
            fields = fields.split(',')
        exclude = request.REQUEST.get('exclude', '')
        if exclude:
            exclude = exclude.split(',')            
        page = self.paginate_queryset(self.object_list)
        if page is not None:
            serializer = self.get_pagination_serializer(page, fields, exclude = exclude)
        else:
            serializer = self.get_serializer(self.object_list, many=True, fields = fields, exclude = exclude)

        data = serializer.data
        cache.set(cache_key, data,30)
        return Response(data)