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.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(
|
||||
|
|
|
@ -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)
|
||||
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
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block title %}Nouvelle commande groupée{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -10,8 +12,9 @@
|
|||
<p class="title">Nouvelle commande groupée</p>
|
||||
<div class="columns">
|
||||
<div class="column is-8">
|
||||
<form method="post" onsubmit="deadlinePassedCheck(event)">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<form method="post" onsubmit="deadlinePassedCheck(event)">
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
<div class="buttons">
|
||||
<a class="button is-light" href="{% url 'order:index' %}">Annuler</a>
|
||||
<input class="button is-primary" type="submit" value="Suivant">
|
||||
|
|
|
@ -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 %}
|
||||
</script>
|
||||
|
|
|
@ -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 @@
|
|||
<div class="box">
|
||||
<p class="title">{{ grouped_order.name }} - modifier</p>
|
||||
<form method="post" onsubmit="deadlinePassedCheck(event)">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
{{ form | crispy }}
|
||||
<div class="buttons">
|
||||
<a class="button is-light" href="{% url 'order:index' %}">Annuler</a>
|
||||
<input class="button is-primary" type="submit" value="Suivant">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<button type="button" class="collapsible">Open Collapsible</button>
|
||||
<div class="content">
|
||||
<p>Lorem ipsum...</p>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue