mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-04-29 01:52:38 +00:00
Merge branch 'food_traceability' into 'main'
fix bug See merge request bde/nk20!309
This commit is contained in:
commit
c4404ef995
@ -52,7 +52,7 @@
|
||||
"model": "food.allergen",
|
||||
"pk": 8,
|
||||
"fields": {
|
||||
"name": "Céléri"
|
||||
"name": "Céleri"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ from django_tables2.views import MultiTableMixin
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.generic import DetailView, UpdateView
|
||||
from django.views.generic import DetailView, UpdateView, CreateView
|
||||
from django.views.generic.list import ListView
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
@ -106,7 +106,7 @@ class FoodListView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, Li
|
||||
return context
|
||||
|
||||
|
||||
class QRCodeCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
class QRCodeCreateView(ProtectQuerysetMixin, CreateView):
|
||||
"""
|
||||
A view to add qrcode
|
||||
"""
|
||||
@ -260,6 +260,8 @@ class AddIngredientView(ProtectQuerysetMixin, UpdateView):
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
meals = TransformedFood.objects.filter(pk__in=form.data.getlist('ingredients')).all()
|
||||
if not meals:
|
||||
return HttpResponseRedirect(reverse_lazy('food:food_view', kwargs={"pk": self.object.pk}))
|
||||
for meal in meals:
|
||||
old_ingredients = list(meal.ingredients.all()).copy()
|
||||
old_allergens = list(meal.allergens.all()).copy()
|
||||
@ -385,6 +387,7 @@ class BasicFoodDetailView(FoodDetailView):
|
||||
return context
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
if Food.objects.filter(pk=kwargs['pk']).count() == 1:
|
||||
kwargs['stop_redirect'] = (Food.objects.get(pk=kwargs['pk']).polymorphic_ctype.model == 'basicfood')
|
||||
return super().get(*args, **kwargs)
|
||||
|
||||
@ -404,5 +407,6 @@ class TransformedFoodDetailView(FoodDetailView):
|
||||
return context
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user