<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models.query import QuerySet
from django.utils.cache import add_never_cache_headers
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response
from shop.models.cart import CartModel, CartItemModel
from shop.rest import serializers


class BaseViewSet(viewsets.ModelViewSet):
    def get_queryset(self):
        try:
            cart = CartModel.objects.get_from_request(self.request)
            if self.kwargs.get(self.lookup_field):
                # we're interest only into a certain cart item
                return CartItemModel.objects.filter(cart=cart)
            # otherwise the CartSerializer will show its detail view and list all its cart items
            return cart
        except CartModel.DoesNotExist:
            return None

    def paginate_queryset(self, queryset):
        if isinstance(queryset, QuerySet):
            return super(BaseViewSet, self).paginate_queryset(queryset)

    def get_serializer(self, *args, **kwargs):
        kwargs.update(context=self.get_serializer_context(), label=self.serializer_label)
        many = kwargs.pop('many', False)
        if many or self.item_serializer_class is None:<commit_msg>return empty queryset for non existing cart<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models.query import QuerySet
from django.utils.cache import add_never_cache_headers
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response
from shop.models.cart import CartModel, CartItemModel
from shop.rest import serializers


class BaseViewSet(viewsets.ModelViewSet):
    def get_queryset(self):
        try:
            cart = CartModel.objects.get_from_request(self.request)
            if self.kwargs.get(self.lookup_field):
                # we're interest only into a certain cart item
                return CartItemModel.objects.filter(cart=cart)
            # otherwise the CartSerializer will show its detail view and list all its cart items
            return cart
        except CartModel.DoesNotExist:
            return CartModel.objects.none()

    def paginate_queryset(self, queryset):
        if isinstance(queryset, QuerySet):
            return super(BaseViewSet, self).paginate_queryset(queryset)

    def get_serializer(self, *args, **kwargs):
        kwargs.update(context=self.get_serializer_context(), label=self.serializer_label)
        many = kwargs.pop('many', False)
        if many or self.item_serializer_class is None:
{'fraction_non_alphanumeric': 0.07169529499626587, 'fraction_numerical': 0.0007468259895444362, 'mean_word_length': 3.3560975609756096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1024893', 'n_tokens_mistral': 718, 'n_tokens_neox': 705, 'n_words': 203}