mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-03 12:21:52 +02:00
166 téléphone obligatoire (manque css)
This commit is contained in:
parent
34d2db8623
commit
76311065d9
7 changed files with 55 additions and 9 deletions
|
@ -4,6 +4,7 @@ from django import forms
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.forms.utils import to_current_timezone
|
from django.forms.utils import to_current_timezone
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from pygments.lexer import default
|
||||||
|
|
||||||
from la_chariotte.order.models import GroupedOrder, Item
|
from la_chariotte.order.models import GroupedOrder, Item
|
||||||
|
|
||||||
|
@ -18,6 +19,10 @@ class GroupedOrderForm(forms.ModelForm):
|
||||||
widget=forms.TimeInput(attrs={"type": "time"}),
|
widget=forms.TimeInput(attrs={"type": "time"}),
|
||||||
initial=datetime.time(hour=23, minute=59, second=59),
|
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:
|
class Meta:
|
||||||
model = GroupedOrder
|
model = GroupedOrder
|
||||||
|
@ -29,6 +34,7 @@ class GroupedOrderForm(forms.ModelForm):
|
||||||
"delivery_slot",
|
"delivery_slot",
|
||||||
"place",
|
"place",
|
||||||
"description",
|
"description",
|
||||||
|
"phone_mandatory"
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
"name": forms.TextInput(
|
"name": forms.TextInput(
|
||||||
|
|
|
@ -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"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -27,6 +27,7 @@ class GroupedOrder(models.Model):
|
||||||
description = models.TextField("Description", null=True, blank=True)
|
description = models.TextField("Description", null=True, blank=True)
|
||||||
total_price = models.DecimalField(max_digits=10, decimal_places=2, default=0)
|
total_price = models.DecimalField(max_digits=10, decimal_places=2, default=0)
|
||||||
code = models.CharField(auto_created=True)
|
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):
|
def create_code_from_pk(self):
|
||||||
"""When a grouped order is created, a unique code is generated, to be used to
|
"""When a grouped order is created, a unique code is generated, to be used to
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
|
||||||
{% block title %}Nouvelle commande groupée{% endblock %}
|
{% block title %}Nouvelle commande groupée{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -10,8 +12,9 @@
|
||||||
<p class="title">Nouvelle commande groupée</p>
|
<p class="title">Nouvelle commande groupée</p>
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column is-8">
|
<div class="column is-8">
|
||||||
<form method="post" onsubmit="deadlinePassedCheck(event)">{% csrf_token %}
|
<form method="post" onsubmit="deadlinePassedCheck(event)">
|
||||||
{{ form.as_p }}
|
{% csrf_token %}
|
||||||
|
{{ form | crispy }}
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a class="button is-light" href="{% url 'order:index' %}">Annuler</a>
|
<a class="button is-light" href="{% url 'order:index' %}">Annuler</a>
|
||||||
<input class="button is-primary" type="submit" value="Suivant">
|
<input class="button is-primary" type="submit" value="Suivant">
|
||||||
|
|
|
@ -186,7 +186,6 @@
|
||||||
// Compute total price whenever a value in input is modified
|
// Compute total price whenever a value in input is modified
|
||||||
document.getElementById("inputs-parent").addEventListener("change", function () {
|
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
|
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 }};
|
prices = {{ prices_dict | safe }};
|
||||||
let total_price = 0;
|
let total_price = 0;
|
||||||
|
|
||||||
|
@ -200,5 +199,11 @@
|
||||||
el.innerHTML = total_price;
|
el.innerHTML = total_price;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if( '{{ phone_required }}' === 'True') {
|
||||||
|
document.getElementById('phone').required = true
|
||||||
|
}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
|
||||||
{% block title %}Modifier la commande groupée{% endblock %}
|
{% block title %}Modifier la commande groupée{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -9,13 +11,19 @@
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<p class="title">{{ grouped_order.name }} - modifier</p>
|
<p class="title">{{ grouped_order.name }} - modifier</p>
|
||||||
<form method="post" onsubmit="deadlinePassedCheck(event)">{% csrf_token %}
|
<form method="post" onsubmit="deadlinePassedCheck(event)">{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form | crispy }}
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a class="button is-light" href="{% url 'order:index' %}">Annuler</a>
|
<a class="button is-light" href="{% url 'order:index' %}">Annuler</a>
|
||||||
<input class="button is-primary" type="submit" value="Suivant">
|
<input class="button is-primary" type="submit" value="Suivant">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button type="button" class="collapsible">Open Collapsible</button>
|
||||||
|
<div class="content">
|
||||||
|
<p>Lorem ipsum...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
|
|
|
@ -30,8 +30,8 @@ class IndexView(LoginRequiredMixin, generic.ListView):
|
||||||
|
|
||||||
# Get the 5 most recent old grouped orders
|
# Get the 5 most recent old grouped orders
|
||||||
old = grouped_orders.filter(delivery_date__lt=today).order_by("-delivery_date")[
|
old = grouped_orders.filter(delivery_date__lt=today).order_by("-delivery_date")[
|
||||||
:5
|
:5
|
||||||
]
|
]
|
||||||
|
|
||||||
# Get grouped orders that have crossed their ordering deadline
|
# Get grouped orders that have crossed their ordering deadline
|
||||||
# but the delivery date is still to come.
|
# 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"
|
description += "Heure de livraison : " + self.object.delivery_slot + "\n"
|
||||||
if self.object.description:
|
if self.object.description:
|
||||||
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))
|
event.add("description", vText(description))
|
||||||
|
|
||||||
|
@ -112,7 +112,8 @@ class GroupedOrderDetailView(generic.DetailView):
|
||||||
return get_object_or_404(GroupedOrder, code=self.kwargs.get("code"))
|
return get_object_or_404(GroupedOrder, code=self.kwargs.get("code"))
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
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}
|
remaining_qty = {item.id: item.get_remaining_nb() for item in items}
|
||||||
prices_dict = {item.id: item.price 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),
|
"prices_dict": json.dumps(prices_dict, cls=DjangoJSONEncoder),
|
||||||
"remaining_qty": remaining_qty,
|
"remaining_qty": remaining_qty,
|
||||||
"order_author": order_author,
|
"order_author": order_author,
|
||||||
|
# Used to set if the phone is required in the form
|
||||||
|
"phone_required": grouped_order.phone_mandatory,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return context
|
return context
|
||||||
|
@ -362,7 +365,7 @@ class ExportGroupedOrderToCSVView(GroupedOrderExportView):
|
||||||
response = http.HttpResponse(
|
response = http.HttpResponse(
|
||||||
content_type="text/csv",
|
content_type="text/csv",
|
||||||
headers={
|
headers={
|
||||||
"Content-Disposition": f'attachment; filename="{ context["object"].name }-commandes"'
|
"Content-Disposition": f'attachment; filename="{context["object"].name}-commandes"'
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
writer = csv.writer(response)
|
writer = csv.writer(response)
|
||||||
|
|
Loading…
Reference in a new issue