From b3cc0085ff54d6f84a84c8b3dc832df239d663e1 Mon Sep 17 00:00:00 2001 From: Laetitia Date: Sat, 15 Feb 2025 17:43:30 +0100 Subject: [PATCH] Make phone not mandatory --- la_chariotte/order/forms.py | 5 ++++ .../0028_groupedorder_is_phone_mandatory.py | 20 +++++++++++++ ...set_phone_mandatory_for_existing_orders.py | 20 +++++++++++++ la_chariotte/order/models.py | 3 ++ .../templates/order/grouped_order_create.html | 7 +++-- .../templates/order/grouped_order_detail.html | 13 ++++---- .../order/grouped_order_overview.html | 2 +- .../templates/order/grouped_order_update.html | 5 +++- la_chariotte/order/views/grouped_order.py | 7 +++-- .../tests/test_order_views_grouped_order.py | 30 +++++++++++++++++++ la_chariotte/tests/utils.py | 12 ++++++-- 11 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 la_chariotte/order/migrations/0028_groupedorder_is_phone_mandatory.py create mode 100644 la_chariotte/order/migrations/0029_set_phone_mandatory_for_existing_orders.py diff --git a/la_chariotte/order/forms.py b/la_chariotte/order/forms.py index 8e28d5a..2cf2817 100644 --- a/la_chariotte/order/forms.py +++ b/la_chariotte/order/forms.py @@ -18,6 +18,10 @@ class GroupedOrderForm(forms.ModelForm): widget=forms.TimeInput(attrs={"type": "time"}), initial=datetime.time(hour=23, minute=59, second=59), ) + is_phone_mandatory = forms.BooleanField( + label="Numéro de téléphone obligatoire pour les participants", + required=False, + ) class Meta: model = GroupedOrder @@ -29,6 +33,7 @@ class GroupedOrderForm(forms.ModelForm): "delivery_slot", "place", "description", + "is_phone_mandatory", ] widgets = { "name": forms.TextInput( diff --git a/la_chariotte/order/migrations/0028_groupedorder_is_phone_mandatory.py b/la_chariotte/order/migrations/0028_groupedorder_is_phone_mandatory.py new file mode 100644 index 0000000..809fd55 --- /dev/null +++ b/la_chariotte/order/migrations/0028_groupedorder_is_phone_mandatory.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.16 on 2024-12-08 15:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("order", "0027_remove_groupedorder_total_price_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="groupedorder", + name="is_phone_mandatory", + field=models.BooleanField( + default=False, verbose_name="Numéro de téléphone obligatoire" + ), + ), + ] diff --git a/la_chariotte/order/migrations/0029_set_phone_mandatory_for_existing_orders.py b/la_chariotte/order/migrations/0029_set_phone_mandatory_for_existing_orders.py new file mode 100644 index 0000000..2b6a0a9 --- /dev/null +++ b/la_chariotte/order/migrations/0029_set_phone_mandatory_for_existing_orders.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.16 on 2024-12-08 15:41 + +from django.db import migrations + +def set_phone_mandatory(apps, schema_editor): + """For continuity, force mandatory phone for the orders that were created so far.""" + GroupedOrder = apps.get_model("order", "GroupedOrder") + for grouped_order in GroupedOrder.objects.all(): + grouped_order.is_phone_mandatory = True + grouped_order.save() + +class Migration(migrations.Migration): + + dependencies = [ + ("order", "0028_groupedorder_is_phone_mandatory"), + ] + + operations = [ + migrations.RunPython(set_phone_mandatory), + ] diff --git a/la_chariotte/order/models.py b/la_chariotte/order/models.py index 7dd7c0c..5450f72 100644 --- a/la_chariotte/order/models.py +++ b/la_chariotte/order/models.py @@ -26,6 +26,9 @@ class GroupedOrder(models.Model): ) description = models.TextField("Description", null=True, blank=True) code = models.CharField(auto_created=True) + is_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..b73d467 100644 --- a/la_chariotte/order/templates/order/grouped_order_detail.html +++ b/la_chariotte/order/templates/order/grouped_order_detail.html @@ -158,16 +158,18 @@ value="{{ order_author.last_name }}" required>

-

-

+

+

-

-

+

+