From 8f3957dc14e29c0b32ef7e176c12f3922deba0e3 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 6 Aug 2014 10:59:16 -0400 Subject: [PATCH] allow blank ISBN version in production throws invalid isbn exception made sure you can't delete an id if the edition is left id-les fixed bug where using an existing id omits admin setting --- frontend/forms.py | 6 +++++- frontend/views.py | 2 +- utils/fields.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/forms.py b/frontend/forms.py index e91432c1..277e4a53 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -67,6 +67,7 @@ from regluit.mobi import Mobi from regluit.pyepub import EPUB logger = logging.getLogger(__name__) +nulls = [False, 'delete', ''] class EditionForm(forms.ModelForm): add_author = forms.CharField(max_length=500, required=False) @@ -132,7 +133,10 @@ class EditionForm(forms.ModelForm): coverfile = forms.ImageField(required=False) def clean(self): - if not self.cleaned_data.get("isbn",False) and not self.cleaned_data.get("oclc",False) and not self.cleaned_data.get("goog",False): + has_isbn = self.cleaned_data.get("isbn", False) not in nulls + has_oclc = self.cleaned_data.get("oclc", False) not in nulls + has_goog = self.cleaned_data.get("goog", False) not in nulls + if not has_isbn and not has_oclc and not has_goog: raise forms.ValidationError(_("There must be either an ISBN or an OCLC number.")) return self.cleaned_data diff --git a/frontend/views.py b/frontend/views.py index 51d522d8..389fc303 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -595,7 +595,7 @@ def new_edition(request, work_id, edition_id, by=None): existing= models.Identifier.objects.filter(type=id_type, value=form.cleaned_data[id_type]) if existing.count() and existing[0].edition != edition: return render(request, 'new_edition.html', { - 'form': form, 'edition': edition, + 'form': form, 'edition': edition, 'admin': admin, 'id_msg': "%s = %s already exists"%( id_type, id_val ), }) else: diff --git a/utils/fields.py b/utils/fields.py index e2b7b929..33b27c0e 100644 --- a/utils/fields.py +++ b/utils/fields.py @@ -17,7 +17,9 @@ class EpubFileField(forms.FileField): class ISBNField(forms.CharField): def to_python(self, value): value=super(ISBNField,self).to_python(value) - if value == 'delete': + if not value: + return '' + elif value == 'delete': return value self.isbn=ISBN(value) if self.isbn.error: