From 9f0969ec9aadb735493a41d825b390ac1fe6b3f5 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 2 Apr 2023 18:19:56 +0200 Subject: [PATCH] Use render instead of template response --- src/purchase/views/basket.py | 7 +++---- src/purchase/views/reports.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/purchase/views/basket.py b/src/purchase/views/basket.py index e8b3c80..3745bd8 100644 --- a/src/purchase/views/basket.py +++ b/src/purchase/views/basket.py @@ -5,7 +5,6 @@ from django.contrib.auth.decorators import permission_required from django.core.handlers.wsgi import WSGIRequest from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect, render -from django.template.response import TemplateResponse from django.urls import reverse from django.utils.datastructures import MultiValueDict from django.utils.translation import gettext_lazy as _ @@ -35,7 +34,7 @@ def new_basket(request: WSGIRequest) -> HttpResponse: else: form = BasketForm() - return TemplateResponse( + return render( request, "purchase/basket_form.html", {"form": form, "products": Product.objects.with_no_fixed_price()}, @@ -102,7 +101,7 @@ def additional_unpriced_product(request: WSGIRequest) -> HttpResponse: @condition(etag_func=reports_etag, last_modified_func=reports_last_modified) def list_baskets(request: WSGIRequest) -> HttpResponse: context = {"baskets": Basket.objects.priced().order_by("-id")} - return TemplateResponse(request, "purchase/basket_list.html", context) + return render(request, "purchase/basket_list.html", context) @require_http_methods(["GET", "POST"]) @@ -111,7 +110,7 @@ def delete_basket(request: WSGIRequest, pk: int) -> HttpResponse: basket = get_object_or_404(Basket, pk=pk) if request.method == "GET": context = {"basket": basket} - return TemplateResponse(request, "purchase/basket_confirm_delete.html", context) + return render(request, "purchase/basket_confirm_delete.html", context) basket.delete() messages.success(request, _("Basket successfully deleted.")) return redirect("purchase:list") diff --git a/src/purchase/views/reports.py b/src/purchase/views/reports.py index bdfa36a..bac3fed 100644 --- a/src/purchase/views/reports.py +++ b/src/purchase/views/reports.py @@ -71,7 +71,7 @@ def reports(request): baskets = list(Basket.objects.priced().order_by("created_at")) if not baskets: messages.warning(request, _("No sale to report")) - return TemplateResponse(request, template_name, {}) + return render(request, template_name, {}) dates = Basket.objects.values_list("created_at__date", flat=True).distinct() by_day_report = [