mirror of https://gitlab.crans.org/bde/nk20
68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
# Copyright (C) 2018-2022 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
from crispy_forms.helper import FormHelper
|
|
from django import forms
|
|
|
|
from member.models import Club
|
|
from note_kfet.inputs import AmountInput, Autocomplete, DateTimePickerInput
|
|
|
|
from .models import Food, FoodOption, Meal, Sheet
|
|
|
|
|
|
class SheetForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Sheet
|
|
fields = '__all__'
|
|
widgets = {
|
|
'date': DateTimePickerInput(),
|
|
}
|
|
|
|
|
|
class FoodForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Food
|
|
exclude = ('sheet', )
|
|
widgets = {
|
|
'price': AmountInput(),
|
|
'club': Autocomplete(
|
|
model=Club,
|
|
attrs={"api_url": "/api/members/club/"},
|
|
),
|
|
}
|
|
|
|
|
|
class FoodOptionForm(forms.ModelForm):
|
|
class Meta:
|
|
model = FoodOption
|
|
fields = '__all__'
|
|
widgets = {
|
|
'extra_cost': AmountInput(),
|
|
}
|
|
|
|
|
|
FoodOptionsFormSet = forms.inlineformset_factory(
|
|
Food,
|
|
FoodOption,
|
|
form=FoodOptionForm,
|
|
extra=0,
|
|
)
|
|
|
|
|
|
class FoodOptionFormSetHelper(FormHelper):
|
|
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 MealForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Meal
|
|
exclude = ('sheet', )
|
|
widgets = {
|
|
'content': forms.CheckboxSelectMultiple(),
|
|
'price': AmountInput(),
|
|
}
|