diff --git a/la_chariotte/order/forms.py b/la_chariotte/order/forms.py index 8e28d5a..334339c 100644 --- a/la_chariotte/order/forms.py +++ b/la_chariotte/order/forms.py @@ -4,6 +4,7 @@ from django import forms from django.contrib.auth import get_user_model from django.forms.utils import to_current_timezone from django.utils import timezone +from pygments.lexer import default from la_chariotte.order.models import GroupedOrder, Item @@ -18,6 +19,10 @@ class GroupedOrderForm(forms.ModelForm): widget=forms.TimeInput(attrs={"type": "time"}), initial=datetime.time(hour=23, minute=59, second=59), ) + phone_mandatory = forms.BooleanField( + label="Numéro de téléphone obligatoire pour les participants", + required=False, + ) class Meta: model = GroupedOrder @@ -29,6 +34,7 @@ class GroupedOrderForm(forms.ModelForm): "delivery_slot", "place", "description", + "phone_mandatory" ] widgets = { "name": forms.TextInput( diff --git a/la_chariotte/order/migrations/0027_groupedorder_phone_mandatory.py b/la_chariotte/order/migrations/0027_groupedorder_phone_mandatory.py new file mode 100644 index 0000000..273749b --- /dev/null +++ b/la_chariotte/order/migrations/0027_groupedorder_phone_mandatory.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.11 on 2024-04-14 08:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("order", "0026_groupedorder_delivery_slot"), + ] + + operations = [ + migrations.AddField( + model_name="groupedorder", + name="phone_mandatory", + field=models.BooleanField( + default=False, verbose_name="Numéro de téléphone obligatoire" + ), + ), + ] diff --git a/la_chariotte/order/models.py b/la_chariotte/order/models.py index 55dd867..84d601f 100644 --- a/la_chariotte/order/models.py +++ b/la_chariotte/order/models.py @@ -27,6 +27,7 @@ class GroupedOrder(models.Model): description = models.TextField("Description", null=True, blank=True) total_price = models.DecimalField(max_digits=10, decimal_places=2, default=0) code = models.CharField(auto_created=True) + phone_mandatory = models.BooleanField(default=False, verbose_name="Numéro de téléphone obligatoire") def create_code_from_pk(self): """When a grouped order is created, a unique code is generated, to be used to diff --git a/la_chariotte/order/templates/order/grouped_order_create.html b/la_chariotte/order/templates/order/grouped_order_create.html index 3accfb1..01c8858 100644 --- a/la_chariotte/order/templates/order/grouped_order_create.html +++ b/la_chariotte/order/templates/order/grouped_order_create.html @@ -1,5 +1,7 @@ {% extends 'base.html' %} +{% load crispy_forms_tags %} + {% block title %}Nouvelle commande groupée{% endblock %} {% block content %} @@ -10,8 +12,9 @@

Nouvelle commande groupée

-
{% csrf_token %} - {{ form.as_p }} + + {% csrf_token %} + {{ form | crispy }}
Annuler diff --git a/la_chariotte/order/templates/order/grouped_order_detail.html b/la_chariotte/order/templates/order/grouped_order_detail.html index b80aed5..b8472dd 100644 --- a/la_chariotte/order/templates/order/grouped_order_detail.html +++ b/la_chariotte/order/templates/order/grouped_order_detail.html @@ -186,7 +186,6 @@ // Compute total price whenever a value in input is modified document.getElementById("inputs-parent").addEventListener("change", function () { inputs = [...document.getElementsByTagName("input")].filter(input => input.getAttribute("name").indexOf("quantity_") === 0); //filter the inputs to get the quantity inputs only - prices = {{ prices_dict | safe }}; let total_price = 0; @@ -200,5 +199,11 @@ el.innerHTML = total_price; }) }); + + + if( '{{ phone_required }}' === 'True') { + document.getElementById('phone').required = true + } + {% endblock %} diff --git a/la_chariotte/order/templates/order/grouped_order_update.html b/la_chariotte/order/templates/order/grouped_order_update.html index e6ad3b4..d8d0695 100644 --- a/la_chariotte/order/templates/order/grouped_order_update.html +++ b/la_chariotte/order/templates/order/grouped_order_update.html @@ -1,5 +1,7 @@ {% extends 'base.html' %} +{% load crispy_forms_tags %} + {% block title %}Modifier la commande groupée{% endblock %} {% block content %} @@ -9,13 +11,19 @@

{{ grouped_order.name }} - modifier

{% csrf_token %} - {{ form.as_p }} + {{ form | crispy }}
+ + +
+

Lorem ipsum...

+
+ {% endblock %} {% block extra_js %} diff --git a/la_chariotte/order/views/grouped_order.py b/la_chariotte/order/views/grouped_order.py index f2c454b..ff77335 100644 --- a/la_chariotte/order/views/grouped_order.py +++ b/la_chariotte/order/views/grouped_order.py @@ -30,8 +30,8 @@ class IndexView(LoginRequiredMixin, generic.ListView): # Get the 5 most recent old grouped orders old = grouped_orders.filter(delivery_date__lt=today).order_by("-delivery_date")[ - :5 - ] + :5 + ] # Get grouped orders that have crossed their ordering deadline # but the delivery date is still to come. @@ -82,7 +82,7 @@ class GroupedOrderEventView(generic.DetailView): description += "Heure de livraison : " + self.object.delivery_slot + "\n" if self.object.description: description += ( - "Note de l'organisateur.ice : " + "\n" + self.object.description + "Note de l'organisateur.ice : " + "\n" + self.object.description ) event.add("description", vText(description)) @@ -112,7 +112,8 @@ class GroupedOrderDetailView(generic.DetailView): return get_object_or_404(GroupedOrder, code=self.kwargs.get("code")) def get_context_data(self, **kwargs): - items = self.get_object().item_set.all() + grouped_order = self.get_object() + items = grouped_order.item_set.all() remaining_qty = {item.id: item.get_remaining_nb() for item in items} prices_dict = {item.id: item.price for item in items} @@ -134,6 +135,8 @@ class GroupedOrderDetailView(generic.DetailView): "prices_dict": json.dumps(prices_dict, cls=DjangoJSONEncoder), "remaining_qty": remaining_qty, "order_author": order_author, + # Used to set if the phone is required in the form + "phone_required": grouped_order.phone_mandatory, } ) return context @@ -362,7 +365,7 @@ class ExportGroupedOrderToCSVView(GroupedOrderExportView): response = http.HttpResponse( content_type="text/csv", headers={ - "Content-Disposition": f'attachment; filename="{ context["object"].name }-commandes"' + "Content-Disposition": f'attachment; filename="{context["object"].name}-commandes"' }, ) writer = csv.writer(response)