mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-15 06:17:37 +02:00
Compare commits
1 Commits
5184071702
...
5a7dadbe5d
Author | SHA1 | Date | |
---|---|---|---|
|
5a7dadbe5d |
@ -168,8 +168,7 @@ class BasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
template_name = "food/food_update.html"
|
template_name = "food/food_update.html"
|
||||||
|
|
||||||
def get_sample_object(self):
|
def get_sample_object(self):
|
||||||
# We choose a club which may work or BDE else
|
return BasicFood(
|
||||||
food = BasicFood(
|
|
||||||
name="",
|
name="",
|
||||||
owner_id=1,
|
owner_id=1,
|
||||||
expiry_date=timezone.now(),
|
expiry_date=timezone.now(),
|
||||||
@ -178,14 +177,6 @@ class BasicFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
date_type='DLC',
|
date_type='DLC',
|
||||||
)
|
)
|
||||||
|
|
||||||
for membership in self.request.user.memberships.all():
|
|
||||||
club_id = membership.club.id
|
|
||||||
food.owner_id = club_id
|
|
||||||
if PermissionBackend.check_perm(self.request, "food.add_basicfood", food):
|
|
||||||
return food
|
|
||||||
|
|
||||||
return food
|
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
if QRCode.objects.filter(qr_code_number=self.kwargs['slug']).count() > 0:
|
if QRCode.objects.filter(qr_code_number=self.kwargs['slug']).count() > 0:
|
||||||
@ -236,22 +227,13 @@ class TransformedFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
template_name = "food/food_update.html"
|
template_name = "food/food_update.html"
|
||||||
|
|
||||||
def get_sample_object(self):
|
def get_sample_object(self):
|
||||||
# We choose a club which may work or BDE else
|
return TransformedFood(
|
||||||
food = TransformedFood(
|
|
||||||
name="",
|
name="",
|
||||||
owner_id=1,
|
owner_id=1,
|
||||||
expiry_date=timezone.now(),
|
expiry_date=timezone.now(),
|
||||||
is_ready=True,
|
is_ready=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
for membership in self.request.user.memberships.all():
|
|
||||||
club_id = membership.club.id
|
|
||||||
food.owner_id = club_id
|
|
||||||
if PermissionBackend.check_perm(self.request, "food.add_transformedfood", food):
|
|
||||||
return food
|
|
||||||
|
|
||||||
return food
|
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.expiry_date = timezone.now() + timedelta(days=3)
|
form.instance.expiry_date = timezone.now() + timedelta(days=3)
|
||||||
@ -266,7 +248,7 @@ class TransformedFoodCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|||||||
MAX_FORMS = 10
|
MAX_FORMS = 10
|
||||||
|
|
||||||
|
|
||||||
class ManageIngredientsView(LoginRequiredMixin, UpdateView):
|
class ManageIngredientsView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
A view to manage ingredient for a transformed food
|
A view to manage ingredient for a transformed food
|
||||||
"""
|
"""
|
||||||
@ -297,14 +279,6 @@ class ManageIngredientsView(LoginRequiredMixin, UpdateView):
|
|||||||
ingredient.end_of_life = _('Fully used in {meal}'.format(
|
ingredient.end_of_life = _('Fully used in {meal}'.format(
|
||||||
meal=self.object.name))
|
meal=self.object.name))
|
||||||
ingredient.save()
|
ingredient.save()
|
||||||
# We recalculate new expiry date and allergens
|
|
||||||
self.object.expiry_date = self.object.creation_date + self.object.shelf_life
|
|
||||||
self.object.allergens.clear()
|
|
||||||
|
|
||||||
for ingredient in self.object.ingredients.iterator():
|
|
||||||
if not (ingredient.polymorphic_ctype.model == 'basicfood' and ingredient.date_type == 'DDM'):
|
|
||||||
self.object.expiry_date = min(self.object.expiry_date, ingredient.expiry_date)
|
|
||||||
self.object.allergens.set(self.object.allergens.union(ingredient.allergens.all()))
|
|
||||||
|
|
||||||
self.object.save(old_ingredients=old_ingredients, old_allergens=old_allergens)
|
self.object.save(old_ingredients=old_ingredients, old_allergens=old_allergens)
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user