# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.http import HttpResponse
+from django.utils.decorators import method_decorator
from django.utils.encoding import iri_to_uri
+from django.views.decorators.vary import vary_on_headers
def oauthlib_request(request):
v = iri_to_uri(v)
response[k] = v
return response
+
+
+vary_on_auth = method_decorator(vary_on_headers('Authorization'), 'dispatch')
from .models import BookUserData
from . import serializers
from .request_validator import PistonRequestValidator
-from .utils import oauthlib_request, oauthlib_response
+from .utils import oauthlib_request, oauthlib_response, vary_on_auth
class OAuth1RequestTokenEndpoint(RequestTokenEndpoint):
return urlencode(token.items())
+# Never Cache
class OAuth1RequestTokenView(View):
def __init__(self):
self.endpoint = OAuth1RequestTokenEndpoint(PistonRequestValidator())
return urlencode(token.items())
+# Never cache
class OAuth1AccessTokenView(View):
def __init__(self):
self.endpoint = OAuth1AccessTokenEndpoint(PistonRequestValidator())
)
+@vary_on_auth
class UserView(RetrieveAPIView):
permission_classes = [IsAuthenticated]
serializer_class = serializers.UserSerializer
return self.request.user
+@vary_on_auth
class BookUserDataView(RetrieveAPIView):
permission_classes = [IsAuthenticated]
serializer_class = serializers.BookUserDataSerializer
from rest_framework import status
from paypal.permissions import IsSubscribed
from api.handlers import read_tags
+from api.utils import vary_on_auth
from .helpers import books_after, order_books
from . import serializers
from catalogue.forms import BookImportForm
serializer_class = serializers.CollectionListSerializer
+@vary_on_auth # Because of 'liked'.
class CollectionDetail(RetrieveAPIView):
queryset = Collection.objects.all()
lookup_field = 'slug'
serializer_class = serializers.CollectionSerializer
+@vary_on_auth # Because of 'liked'.
class BookList(ListAPIView):
permission_classes = [DjangoModelPermissionsOrAnonReadOnly]
queryset = Book.objects.none() # Required for DjangoModelPermissions
raise Http404
+@vary_on_auth # Because of 'liked'.
class BookDetail(RetrieveAPIView):
queryset = Book.objects.all()
lookup_field = 'slug'
serializer_class = serializers.EbookSerializer
+@vary_on_auth # Because of 'liked'.
class Preview(ListAPIView):
queryset = Book.objects.filter(preview=True)
serializer_class = serializers.BookPreviewSerializer
+@vary_on_auth # Because of 'liked'.
class FilterBookList(ListAPIView):
serializer_class = serializers.FilterBookListSerializer
)
+@vary_on_auth # Because of 'liked'.
class FragmentList(ListAPIView):
serializer_class = serializers.FragmentSerializer
return Fragment.tagged.with_all(tags).select_related('book')
+@vary_on_auth # Because of 'liked'.
class FragmentView(RetrieveAPIView):
serializer_class = serializers.FragmentDetailSerializer
def render(self, name, value=None, attrs=None):
final_attrs = self.build_attrs(self.attrs, attrs)
+ final_attrs["name"] = name
if value:
final_attrs['value'] = smart_unicode(value)
from rest_framework.response import Response
from rest_framework.views import APIView
from api.models import BookUserData
+from api.utils import vary_on_auth
from catalogue.api.helpers import order_books, books_after
from catalogue.api.serializers import BookSerializer
from catalogue.models import Book
from social.utils import likes
+@vary_on_auth
class LikeView(APIView):
permission_classes = [IsAuthenticated]
return Response({})
+@vary_on_auth
class ShelfView(ListAPIView):
permission_classes = [IsAuthenticated]
serializer_class = BookSerializer