mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-11-08 15:59:50 +01:00
Add model Recipe
This commit is contained in:
@@ -6,14 +6,15 @@ from random import shuffle
|
||||
from bootstrap_datepicker_plus.widgets import DateTimePickerInput
|
||||
from crispy_forms.helper import FormHelper
|
||||
from django import forms
|
||||
from django.forms.widgets import NumberInput
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.forms.widgets import NumberInput, TextInput
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from member.models import Club
|
||||
from note_kfet.inputs import Autocomplete, AmountInput
|
||||
from note_kfet.middlewares import get_current_request
|
||||
from permission.backends import PermissionBackend
|
||||
|
||||
from .models import Food, BasicFood, TransformedFood, QRCode, Dish, Supplement, Order
|
||||
from .models import Food, BasicFood, TransformedFood, QRCode, Dish, Supplement, Order, Recipe
|
||||
|
||||
|
||||
class QRCodeForms(forms.ModelForm):
|
||||
@@ -134,7 +135,7 @@ class AddIngredientForms(forms.ModelForm):
|
||||
Form for add an ingredient
|
||||
"""
|
||||
fully_used = forms.BooleanField()
|
||||
fully_used.initial = True
|
||||
fully_used.initial = False
|
||||
fully_used.required = False
|
||||
fully_used.label = _("Fully used")
|
||||
|
||||
@@ -142,11 +143,14 @@ class AddIngredientForms(forms.ModelForm):
|
||||
super().__init__(*args, **kwargs)
|
||||
# TODO find a better way to get pk (be not url scheme dependant)
|
||||
pk = get_current_request().path.split('/')[-1]
|
||||
self.fields['ingredients'].queryset = self.fields['ingredients'].queryset.filter(
|
||||
qs = self.fields['ingredients'].queryset.filter(
|
||||
polymorphic_ctype__model="transformedfood",
|
||||
is_ready=False,
|
||||
end_of_life='',
|
||||
).filter(PermissionBackend.filter_queryset(get_current_request(), Food, "change")).exclude(pk=pk)
|
||||
).filter(PermissionBackend.filter_queryset(get_current_request(), Food, "change"))
|
||||
if pk:
|
||||
qs = qs.exclude(pk=pk)
|
||||
self.fields['ingredients'].queryset = qs
|
||||
|
||||
class Meta:
|
||||
model = TransformedFood
|
||||
@@ -158,7 +162,7 @@ class ManageIngredientsForm(forms.Form):
|
||||
Form to manage ingredient
|
||||
"""
|
||||
fully_used = forms.BooleanField()
|
||||
fully_used.initial = True
|
||||
fully_used.initial = False
|
||||
fully_used.required = True
|
||||
fully_used.label = _('Fully used')
|
||||
|
||||
@@ -248,3 +252,43 @@ class OrderForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Order
|
||||
exclude = ("activity", "number", "ordered_at", "served", "served_at")
|
||||
|
||||
|
||||
class RecipeForm(forms.ModelForm):
|
||||
"""
|
||||
Form to create a recipe
|
||||
"""
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name',)
|
||||
|
||||
|
||||
class RecipeIngredientsForm(forms.Form):
|
||||
"""
|
||||
Form to add ingredients to a recipe
|
||||
"""
|
||||
name = forms.CharField()
|
||||
name.widget = TextInput()
|
||||
name.label = _("Name")
|
||||
|
||||
|
||||
RecipeIngredientsFormSet = forms.formset_factory(
|
||||
RecipeIngredientsForm,
|
||||
extra=1,
|
||||
)
|
||||
|
||||
|
||||
class UseRecipeForm(forms.Form):
|
||||
"""
|
||||
Form to add ingredients to a TransformedFood using a Recipe
|
||||
"""
|
||||
recipe = forms.ModelChoiceField(
|
||||
queryset=Recipe.objects,
|
||||
label=_('Recipe'),
|
||||
)
|
||||
|
||||
ingredients = forms.ModelMultipleChoiceField(
|
||||
queryset=Food.objects,
|
||||
label=_("Ingredients"),
|
||||
widget=CheckboxSelectMultiple(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user