manuels-scolaires/manuels/forms.py

49 lines
1.8 KiB
Python
Raw Normal View History

2018-05-21 22:23:53 +02:00
from django import forms
from manuels.models import Book, SuppliesRequirement
2018-05-21 22:23:53 +02:00
class EditBookForm(forms.ModelForm):
2018-05-21 22:23:53 +02:00
class Meta:
model = Book
2018-06-04 18:24:09 +02:00
fields = ['teacher', 'level', 'field', 'no_book', 'see_later', 'title', 'authors', 'editor', 'publication_year',
'isbn', 'price', 'previously_acquired', 'comments']
no_book = forms.BooleanField(label='Pas de livre pour cette classe/matière', required=False, initial=False)
2018-06-04 18:24:09 +02:00
see_later = forms.BooleanField(
label='Voir à la rentrée', help_text="Notamment en cas de désaccord sur l'adoption ou non d'un manuel",
required=False, initial=False
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['title'].widget = forms.TextInput()
self.fields['authors'].widget = forms.TextInput()
2018-06-02 16:52:17 +02:00
self.fields['comments'].widget.attrs.update(rows=3)
class AddBookForm(EditBookForm):
class Meta(EditBookForm.Meta):
2018-06-04 18:24:09 +02:00
fields = ['teacher', 'level', 'field', 'no_book', 'see_later', 'title', 'authors', 'editor', 'publication_year',
'isbn', 'price', 'previously_acquired', 'comments', 'add_another']
2018-05-21 23:12:35 +02:00
add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True)
class EditSuppliesForm(forms.ModelForm):
class Meta:
model = SuppliesRequirement
2018-06-02 16:52:17 +02:00
fields = ['teacher', 'level', 'fields', 'supplies']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['fields'].widget.attrs.update(rows=3)
self.fields['supplies'].widget.attrs.update(rows=3)
2018-06-02 16:34:15 +02:00
class AddSuppliesForm(EditSuppliesForm):
class Meta(EditSuppliesForm.Meta):
pass
add_another = forms.BooleanField(label="Ajouter d'autres fournitures", required=False, initial=True)