feat: update address working
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from django import forms
|
||||
from django.forms import widgets
|
||||
|
||||
from shop.models import CustomerAddress
|
||||
|
||||
|
||||
class CartItemForm(forms.Form):
|
||||
"""
|
||||
@@ -35,3 +37,17 @@ class CreateOrderForm(forms.Form):
|
||||
billing_address_phone = forms.CharField(max_length=16, required=False)
|
||||
|
||||
shipping_method = forms.IntegerField()
|
||||
|
||||
|
||||
class CustomerAddressForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = CustomerAddress
|
||||
fields = (
|
||||
"vat_id",
|
||||
"full_name",
|
||||
"address",
|
||||
"address_town",
|
||||
"address_zip",
|
||||
"address_state",
|
||||
"address_phone",
|
||||
)
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
{% for address in customer_addresses %}
|
||||
<form id="edit_address_{{ address.pk }}" class="hidden py-2 md:py-4" hx-post="" hx-swap="none">
|
||||
<form
|
||||
id="edit_address_{{ address.pk }}"
|
||||
class="hidden py-2 md:py-4"
|
||||
hx-post="{% url 'web:update_customer_address' pk=address.pk %}"
|
||||
hx-on:htmx:after-request="htmx.toggleClass(htmx.find('#edit_address_{{ address.pk }}'), 'hidden'); htmx.toggleClass(htmx.find('#details_address_{{ address.pk }}'), 'hidden')"
|
||||
hx-swap="none"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<div class="mb-4 grid gap-4 sm:grid-cols-2 sm:gap-8 lg:gap-16">
|
||||
<div class="space-y-4">
|
||||
@@ -16,7 +22,7 @@
|
||||
focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700
|
||||
dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500
|
||||
dark:focus:border-primary-500"
|
||||
id="address_full_name" type="text" value="{{ address.full_name }}">
|
||||
id="address_full_name" name="full_name" type="text" value="{{ address.full_name }}">
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
@@ -100,7 +106,7 @@
|
||||
focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600
|
||||
dark:hover:bg-primary-700 dark:focus:ring-primary-800"
|
||||
>
|
||||
{% translate 'Actualizar datos' %}
|
||||
{% translate 'Guardar' %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
+2
-1
@@ -9,7 +9,7 @@ from web.views.components import (
|
||||
list_products,
|
||||
list_wishlisted_products,
|
||||
wishlist_button,
|
||||
user_info_component,
|
||||
user_info_component, update_customer_address,
|
||||
)
|
||||
from web.views.users import (
|
||||
login,
|
||||
@@ -96,6 +96,7 @@ urlpatterns = [
|
||||
delete_from_wishlist,
|
||||
name="delete_from_wishlist",
|
||||
),
|
||||
path("web/customer-address/<int:pk>/", update_customer_address, name="update_customer_address"),
|
||||
# manifest
|
||||
path("manifest.json", manifest, name="manifest_json"),
|
||||
]
|
||||
|
||||
@@ -14,6 +14,7 @@ from shop.models import (
|
||||
WishlistedProduct,
|
||||
)
|
||||
from users.forms.info import UserInfoForm
|
||||
from web.forms import CustomerAddressForm
|
||||
from web.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin
|
||||
from web.models import WebSettings
|
||||
from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
@@ -178,6 +179,17 @@ class UserInfoComponentView(TemplateView):
|
||||
return render(request, self.template_name, {"form": form})
|
||||
|
||||
|
||||
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(form.errors, status=400)
|
||||
|
||||
|
||||
list_products = ListProducts.as_view()
|
||||
list_wishlisted_products = ListWishlistedProducts.as_view()
|
||||
wishlist_button = WishlistButton.as_view()
|
||||
|
||||
Reference in New Issue
Block a user