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
pull/1/head
eric 2014-08-06 10:59:16 -04:00
parent e9ddbf98c0
commit 8f3957dc14
3 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -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:

View File

@ -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: