3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-10-05 19:12:09 +00:00

Divide keg forms

This commit is contained in:
Yoann Pétri 2019-08-29 12:45:30 +02:00
parent 03b07cad95
commit 2718884b77
2 changed files with 23 additions and 8 deletions

View file

@ -42,9 +42,9 @@ class ProductForm(forms.ModelForm):
fields = "__all__" fields = "__all__"
widgets = {'amount': forms.TextInput} widgets = {'amount': forms.TextInput}
class KegForm(forms.ModelForm): class CreateKegForm(forms.ModelForm):
""" """
A form to create and edit a :class:`~gestion.models.Keg`. A form to create a :class:`~gestion.models.Keg`.
""" """
class Meta: class Meta:
@ -52,7 +52,7 @@ class KegForm(forms.ModelForm):
fields = ["name", "stockHold", "amount", "capacity"] fields = ["name", "stockHold", "amount", "capacity"]
widgets = {'amount': forms.TextInput} widgets = {'amount': forms.TextInput}
category = forms.ModelChoiceField(queryset=Category.objects.all(), label="Catégorie") category = forms.ModelChoiceField(queryset=Category.objects.all(), label="Catégorie", help_text="Catégorie dans laquelle placer les produits pinte, demi (et galopin si besoin).")
deg = forms.DecimalField(max_digits=5, decimal_places=2, label="Degré", validators=[MinValueValidator(0)]) deg = forms.DecimalField(max_digits=5, decimal_places=2, label="Degré", validators=[MinValueValidator(0)])
create_galopin = forms.BooleanField(required=False, label="Créer le produit galopin ?") create_galopin = forms.BooleanField(required=False, label="Créer le produit galopin ?")
@ -61,6 +61,21 @@ class KegForm(forms.ModelForm):
if cleaned_data.get("name")[0:4] != "Fût ": if cleaned_data.get("name")[0:4] != "Fût ":
raise ValidationError("Le nom du fût doit être sous la forme 'Fût nom de la bière'") raise ValidationError("Le nom du fût doit être sous la forme 'Fût nom de la bière'")
class EditKegForm(forms.ModelForm):
"""
A form to edit a :class:`~gestion.models.Keg`.
"""
class Meta:
model = Keg
fields = ["name", "stockHold", "amount", "capacity", "pinte", "demi", "galopin"]
widgets = {'amount': forms.TextInput}
def clean(self):
cleaned_data = super().clean()
if cleaned_data.get("name")[0:4] != "Fût ":
raise ValidationError("Le nom du fût doit être sous la forme 'Fût nom de la bière'")
class MenuForm(forms.ModelForm): class MenuForm(forms.ModelForm):
""" """
A form to create and edit a :class:`~gestion.models.Menu`. A form to create and edit a :class:`~gestion.models.Menu`.

View file

@ -22,7 +22,7 @@ from decimal import *
import os import os
from math import floor, ceil from math import floor, ceil
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm, CategoryForm, SearchCategoryForm, GenerateInvoiceForm, ComputePriceForm from .forms import ReloadForm, RefundForm, ProductForm, CreateKegForm, EditKegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm, CategoryForm, SearchCategoryForm, GenerateInvoiceForm, ComputePriceForm
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund, Category from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund, Category
from users.models import School from users.models import School
from preferences.models import PaymentMethod, GeneralPreferences, Cotisation, DivideHistory, PriceProfile from preferences.models import PaymentMethod, GeneralPreferences, Cotisation, DivideHistory, PriceProfile
@ -515,9 +515,9 @@ def stocks(request):
@permission_required('gestion.add_keg') @permission_required('gestion.add_keg')
def addKeg(request): def addKeg(request):
""" """
Displays a :class:`gestion.forms.KegForm` to add a :class:`gestion.models.Keg`. Displays a :class:`gestion.forms.CreateKegForm` to add a :class:`gestion.models.Keg`.
""" """
form = KegForm(request.POST or None) form = CreateKegForm(request.POST or None)
if form.is_valid(): if form.is_valid():
try: try:
price_profile = PriceProfile.objects.get(use_for_draft=True) price_profile = PriceProfile.objects.get(use_for_draft=True)
@ -588,13 +588,13 @@ def addKeg(request):
@permission_required('gestion.change_keg') @permission_required('gestion.change_keg')
def editKeg(request, pk): def editKeg(request, pk):
""" """
Displays a :class:`gestion.forms.KegForm` to edit a :class:`gestion.models.Keg`. Displays a :class:`gestion.forms.EditKegForm` to edit a :class:`gestion.models.Keg`.
pk pk
The primary key of the :class:`gestion.models.Keg` to edit. The primary key of the :class:`gestion.models.Keg` to edit.
""" """
keg = get_object_or_404(Keg, pk=pk) keg = get_object_or_404(Keg, pk=pk)
form = KegForm(request.POST or None, instance=keg) form = EditKegForm(request.POST or None, instance=keg)
if(form.is_valid()): if(form.is_valid()):
form.save() form.save()
messages.success(request, "Le fût a bien été modifié") messages.success(request, "Le fût a bien été modifié")