diff --git a/apps/food/templates/food/create_qrcode_form.html b/apps/food/templates/food/create_qrcode_form.html index 17fff49f..456b9970 100644 --- a/apps/food/templates/food/create_qrcode_form.html +++ b/apps/food/templates/food/create_qrcode_form.html @@ -2,6 +2,7 @@ {% comment %} SPDX-License-Identifier: GPL-3.0-or-later {% endcomment %} +{% load render_table from django_tables2 %} {% load i18n crispy_forms_tags %} {% block content %} @@ -18,6 +19,37 @@ SPDX-License-Identifier: GPL-3.0-or-later {{ form|crispy }} +
+

{% trans "Copy constructor" %}

+ + + + + + + + + + + {% for basic in last_basic %} + + + + + + + {% endfor %} + +
+ {% trans "Name" %} + + {% trans "Owner" %} + + {% trans "Arrival date" %} + + {% trans "Expiry date" %} +
{{ basic.name }}{{ basic.owner }}{{ basic.arrival_date }}{{ basic.expiry_date }}
+
{% endblock %} diff --git a/apps/food/views.py b/apps/food/views.py index 9123c757..88964a5f 100644 --- a/apps/food/views.py +++ b/apps/food/views.py @@ -150,6 +150,7 @@ class QRCodeBasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView): return reverse('food:qrcode_view', kwargs={"slug": self.kwargs['slug']}) def get_sample_object(self): + # We choose a club which may work or BDE else owner_id = 1 for membership in self.request.user.memberships.all(): @@ -172,6 +173,14 @@ class QRCodeBasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView): form.fields['is_active'].widget = HiddenInput() form.fields['was_eaten'].widget = HiddenInput() + copy = self.request.GET.get('copy', None) + if copy is not None: + basic = BasicFood.objects.get(pk=copy) + for field in ['date_type', 'expiry_date', 'name', 'owner']: + form.fields[field].initial = getattr(basic, field) + for field in ['allergens']: + form.fields[field].initial = getattr(basic, field).all() + return context @@ -188,14 +197,15 @@ class QRCodeCreateView(ProtectQuerysetMixin, ProtectedCreateView): qrcode = kwargs["slug"] if self.model.objects.filter(qr_code_number=qrcode).count() > 0: return HttpResponseRedirect(reverse("food:qrcode_view", kwargs=kwargs)) - elif not TransformedFood.objects.filter(is_ready=False, was_eaten=False, is_active=True).count() > 0: - return HttpResponseRedirect(reverse("food:qrcode_basic_create", kwargs=kwargs)) else: return super().get(*args, **kwargs) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["slug"] = self.kwargs["slug"] + + context["last_basic"] = BasicFood.objects.order_by('-pk').all()[:10] + return context @transaction.atomic diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 298331b9..e3edfeea 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -562,16 +562,19 @@ msgstr "Aliment transformé" msgid "Transformed foods" msgstr "Aliments transformés" +#: apps/food/templates/food/create_qrcode_form.html:31 #: apps/food/templates/food/basicfood_detail.html:14 #: apps/food/templates/food/qrcode_detail.html:15 #: apps/food/templates/food/transformedfood_detail.html:14 msgid "Owner" msgstr "Propriétaire" +#: apps/food/templates/food/create_qrcode_form.html:34 #: apps/food/templates/food/basicfood_detail.html:15 msgid "Arrival date" msgstr "Date d'arrivée" +#: apps/food/templates/food/create_qrcode_form.html:37 #: apps/food/templates/food/basicfood_detail.html:16 #: apps/food/templates/food/qrcode_detail.html:16 #: apps/food/templates/food/transformedfood_detail.html:19 @@ -605,10 +608,15 @@ msgstr "Ajouter à un plat" msgid "New basic food" msgstr "Nouvel aliment basique" +#: apps/food/templates/food/create_qrcode_form.html:23 +msgid "Copy constructor" +msgstr "Constructeur de copie" + #: apps/food/templates/food/qrcode_detail.html:10 msgid "number" msgstr "numéro" +#: apps/food/templates/food/create_qrcode_form.html:28 #: apps/food/templates/food/qrcode_detail.html:14 #: apps/note/templates/note/transaction_form.html:132 #: apps/treasury/models.py:60 @@ -1644,13 +1652,9 @@ msgstr "" #: apps/note/models/notes.py:70 msgid "The note is blocked by the the BDE and can't be manually reactivated." msgstr "" -<<<<<<< HEAD -"La note est bloquée de force par le BDE et ne peut pas être débloquée par " -"le·a possesseur·ice de la note." -======= "La note est bloquée de force par le BDE et ne peut pas être débloquée par læ " "propriétaire de la note." ->>>>>>> main + #: apps/note/models/notes.py:78 msgid "notes"