mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-11-01 16:14:30 +01:00
Alpha version (without tests)
This commit is contained in:
@@ -4,15 +4,16 @@
|
||||
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.utils.translation import gettext_lazy as _
|
||||
from member.models import Club
|
||||
from note_kfet.inputs import Autocomplete
|
||||
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
|
||||
from .models import Food, BasicFood, TransformedFood, QRCode, Dish, Supplement, Order
|
||||
|
||||
|
||||
class QRCodeForms(forms.ModelForm):
|
||||
@@ -185,3 +186,60 @@ ManageIngredientsFormSet = forms.formset_factory(
|
||||
ManageIngredientsForm,
|
||||
extra=1,
|
||||
)
|
||||
|
||||
|
||||
class DishForm(forms.ModelForm):
|
||||
"""
|
||||
Form to create a dish
|
||||
"""
|
||||
class Meta:
|
||||
model = Dish
|
||||
fields = ('main', 'price', 'available')
|
||||
widgets = {
|
||||
"price": AmountInput(),
|
||||
}
|
||||
|
||||
|
||||
class SupplementForm(forms.ModelForm):
|
||||
"""
|
||||
Form to create a dish
|
||||
"""
|
||||
class Meta:
|
||||
model = Supplement
|
||||
fields = '__all__'
|
||||
widgets = {
|
||||
"price": AmountInput(),
|
||||
}
|
||||
|
||||
|
||||
# The 2 following classes are copied from treasury app
|
||||
# Add a subform per supplement in the dish form, and manage correctly the link between the dish and
|
||||
# its supplements. The FormSet will search automatically the ForeignKey in the Supplement model.
|
||||
SupplementFormSet = forms.inlineformset_factory(
|
||||
Dish,
|
||||
Supplement,
|
||||
form=SupplementForm,
|
||||
extra=0,
|
||||
)
|
||||
|
||||
|
||||
class SupplementFormSetHelper(FormHelper):
|
||||
"""
|
||||
Specify some template information for the supplement form
|
||||
"""
|
||||
|
||||
def __init__(self, form=None):
|
||||
super().__init__(form)
|
||||
self.form_tag = False
|
||||
self.form_method = 'POST'
|
||||
self.form_class = 'form-inline'
|
||||
self.template = 'bootstrap4/table_inline_formset.html'
|
||||
|
||||
|
||||
class OrderForm(forms.ModelForm):
|
||||
"""
|
||||
Form to order food
|
||||
"""
|
||||
class Meta:
|
||||
model = Order
|
||||
exclude = ("activity", "number", "ordered_at", "served", "served_at")
|
||||
|
||||
Reference in New Issue
Block a user