Copy constructor

This commit is contained in:
korenstin 2024-08-27 18:01:13 +02:00
parent 2e71ce05a9
commit 9ccac36831
3 changed files with 53 additions and 7 deletions

View File

@ -2,6 +2,7 @@
{% comment %} {% comment %}
SPDX-License-Identifier: GPL-3.0-or-later SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %} {% endcomment %}
{% load render_table from django_tables2 %}
{% load i18n crispy_forms_tags %} {% load i18n crispy_forms_tags %}
{% block content %} {% block content %}
@ -18,6 +19,37 @@ SPDX-License-Identifier: GPL-3.0-or-later
{{ form|crispy }} {{ form|crispy }}
<button class="btn btn-primary" type="submit">{% trans "Submit" %}</button> <button class="btn btn-primary" type="submit">{% trans "Submit" %}</button>
</form> </form>
<div class="card-body" id="profile_infos">
<h4>{% trans "Copy constructor" %}</h4>
<table class="table">
<thead>
<tr>
<th class="orderable">
{% trans "Name" %}
</th>
<th class="orderable">
{% trans "Owner" %}
</th>
<th class="orderable">
{% trans "Arrival date" %}
</th>
<th class="orderable">
{% trans "Expiry date" %}
</th>
</tr>
</thead>
<tbody>
{% for basic in last_basic %}
<tr>
<td><a href="{% url "food:qrcode_basic_create" slug=slug %}?copy={{ basic.pk }}">{{ basic.name }}</a></td>
<td>{{ basic.owner }}</td>
<td>{{ basic.arrival_date }}</td>
<td>{{ basic.expiry_date }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -150,6 +150,7 @@ class QRCodeBasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
return reverse('food:qrcode_view', kwargs={"slug": self.kwargs['slug']}) return reverse('food:qrcode_view', kwargs={"slug": self.kwargs['slug']})
def get_sample_object(self): def get_sample_object(self):
# We choose a club which may work or BDE else # We choose a club which may work or BDE else
owner_id = 1 owner_id = 1
for membership in self.request.user.memberships.all(): for membership in self.request.user.memberships.all():
@ -172,6 +173,14 @@ class QRCodeBasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
form.fields['is_active'].widget = HiddenInput() form.fields['is_active'].widget = HiddenInput()
form.fields['was_eaten'].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 return context
@ -188,14 +197,15 @@ class QRCodeCreateView(ProtectQuerysetMixin, ProtectedCreateView):
qrcode = kwargs["slug"] qrcode = kwargs["slug"]
if self.model.objects.filter(qr_code_number=qrcode).count() > 0: if self.model.objects.filter(qr_code_number=qrcode).count() > 0:
return HttpResponseRedirect(reverse("food:qrcode_view", kwargs=kwargs)) 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: else:
return super().get(*args, **kwargs) return super().get(*args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["slug"] = self.kwargs["slug"] context["slug"] = self.kwargs["slug"]
context["last_basic"] = BasicFood.objects.order_by('-pk').all()[:10]
return context return context
@transaction.atomic @transaction.atomic

View File

@ -562,16 +562,19 @@ msgstr "Aliment transformé"
msgid "Transformed foods" msgid "Transformed foods"
msgstr "Aliments transformés" 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/basicfood_detail.html:14
#: apps/food/templates/food/qrcode_detail.html:15 #: apps/food/templates/food/qrcode_detail.html:15
#: apps/food/templates/food/transformedfood_detail.html:14 #: apps/food/templates/food/transformedfood_detail.html:14
msgid "Owner" msgid "Owner"
msgstr "Propriétaire" msgstr "Propriétaire"
#: apps/food/templates/food/create_qrcode_form.html:34
#: apps/food/templates/food/basicfood_detail.html:15 #: apps/food/templates/food/basicfood_detail.html:15
msgid "Arrival date" msgid "Arrival date"
msgstr "Date d'arrivée" 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/basicfood_detail.html:16
#: apps/food/templates/food/qrcode_detail.html:16 #: apps/food/templates/food/qrcode_detail.html:16
#: apps/food/templates/food/transformedfood_detail.html:19 #: apps/food/templates/food/transformedfood_detail.html:19
@ -605,10 +608,15 @@ msgstr "Ajouter à un plat"
msgid "New basic food" msgid "New basic food"
msgstr "Nouvel aliment basique" 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 #: apps/food/templates/food/qrcode_detail.html:10
msgid "number" msgid "number"
msgstr "numéro" msgstr "numéro"
#: apps/food/templates/food/create_qrcode_form.html:28
#: apps/food/templates/food/qrcode_detail.html:14 #: apps/food/templates/food/qrcode_detail.html:14
#: apps/note/templates/note/transaction_form.html:132 #: apps/note/templates/note/transaction_form.html:132
#: apps/treasury/models.py:60 #: apps/treasury/models.py:60
@ -1644,13 +1652,9 @@ msgstr ""
#: apps/note/models/notes.py:70 #: apps/note/models/notes.py:70
msgid "The note is blocked by the the BDE and can't be manually reactivated." msgid "The note is blocked by the the BDE and can't be manually reactivated."
msgstr "" 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æ " "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." "propriétaire de la note."
>>>>>>> main
#: apps/note/models/notes.py:78 #: apps/note/models/notes.py:78
msgid "notes" msgid "notes"