feat: improve customer address views
This commit is contained in:
+13
-3
@@ -77,7 +77,7 @@ def cart_dropdown(request, *args, **kwargs):
|
||||
)
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
response.set_cookie(ANONYMOUS_CART_ID_COOKIE_NAME, cart.uuid)
|
||||
response.set_cookie(ANONYMOUS_CART_ID_COOKIE_NAME, cart.uuid, samesite="strict")
|
||||
return response
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ def cart(request, *args, **kwargs):
|
||||
)
|
||||
|
||||
if not request.user.is_authenticated:
|
||||
response.set_cookie(ANONYMOUS_CART_ID_COOKIE_NAME, cart.uuid)
|
||||
response.set_cookie(ANONYMOUS_CART_ID_COOKIE_NAME, cart.uuid, samesite="strict")
|
||||
return response
|
||||
|
||||
|
||||
@@ -179,13 +179,22 @@ class UserInfoComponentView(TemplateView):
|
||||
return render(request, self.template_name, {"form": form})
|
||||
|
||||
|
||||
class ListCustomerAddressComponent(TemplateView):
|
||||
template_name = "components/users/retrieve_update_address.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return {
|
||||
"customer_addresses": CustomerAddress.objects.filter(user=self.request.user)
|
||||
}
|
||||
|
||||
|
||||
def update_customer_address(request, pk):
|
||||
customer_address = get_object_or_404(CustomerAddress, pk=pk, user=request.user)
|
||||
form = CustomerAddressForm(request.POST, instance=customer_address)
|
||||
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return HttpResponse(status=200)
|
||||
return HttpResponse(status=200, headers={"HX-Trigger": "updated_addresses"})
|
||||
|
||||
return HttpResponse(form.errors, status=400)
|
||||
|
||||
@@ -195,3 +204,4 @@ list_wishlisted_products = ListWishlistedProducts.as_view()
|
||||
wishlist_button = WishlistButton.as_view()
|
||||
|
||||
user_info_component = UserInfoComponentView.as_view()
|
||||
list_customer_addresses_component = ListCustomerAddressComponent.as_view()
|
||||
|
||||
+7
-3
@@ -6,7 +6,11 @@ from django.contrib.auth.tokens import default_token_generator
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import IntegrityError
|
||||
from django.shortcuts import redirect, render, reverse
|
||||
from django.utils.http import url_has_allowed_host_and_scheme, urlsafe_base64_decode, urlencode
|
||||
from django.utils.http import (
|
||||
url_has_allowed_host_and_scheme,
|
||||
urlencode,
|
||||
urlsafe_base64_decode,
|
||||
)
|
||||
from django.utils.text import gettext_lazy as _
|
||||
from django.views.generic import TemplateView, View
|
||||
|
||||
@@ -30,10 +34,10 @@ class LoginView(View, RedirectionMixin):
|
||||
login_form_class = LoginForm
|
||||
|
||||
def get_redirection(self):
|
||||
next_page = self.request.GET.get('next', '')
|
||||
next_page = self.request.GET.get("next", "")
|
||||
|
||||
if next_page:
|
||||
return f'{reverse(self.redirect_to)}?next={next_page}'
|
||||
return f"{reverse(self.redirect_to)}?next={next_page}"
|
||||
|
||||
return reverse(self.redirect_to)
|
||||
|
||||
|
||||
+17
-7
@@ -36,8 +36,8 @@ class IndexView(TemplateView):
|
||||
}
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if self.request.GET.get('next'):
|
||||
return redirect(self.request.GET.get('next'))
|
||||
if self.request.GET.get("next"):
|
||||
return redirect(self.request.GET.get("next"))
|
||||
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
@@ -230,7 +230,7 @@ def add_cart_item(request, *args, **kwargs):
|
||||
response = HttpResponse(status=201, headers={"HX-Trigger": "updated-cart"})
|
||||
|
||||
if created and request.user.is_anonymous:
|
||||
response.set_cookie(ANONYMOUS_CART_ID_COOKIE_NAME, cart.uuid)
|
||||
response.set_cookie(ANONYMOUS_CART_ID_COOKIE_NAME, cart.uuid, samesite="strict")
|
||||
|
||||
# Comprobamos si existe una línea de carrito para ese carrito de ese producto
|
||||
existing_cart_item = CartItem.objects.filter(cart=cart, product=product).first()
|
||||
@@ -309,11 +309,21 @@ def manifest(request, *args, **kwargs):
|
||||
"orientation": "portrait",
|
||||
}
|
||||
|
||||
if settings.logo_240:
|
||||
if settings.logo:
|
||||
data["icons"].append(
|
||||
{
|
||||
"src": settings.logo_240.url,
|
||||
"sizes": "240x240",
|
||||
"src": settings.logo.url,
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any",
|
||||
}
|
||||
)
|
||||
|
||||
if settings.logo_256:
|
||||
data["icons"].append(
|
||||
{
|
||||
"src": settings.logo_256.url,
|
||||
"sizes": "256x256",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any",
|
||||
}
|
||||
@@ -323,7 +333,7 @@ def manifest(request, *args, **kwargs):
|
||||
data["icons"].append(
|
||||
{
|
||||
"src": settings.logo_128.url,
|
||||
"sizes": "240x240",
|
||||
"sizes": "128x128",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user