1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-22 23:42:25 +00:00

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 %}
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 }}
<button class="btn btn-primary" type="submit">{% trans "Submit" %}</button>
</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>
{% endblock %}

View File

@ -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

View File

@ -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"