class BasketDetail(generics.RetrieveUpdateDestroyAPIView): serializer_class = BasketSerializer permission_classes = (permissions.RequestAllowsAccessTo, ) queryset = editable_baskets() def get_object(self): basket = super(BasketDetail, self).get_object() return assign_basket_strategy(basket, self.request)
def get_queryset(self): basket_pk = self.kwargs.get("basket_pk") basket = generics.get_object_or_404(operations.editable_baskets(), pk=basket_pk) prepped_basket = operations.prepare_basket(basket, self.request) if operations.request_allows_access_to_basket(self.request, prepped_basket): return prepped_basket.all_lines() else: return self.queryset.none()
def get_queryset(self): basket_pk = self.kwargs.get('basket_pk') basket = get_object_or_404(operations.editable_baskets(), pk=basket_pk) prepped_basket = operations.prepare_basket(basket, self.request) if operations.request_allows_access_to_basket(self.request, prepped_basket): return prepped_basket.all_lines() else: return self.queryset.none()
def get_queryset(self): basket_pk = self.kwargs.get('basket_pk') basket = get_object_or_404(operations.editable_baskets(), pk=basket_pk) prepped_basket = operations.prepare_basket(basket, self.request) if operations.request_contains_basket(self.request, prepped_basket): return prepped_basket.all_lines() else: return self.queryset.none()
class BasketList(generics.ListAPIView): """ Retrieve all baskets that belong to the current (authenticated) user. """ serializer_class = BasketSerializer queryset = editable_baskets() def get_queryset(self): qs = super(BasketList, self).get_queryset() if self.request.user.is_authenticated: qs = qs.filter(owner=self.request.user) mapped_with_baskets = list( map(functools.partial(assign_basket_strategy, request=self.request), qs) ) else: # anonymous users have max 1 basket. basket = get_anonymous_basket(self.request) mapped_with_baskets = [prepare_basket(basket, self.request)] return QuerySetList(mapped_with_baskets, qs)
class BasketList(generics.ListCreateAPIView): """ Retrieve all baskets that belong to the current user. While each user can view their own basket, for creating baskets user must be assigned the correct (basket update) permissions. """ serializer_class = BasketSerializer queryset = editable_baskets() permission_classes = (DjangoModelPermissions, ) def get_queryset(self): qs = super(BasketList, self).get_queryset() if self.request.user.is_authenticated: qs = qs.filter(owner=self.request.user) mapped_with_baskets = list( map( functools.partial(assign_basket_strategy, request=self.request), qs)) else: # anonymous users have max 1 basket. basket = get_anonymous_basket(self.request) mapped_with_baskets = [prepare_basket(basket, self.request)] return QuerySetList(mapped_with_baskets, qs)