mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-05 13:21:49 +02:00
autocomplete personal informations from current user
This commit is contained in:
parent
ab5d510181
commit
008b2b36ea
3 changed files with 15 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
import random
|
||||
from typing import Any
|
||||
|
||||
import base36
|
||||
from django.core.exceptions import ValidationError
|
||||
|
@ -8,7 +9,6 @@ from django.utils import timezone
|
|||
|
||||
from la_chariotte.settings import AUTH_USER_MODEL
|
||||
|
||||
|
||||
class GroupedOrder(models.Model):
|
||||
name = models.CharField(
|
||||
max_length=100, null=True, verbose_name="Titre de la commande"
|
||||
|
@ -92,10 +92,9 @@ class GroupedOrder(models.Model):
|
|||
|
||||
|
||||
class OrderAuthor(models.Model):
|
||||
"""Used when a user orders (with or without an account)"""
|
||||
|
||||
# TODO faire le lien avec CustomUser (CustomUser hérite de OrderAuthor),
|
||||
# pour ensuite préremplir quand on est connecté·e
|
||||
|
||||
"""Used when a user orders (with or without an account)"""
|
||||
first_name = models.CharField(verbose_name="Prénom")
|
||||
last_name = models.CharField(verbose_name="Nom")
|
||||
phone = models.CharField(
|
||||
|
@ -107,6 +106,7 @@ class OrderAuthor(models.Model):
|
|||
help_text="Pour que l'organisateur·ice vous contacte en cas de besoin",
|
||||
)
|
||||
|
||||
|
||||
def __str__(self): # pragma: no cover
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
|
|
|
@ -138,15 +138,15 @@
|
|||
<div class="columns">
|
||||
<div class="column">
|
||||
<p><label for="first_name">Prénom : </label>
|
||||
<input id="first_name" type="text" name="first_name" placeholder="Votre prénom" value="{{ author.first_name }}" required></p>
|
||||
<input id="first_name" type="text" name="first_name" placeholder="Votre prénom" value="{{ order_author.first_name }}" required></p>
|
||||
<p><label for="first_name">Nom : </label>
|
||||
<input id="last_name" type="text" name="last_name" placeholder="Votre nom" value="{{ author.last_name }}" required></p>
|
||||
<input id="last_name" type="text" name="last_name" placeholder="Votre nom" value="{{ order_author.last_name }}" required></p>
|
||||
</div>
|
||||
<div class="column">
|
||||
<p><label for="phone">Numéro de téléphone :</label>
|
||||
<input id="phone" type="tel" pattern="[0-9]{10}" placeholder="0601020304" name="phone" value="{{ author.phone }}" required></p>
|
||||
<input id="phone" type="tel" pattern="[0-9]{10}" placeholder="0601020304" name="phone" value="{{ order_author.phone }}" required></p>
|
||||
<p><label for="email">Adresse mail : </label>
|
||||
<input id="email" type="email" placeholder="exemple@mail.fr" name="email" value="{{ author.email }}" required></p>
|
||||
<input id="email" type="email" placeholder="exemple@mail.fr" name="email" value="{{ order_author.email }}" required></p>
|
||||
</div>
|
||||
</div>
|
||||
<p><label for="note">Note à l'organisateur·ice</label>
|
||||
|
|
|
@ -110,6 +110,11 @@ class GroupedOrderDetailView(generic.DetailView):
|
|||
|
||||
remaining_qty = {item.id: item.get_remaining_nb() for item in items}
|
||||
prices_dict = {item.id: item.price for item in items}
|
||||
if self.request.user.is_authenticated:
|
||||
order_author = OrderAuthor.objects.create(first_name=self.request.user.first_name, last_name=self.request.user.last_name, email=self.request.user.username)
|
||||
order_author.save()
|
||||
else:
|
||||
order_author = None
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(
|
||||
|
@ -117,8 +122,10 @@ class GroupedOrderDetailView(generic.DetailView):
|
|||
# Used for the js display of total price of an order
|
||||
"prices_dict": json.dumps(prices_dict, cls=DjangoJSONEncoder),
|
||||
"remaining_qty": remaining_qty,
|
||||
"order_author": order_author,
|
||||
}
|
||||
)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue