diff --git a/src/purchase/templates/purchase/basket_confirm_delete.html b/src/purchase/templates/purchase/basket_confirm_delete.html new file mode 100644 index 0000000..e7bcc07 --- /dev/null +++ b/src/purchase/templates/purchase/basket_confirm_delete.html @@ -0,0 +1,10 @@ +{% extends "common/base.html" %} +{% block content %} +

{{ object }}

+
+ {% csrf_token %} +

Are you sure you want to delete "{{ object }}"?

+ {{ form }} + +
+{% endblock %} diff --git a/src/purchase/templates/purchase/basket_list.html b/src/purchase/templates/purchase/basket_list.html new file mode 100644 index 0000000..60458d2 --- /dev/null +++ b/src/purchase/templates/purchase/basket_list.html @@ -0,0 +1,22 @@ +{% extends "common/base.html" %} +{% block content %} +

Baskets

+
+ {% for basket in baskets %} +
+
+
+
Basket #{{ basket.id }}
+

+ {{ basket.items.count }} items
+ {{ basket.price_display }}
+ {{ basket.payment_method }} +

+ Edit + Delete +
+
+
+ {% endfor %} +
+{% endblock %} diff --git a/src/purchase/urls.py b/src/purchase/urls.py index 83921e8..622298e 100644 --- a/src/purchase/urls.py +++ b/src/purchase/urls.py @@ -1,9 +1,16 @@ from django.urls import path -from purchase.views import NewBasketView, UpdateBasketView +from purchase.views import ( + DeleteBasketView, + ListBasketsView, + NewBasketView, + UpdateBasketView, +) app_name = "purchase" urlpatterns = [ + path("", ListBasketsView.as_view(), name="list"), path("new/", NewBasketView.as_view(), name="new"), - path("update//", UpdateBasketView.as_view(), name="update"), + path("/update/", UpdateBasketView.as_view(), name="update"), + path("/delete/", DeleteBasketView.as_view(), name="delete"), ] diff --git a/src/purchase/views.py b/src/purchase/views.py index 3b579a5..d54745f 100644 --- a/src/purchase/views.py +++ b/src/purchase/views.py @@ -1,6 +1,6 @@ from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin from django.urls import reverse -from django.views.generic import CreateView, UpdateView +from django.views.generic import CreateView, DeleteView, ListView, UpdateView from purchase.forms import BasketForm from purchase.models import Basket @@ -20,3 +20,18 @@ class UpdateBasketView(ProtectedViewsMixin, UpdateView): permission_required = ["purchase.change_basket", "purchase.view_basket"] model = Basket form_class = BasketForm + + +class ListBasketsView(ProtectedViewsMixin, ListView): + permission_required = ["purchase.view_basket"] + model = Basket + context_object_name = "baskets" + ordering = "-id" + + +class DeleteBasketView(ProtectedViewsMixin, DeleteView): + permission_required = ["purchase.delete_basket"] + model = Basket + + def get_success_url(self): + return reverse("purchase:list")