From aa9b69f2d671358acc78f2cc9c5ba9b578745974 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 12 May 2020 14:56:31 +0200 Subject: [PATCH] Fix openlibrary scrap, fix linters --- med/settings.py | 2 +- media/forms.py | 29 +++++++++++++++++++++++++---- media/validators.py | 3 +-- requirements.txt | 4 ++-- tox.ini | 6 +++--- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/med/settings.py b/med/settings.py index fb11d68..7e79e27 100644 --- a/med/settings.py +++ b/med/settings.py @@ -65,7 +65,7 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.sites.middleware.CurrentSiteMiddleware', - 'cas.middleware.CASMiddleware', + # 'cas.middleware.CASMiddleware', ] AUTHENTICATION_BACKENDS = ( diff --git a/media/forms.py b/media/forms.py index 341cdf5..fd02718 100644 --- a/media/forms.py +++ b/media/forms.py @@ -54,6 +54,7 @@ class MediaAdminForm(ModelForm): return False def parse_data_openlibrary(self, data): + print(data) self.cleaned_data['external_url'] = data['url'] if 'title' in data: self.cleaned_data['title'] = data['title'] @@ -74,9 +75,28 @@ class MediaAdminForm(ModelForm): if len(split) == 1: self.cleaned_data['publish_date'] = split[0] + "-01-01" else: - self.cleaned_data['publish_date'] = "{}-{:02d}-{:02d}" \ - .format(split[2], months.index(split[0]) + 1, - int(split[1]), ) + month_to_number = dict( + Jan="01", + Feb="02", + Mar="03", + Apr="04", + May="05", + Jun="06", + Jul="07", + Aug="08", + Sep="09", + Oct="10", + Nov="11", + Dec="12", + ) + if split[0] in month_to_number: + self.cleaned_data['publish_date']\ + = split[2] + "-" \ + + month_to_number[split[0]] + "-" + split[1] + else: + self.cleaned_data['publish_date'] = "{}-{:02d}-{:02d}" \ + .format(split[2], months.index(split[0]) + + 1, int(split[1]), ) if 'authors' in data: if 'author' not in self.cleaned_data: @@ -92,7 +112,8 @@ class MediaAdminForm(ModelForm): """ super().clean() - if "_isbn" in self.request.POST or "_isbn_addanother" in self.request.POST: + if "_isbn" in self.request.POST\ + or "_isbn_addanother" in self.request.POST: isbn = self.cleaned_data.get('isbn') if "_isbn_addanother" in self.request.POST: self.request.POST = self.request.POST.copy() diff --git a/media/validators.py b/media/validators.py index 151c90f..3d7af51 100644 --- a/media/validators.py +++ b/media/validators.py @@ -8,7 +8,6 @@ Based on https://github.com/secnot/django-isbn-field from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ -from stdnum import isbn def isbn_validator(raw_isbn): @@ -21,7 +20,7 @@ def isbn_validator(raw_isbn): if len(isbn_to_check) != 10 and len(isbn_to_check) != 13: raise ValidationError(_('Invalid ISBN: Wrong length')) - #if not isbn.is_valid(isbn_to_check): + # if not isbn.is_valid(isbn_to_check): # raise ValidationError(_('Invalid ISBN: Failed checksum')) if isbn_to_check != isbn_to_check.upper(): diff --git a/requirements.txt b/requirements.txt index 22d851f..73c63c8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,11 +4,11 @@ Pillow==5.4.1 pytz==2019.1 six==1.12.0 sqlparse==0.2.4 +django-cas-client==1.5.3 django-reversion==3.0.3 python-stdnum==1.10 djangorestframework==3.9.2 pyyaml==3.13 coreapi==2.3.3 -psycopg2==2.7.7 +psycopg2-binary uwsgi==2.0.18 -mysqlclient==1.4.3 diff --git a/tox.ini b/tox.ini index a512056..ebc489d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35,py36,py37,linters +envlist = py35,py36,py37,py38,linters skipsdist = True [testenv] @@ -28,11 +28,11 @@ deps = pyflakes pylint commands = - flake8 logs media search users + flake8 logs media users pylint . [flake8] -ignore = D203, W503, E203, I100, I201, I202 +ignore = D203, W503, E203, I100, I201, I202, C901 exclude = .tox, .git,