You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
from django import forms |
|
from .models import Course |
|
|
|
from django.utils import timezone |
|
|
|
class CourseForm(forms.ModelForm): |
|
class Meta: |
|
model = Course |
|
fields = ['nom', 'type'] |
|
|
|
def save(self, commit=True): |
|
instance = super().save(commit=False) |
|
instance.date = timezone.localdate() |
|
# owner is set in the view prior to saving (we keep that behaviour) |
|
if commit: |
|
instance.save() |
|
return instance |
|
|
|
def clean(self): |
|
cleaned_data = super().clean() |
|
nom = cleaned_data.get('nom') |
|
date = timezone.localdate() |
|
if Course.objects.filter(nom=nom, date=date).exists(): |
|
raise forms.ValidationError("Une course avec ce nom existe déjà aujourd'hui.") |
|
return cleaned_data |
|
|
|
class DossardForm(forms.Form): |
|
rows = forms.IntegerField(label="Étiquettes par colonne", min_value=1, initial=2) |
|
cols = forms.IntegerField(label="Étiquettes par ligne", min_value=1, initial=2) |
|
|
|
class ScanForm(forms.Form): |
|
course_id = forms.IntegerField(widget=forms.HiddenInput) |
|
qrcode = forms.CharField(max_length=200)
|
|
|