Fix openlibrary scrap, fix linters

This commit is contained in:
Yohann D'ANELLO 2020-05-12 14:56:31 +02:00
parent 8e39f6039e
commit aa9b69f2d6
5 changed files with 32 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

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