From 128b8c2f4853130eb85a40f2436fb9e62ca8b0f3 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 1 Feb 2018 15:19:06 -0500 Subject: [PATCH] url not guaranteed to be cleaned before provider --- frontend/forms/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/forms/__init__.py b/frontend/forms/__init__.py index 76479790..b563b279 100644 --- a/frontend/forms/__init__.py +++ b/frontend/forms/__init__.py @@ -154,12 +154,12 @@ class EbookForm(forms.ModelForm): new_label = self.data.get('new_version_label','') return new_label if new_label else self.cleaned_data['version_label'] - def clean_provider(self): + def set_provider(self): url = self.cleaned_data['url'] new_provider = Ebook.infer_provider(url) if url and not new_provider: raise forms.ValidationError(_("At this time, ebook URLs must point at Internet Archive, Wikisources, Wikibooks, Hathitrust, Project Gutenberg, raw files at Github, Google Books, or OApen.")) - return new_provider if new_provider else "Unglue.it" + self.cleaned_data['provider'] = new_provider if new_provider else "Unglue.it" def clean_url(self): url = self.cleaned_data['url'] @@ -170,6 +170,7 @@ class EbookForm(forms.ModelForm): raise forms.ValidationError(_("There's already an ebook with that url.")) def clean(self): + self.set_provider() format = self.cleaned_data.get('format', '') the_file = self.cleaned_data.get('file', None) url = self.cleaned_data.get('url', None)