-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding api/admin/baskets endpoint (#363)
* Adding BasketAdminList to urls.py Creating admin basket view and serializer correction list comma added restore final update optimizing test * Adding CustomPageNumberPagination for baskets admin endpoint * Adding BasketAdminTest * PR #363 change request to include pagination * perf test test_assign_basket_strategy_call_frequency * perf test test_assign_basket_strategy_call_frequency and fix black linting * Refactoring for linter * Fixing test issue and add overriden decorator * Linter refactoring
- Loading branch information
Showing
7 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from rest_framework import serializers | ||
|
||
from oscar.core.loading import get_model | ||
|
||
from oscarapi.utils.loading import get_api_class | ||
|
||
|
||
Basket = get_model("basket", "Basket") | ||
BasketSerializer = get_api_class("serializers.basket", "BasketSerializer") | ||
|
||
|
||
class AdminBasketSerializer(BasketSerializer): | ||
url = serializers.HyperlinkedIdentityField(view_name="admin-basket-detail") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# pylint: disable=W0632 | ||
import functools | ||
|
||
from rest_framework import generics | ||
|
||
from oscar.core.loading import get_model | ||
from oscarapi.basket.operations import ( | ||
assign_basket_strategy, | ||
editable_baskets, | ||
) | ||
|
||
from oscarapi.utils.loading import get_api_class | ||
from oscarapi.views.utils import QuerySetList, CustomPageNumberPagination | ||
|
||
APIAdminPermission = get_api_class("permissions", "APIAdminPermission") | ||
AdminBasketSerializer = get_api_class( | ||
"serializers.admin.basket", "AdminBasketSerializer" | ||
) | ||
Basket = get_model("basket", "Basket") | ||
|
||
|
||
class BasketAdminList(generics.ListCreateAPIView): | ||
""" | ||
List of all baskets for admin users | ||
""" | ||
|
||
serializer_class = AdminBasketSerializer | ||
pagination_class = CustomPageNumberPagination | ||
permission_classes = (APIAdminPermission,) | ||
|
||
queryset = editable_baskets() | ||
|
||
def get_queryset(self): | ||
qs = super(BasketAdminList, self).get_queryset() | ||
qs = qs.order_by("-id") | ||
return qs | ||
|
||
def list(self, request, *args, **kwargs): | ||
qs = self.filter_queryset(self.get_queryset()) | ||
page = self.paginate_queryset(qs) | ||
|
||
if page is not None: | ||
mapped_with_baskets = list( | ||
map( | ||
functools.partial(assign_basket_strategy, request=self.request), | ||
page, | ||
) | ||
) | ||
serializer = self.get_serializer(mapped_with_baskets, many=True) | ||
return self.get_paginated_response(serializer.data) | ||
|
||
serializer = self.get_serializer(qs, many=True) | ||
return QuerySetList(mapped_with_baskets, qs) | ||
|
||
|
||
class BasketAdminDetail(generics.RetrieveUpdateDestroyAPIView): | ||
|
||
queryset = Basket.objects.all() | ||
serializer_class = AdminBasketSerializer | ||
permission_classes = (APIAdminPermission,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters