Default to no choice for previously acquired. Close #32
This commit is contained in:
parent
99d0f8b6c5
commit
d98ac17eae
3 changed files with 13 additions and 1 deletions
|
@ -44,6 +44,13 @@ class EditBookForm(forms.ModelForm):
|
|||
)
|
||||
)
|
||||
|
||||
def clean_previously_acquired(self):
|
||||
data = self.cleaned_data['previously_acquired']
|
||||
if data is None or data == '':
|
||||
raise ValidationError('Vous devez choisir une valeur')
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class AddBookForm(EditBookForm):
|
||||
class Meta(EditBookForm.Meta):
|
||||
|
|
|
@ -164,6 +164,7 @@ class Book(BaseModel):
|
|||
)
|
||||
price = models.FloatField('prix', validators=[positive_float_validator])
|
||||
YES_NO_CHOICE = (
|
||||
(None, '------------'),
|
||||
(False, 'Non'),
|
||||
(True, 'Oui'),
|
||||
)
|
||||
|
@ -171,7 +172,7 @@ class Book(BaseModel):
|
|||
"manuel acquis précédemment par l'élève",
|
||||
choices=YES_NO_CHOICE,
|
||||
blank=False,
|
||||
default=False,
|
||||
default=None,
|
||||
)
|
||||
done = models.BooleanField(
|
||||
'Traité',
|
||||
|
|
|
@ -19,6 +19,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
|
|||
isbn: document.querySelector('#id_isbn').value,
|
||||
price: document.querySelector('#id_price').value,
|
||||
editor: document.querySelector('#id_editor').value,
|
||||
previouslyAcquired: document.querySelector('#id_previously_acquired').value,
|
||||
};
|
||||
_selector.addEventListener('change', function (event) {
|
||||
if (_selector.checked) {
|
||||
|
@ -29,12 +30,14 @@ document.addEventListener("DOMContentLoaded", function (event) {
|
|||
isbn: document.querySelector('#id_isbn').value,
|
||||
price: document.querySelector('#id_price').value,
|
||||
editor: document.querySelector('#id_editor').value,
|
||||
previouslyAcquired: document.querySelector('#id_previously_acquired').value,
|
||||
};
|
||||
document.querySelector('#id_title').value = selector.value;
|
||||
document.querySelector('#id_authors').value = "N/A";
|
||||
document.querySelector('#id_publication_year').value = 1900;
|
||||
document.querySelector('#id_isbn').value = "0000000000";
|
||||
document.querySelector('#id_price').value = 0;
|
||||
document.querySelector('#id_previously_acquired').value = "False";
|
||||
var editorValue = null;
|
||||
for (var option of document.querySelector('#id_editor').children) {
|
||||
if (editorValue === null && option.value !== "") {
|
||||
|
@ -52,6 +55,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
|
|||
document.querySelector('#id_publication_year').value = data.publicationYear;
|
||||
document.querySelector('#id_isbn').value = data.isbn;
|
||||
document.querySelector('#id_price').value = data.price;
|
||||
document.querySelector('#id_previously_acquired').value = data.previouslyAcquired;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue