1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-07-17 06:45:53 +02:00

Easier access to food details

This commit is contained in:
Ehouarn
2025-07-11 16:35:49 +02:00
parent 608804db30
commit 5989721bc9
4 changed files with 122 additions and 37 deletions

View File

@ -7,7 +7,52 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% load i18n %}
{% block content %}
{{ block.super }}
<div class="card bg-light">
<h3 class="card-header text-center">
{{ title }}
</h3>
<div class="card-body">
<style>
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type=number] {
appearance: textfield;
padding: 6px;
border: 1px solid #ccc;
border-radius: 4px;
width: 100px;
}
</style>
<div class="d-flex align-items-center" style="max-width: 300px;">
<form method="get" action="{% url 'food:redirect_view' %}" class="d-flex w-100">
<input type="number" name="slug" placeholder="QR-code" required class="form-control form-control-sm" style="max-width: 120px;">
<button type="submit" class="btn btn-sm btn-primary">{% trans "View food" %}</button>
</form>
</div>
</div>
<div class="card-body">
<input id="searchbar" type="text" class="form-control"
placeholder="{% trans "Search by attribute such as name..." %}">
</div>
{% block extra_inside_card %}
{% endblock %}
<div id="dynamic-table">
{% if table.data %}
{% render_table table %}
{% else %}
<div class="card-body">
<div class="alert alert-warning">
{% trans "There is no results." %}
</div>
</div>
{% endif %}
</div>
</div>
<br>
<div class="card bg-light mb-3">
<h3 class="card-header text-center">
@ -68,4 +113,20 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endfor %}
{% endif %}
</div>
{% endblock %}
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('goButton').addEventListener('click', function(event) {
event.preventDefault();
const slug = document.getElementById('slugInput').value;
if (slug && !isNaN(slug)) {
window.location.href = `/food/${slug}/`;
} else {
alert("Veuillez entrer un nombre valide.");
}
});
});
</script>
{% endblock %}

View File

@ -18,4 +18,5 @@ urlpatterns = [
path('detail/basic/<int:pk>', views.BasicFoodDetailView.as_view(), name='basicfood_view'),
path('detail/transformed/<int:pk>', views.TransformedFoodDetailView.as_view(), name='transformedfood_view'),
path('add/ingredient/<int:pk>', views.AddIngredientView.as_view(), name='add_ingredient'),
path('redirect/', views.QRCodeRedirectView.as_view(), name='redirect_view'),
]

View File

@ -10,6 +10,7 @@ from django.db.models import Q
from django.http import HttpResponseRedirect, Http404
from django.views.generic import DetailView, UpdateView, CreateView
from django.views.generic.list import ListView
from django.views.generic.base import RedirectView
from django.urls import reverse_lazy
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
@ -483,3 +484,14 @@ class TransformedFoodDetailView(FoodDetailView):
if Food.objects.filter(pk=kwargs['pk']).count() == 1:
kwargs['stop_redirect'] = (Food.objects.get(pk=kwargs['pk']).polymorphic_ctype.model == 'transformedfood')
return super().get(*args, **kwargs)
class QRCodeRedirectView(RedirectView):
"""
Redirects to the QR code creation page from Food List
"""
def get_redirect_url(self, *args, **kwargs):
slug = self.request.GET.get('slug')
if slug:
return reverse_lazy('food:qrcode_create', kwargs={'slug': slug})
return reverse_lazy('food:list')

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-04-30 11:44+0200\n"
"POT-Creation-Date: 2025-07-11 16:10+0200\n"
"PO-Revision-Date: 2022-04-11 22:05+0200\n"
"Last-Translator: bleizi <bleizi@crans.org>\n"
"Language-Team: French <http://translate.ynerant.fr/projects/nk20/nk20/fr/>\n"
@ -563,7 +563,7 @@ msgstr "est prêt"
msgid "order"
msgstr "consigne"
#: apps/food/models.py:107 apps/food/views.py:34
#: apps/food/models.py:107 apps/food/views.py:35
#: note_kfet/templates/base.html:72
msgid "Food"
msgstr "Bouffe"
@ -625,59 +625,73 @@ msgstr "QR-codes"
msgid "QR-code number"
msgstr "Numéro de QR-code"
#: apps/food/templates/food/food_detail.html:19
#: apps/food/templates/food/food_detail.html:22
msgid "Contained in"
msgstr "Contenu dans"
#: apps/food/templates/food/food_detail.html:26
#: apps/food/templates/food/food_detail.html:29
msgid "Contain"
msgstr "Contient"
#: apps/food/templates/food/food_detail.html:35
#: apps/food/templates/food/food_detail.html:38
msgid "Update"
msgstr "Modifier"
#: apps/food/templates/food/food_detail.html:40
#: apps/food/templates/food/food_detail.html:43
msgid "Add to a meal"
msgstr "Ajouter à un plat"
#: apps/food/templates/food/food_detail.html:45
#: apps/food/templates/food/food_detail.html:48
msgid "Manage ingredients"
msgstr "Gérer les ingrédients"
#: apps/food/templates/food/food_detail.html:49
#: apps/food/templates/food/food_detail.html:52
msgid "Return to the food list"
msgstr "Retour à la liste de nourriture"
#: apps/food/templates/food/food_list.html:14
#: apps/food/templates/food/food_list.html:32
msgid "View food"
msgstr "Voir l'aliment"
#: apps/food/templates/food/food_list.html:37
#: note_kfet/templates/base_search.html:15
msgid "Search by attribute such as name..."
msgstr "Chercher par un attribut tel que le nom..."
#: apps/food/templates/food/food_list.html:49
#: note_kfet/templates/base_search.html:23
msgid "There is no results."
msgstr "Il n'y a pas de résultat."
#: apps/food/templates/food/food_list.html:58
msgid "Meal served"
msgstr "Plat servis"
#: apps/food/templates/food/food_list.html:19
#: apps/food/templates/food/food_list.html:63
msgid "New meal"
msgstr "Nouveau plat"
#: apps/food/templates/food/food_list.html:28
#: apps/food/templates/food/food_list.html:72
msgid "There is no meal served."
msgstr "Il n'y a pas de plat servi."
#: apps/food/templates/food/food_list.html:35
#: apps/food/templates/food/food_list.html:79
msgid "Free food"
msgstr "Open"
#: apps/food/templates/food/food_list.html:42
#: apps/food/templates/food/food_list.html:86
msgid "There is no free food."
msgstr "Il n'y a pas de bouffe en open"
#: apps/food/templates/food/food_list.html:50
#: apps/food/templates/food/food_list.html:94
msgid "Food of your clubs"
msgstr "Bouffe de tes clubs"
#: apps/food/templates/food/food_list.html:56
#: apps/food/templates/food/food_list.html:100
msgid "Food of club"
msgstr "Bouffe du club"
#: apps/food/templates/food/food_list.html:63
#: apps/food/templates/food/food_list.html:107
msgid "Yours club has not food yet."
msgstr "Ton club n'a pas de bouffe pour l'instant"
@ -751,49 +765,49 @@ msgstr "semaines"
msgid "and"
msgstr "et"
#: apps/food/views.py:118
#: apps/food/views.py:120
msgid "Add a new QRCode"
msgstr "Ajouter un nouveau QR-code"
#: apps/food/views.py:167
#: apps/food/views.py:169
msgid "Add an aliment"
msgstr "Ajouter un nouvel aliment"
#: apps/food/views.py:226
#: apps/food/views.py:228
msgid "Add a meal"
msgstr "Ajouter un plat"
#: apps/food/views.py:262
#: apps/food/views.py:259
msgid "Manage ingredients of:"
msgstr "Gestion des ingrédienrs de :"
#: apps/food/views.py:276 apps/food/views.py:284
#: apps/food/views.py:273 apps/food/views.py:281
#, python-brace-format
msgid "Fully used in {meal}"
msgstr "Aliment entièrement utilisé dans : {meal}"
#: apps/food/views.py:323
#: apps/food/views.py:320
msgid "Add the ingredient:"
msgstr "Ajouter l'ingrédient"
#: apps/food/views.py:349
#: apps/food/views.py:346
#, python-brace-format
msgid "Food fully used in : {meal.name}"
msgstr "Aliment entièrement utilisé dans : {meal.name}"
#: apps/food/views.py:368
#: apps/food/views.py:365
msgid "Update an aliment"
msgstr "Modifier un aliment"
#: apps/food/views.py:416
#: apps/food/views.py:413
msgid "Details of:"
msgstr "Détails de :"
#: apps/food/views.py:426 apps/treasury/tables.py:149
#: apps/food/views.py:423 apps/treasury/tables.py:149
msgid "Yes"
msgstr "Oui"
#: apps/food/views.py:428 apps/member/models.py:99 apps/treasury/tables.py:149
#: apps/food/views.py:425 apps/member/models.py:99 apps/treasury/tables.py:149
msgid "No"
msgstr "Non"
@ -3933,14 +3947,6 @@ msgstr "Charte Info (FR)"
msgid "FAQ (FR)"
msgstr "FAQ (FR)"
#: note_kfet/templates/base_search.html:15
msgid "Search by attribute such as name..."
msgstr "Chercher par un attribut tel que le nom..."
#: note_kfet/templates/base_search.html:23
msgid "There is no results."
msgstr "Il n'y a pas de résultat."
#: note_kfet/templates/oauth2_provider/application_confirm_delete.html:8
msgid "Are you sure to delete the application"
msgstr "Êtes-vous sûr⋅e de vouloir supprimer l'application"
@ -4161,6 +4167,11 @@ msgstr ""
"d'adhésion. Vous devez également valider votre adresse email en suivant le "
"lien que vous avez reçu."
#, fuzzy
#~| msgid "QR-code"
#~ msgid "Go to QR-code"
#~ msgstr "QR-code"
#, python-brace-format
#~ msgid "QR-code number {qr_code_number}"
#~ msgstr "Numéro du QR-code {qr_code_number}"