Skip to content

Commit 97103b2

Browse files
committed
Adding BasketAdminList to urls.py
Creating admin basket view and serializer correction list comma added restore final update optimizing test
1 parent a12c7c7 commit 97103b2

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

oscarapi/serializers/admin/basket.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from rest_framework import serializers
2+
3+
from oscar.core.loading import get_model
4+
5+
from oscarapi.utils.loading import get_api_classes, get_api_class
6+
7+
8+
Basket = get_model("basket", "Basket")
9+
(
10+
BasketSerializer,
11+
) = get_api_classes(
12+
"serializers.basket",
13+
["BasketSerializer",]
14+
)
15+
16+
17+
class AdminBasketSerializer(BasketSerializer):
18+
url = serializers.HyperlinkedIdentityField(
19+
view_name="admin-basket-detail")

oscarapi/urls.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
)
3030

3131
(StockRecordDetail, PartnerList, PartnerDetail) = get_api_classes(
32-
"views.admin.partner", ["StockRecordDetail", "PartnerList", "PartnerDetail"]
32+
"views.admin.partner", ["StockRecordDetail",
33+
"PartnerList", "PartnerDetail"]
3334
)
3435

3536
(
@@ -149,6 +150,18 @@
149150
],
150151
)
151152

153+
(
154+
BasketAdminList,
155+
BasketAdminDetail,
156+
157+
) = get_api_classes(
158+
"views.admin.basket",
159+
[
160+
"BasketAdminList",
161+
"BasketAdminDetail",
162+
],
163+
)
164+
152165
(UserAdminList, UserAdminDetail) = get_api_classes(
153166
"views.admin.user", ["UserAdminList", "UserAdminDetail"]
154167
)
@@ -219,7 +232,8 @@
219232
path("orders/", OrderList.as_view(), name="order-list"),
220233
path("orders/<int:pk>/", OrderDetail.as_view(), name="order-detail"),
221234
path("orders/<int:pk>/lines/", OrderLineList.as_view(), name="order-lines-list"),
222-
path("orderlines/<int:pk>/", OrderLineDetail.as_view(), name="order-lines-detail"),
235+
path("orderlines/<int:pk>/", OrderLineDetail.as_view(),
236+
name="order-lines-detail"),
223237
path(
224238
"orderlineattributes/<int:pk>/",
225239
OrderLineAttributeDetail.as_view(),
@@ -238,6 +252,13 @@
238252
]
239253

240254
admin_urlpatterns = [
255+
path("baskets/", BasketAdminList.as_view(), name="admin-basket-list"),
256+
path(
257+
"baskets/<int:pk>/",
258+
BasketAdminDetail.as_view(),
259+
name="admin-basket-detail",
260+
),
261+
241262
path("products/", ProductAdminList.as_view(), name="admin-product-list"),
242263
path(
243264
"products/<int:pk>/",

oscarapi/views/admin/basket.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# pylint: disable=W0632
2+
import functools
3+
4+
from rest_framework import generics
5+
6+
from oscar.core.loading import get_model
7+
from oscarapi.basket.operations import (
8+
assign_basket_strategy,
9+
editable_baskets,
10+
get_anonymous_basket,
11+
prepare_basket,
12+
)
13+
14+
from oscarapi.utils.loading import get_api_class
15+
from oscarapi.views.utils import QuerySetList
16+
17+
APIAdminPermission = get_api_class("permissions", "APIAdminPermission")
18+
AdminBasketSerializer = get_api_class(
19+
"serializers.admin.basket", "AdminBasketSerializer")
20+
Basket = get_model("basket", "Basket")
21+
22+
23+
class BasketAdminList(generics.ListCreateAPIView):
24+
"""
25+
List of all baskets for admin users
26+
"""
27+
serializer_class = AdminBasketSerializer
28+
permission_classes = (APIAdminPermission,)
29+
30+
queryset = editable_baskets()
31+
32+
def get_queryset(self):
33+
qs = super(BasketAdminList, self).get_queryset()
34+
mapped_with_baskets = list(
35+
map(functools.partial(assign_basket_strategy, request=self.request), qs)
36+
)
37+
return QuerySetList(mapped_with_baskets, qs)
38+
39+
40+
class BasketAdminDetail(generics.RetrieveUpdateDestroyAPIView):
41+
42+
queryset = Basket.objects.all()
43+
serializer_class = AdminBasketSerializer
44+
permission_classes = (APIAdminPermission,)

oscarapi/views/root.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def PUBLIC_APIS(r, f):
3434

3535
def ADMIN_APIS(r, f):
3636
return [
37+
("baskets", reverse("admin-basket-list", request=r, format=f)),
3738
("productclasses", reverse("admin-productclass-list", request=r, format=f)),
3839
("products", reverse("admin-product-list", request=r, format=f)),
3940
("categories", reverse("admin-category-list", request=r, format=f)),

0 commit comments

Comments
 (0)