1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-11-27 01:27:10 +00:00

Required fields are not checked when the ISBN is typed

This commit is contained in:
Yohann D'ANELLO 2020-02-10 03:08:08 +01:00
parent a52c9f5cb3
commit 552d2b8f0e

View File

@ -60,6 +60,8 @@ class MediaAdminForm(ModelForm):
""" """
If user fetch ISBN data, then download data before validating the form If user fetch ISBN data, then download data before validating the form
""" """
super().clean()
# TODO implement authors, side_identifier # TODO implement authors, side_identifier
if "_continue" in self.request.POST: if "_continue" in self.request.POST:
isbn = self.cleaned_data.get('isbn') isbn = self.cleaned_data.get('isbn')
@ -70,4 +72,25 @@ class MediaAdminForm(ModelForm):
# Try with OpenLibrary # Try with OpenLibrary
self.download_data_openlibrary(isbn) self.download_data_openlibrary(isbn)
return super().clean() return self.cleaned_data
def _clean_fields(self):
for name, field in self.fields.items():
# value_from_datadict() gets the data from the data dictionaries.
# Each widget type knows how to retrieve its own data, because some
# widgets split data over several HTML fields.
if field.disabled:
value = self.get_initial_for_field(field, name)
else:
value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
from django.core.exceptions import ValidationError
try:
# We don't want to check a field when we enter an ISBN.
if "_continue" not in self.request.POST or not self.cleaned_data.get('isbn'):
value = field.clean(value)
self.cleaned_data[name] = value
if hasattr(self, 'clean_%s' % name):
value = getattr(self, 'clean_%s' % name)()
self.cleaned_data[name] = value
except ValidationError as e:
self.add_error(name, e)