Less complexity for download_data_openlibrary
This commit is contained in:
parent
778e3239a4
commit
939efe01a0
|
@ -11,21 +11,19 @@ sleep 2
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
python manage.py collectstatic --no-input
|
python manage.py collectstatic --no-input
|
||||||
|
|
||||||
python manage.py runserver 0.0.0.0:8000
|
|
||||||
|
|
||||||
# harakiri parameter respawns processes taking more than 20 seconds
|
# harakiri parameter respawns processes taking more than 20 seconds
|
||||||
# max-requests parameter respawns processes after serving 5000 requests
|
# max-requests parameter respawns processes after serving 5000 requests
|
||||||
# vacuum parameter cleans up when stopped
|
# vacuum parameter cleans up when stopped
|
||||||
#uwsgi --chdir="$(pwd)" \
|
uwsgi --chdir="$(pwd)" \
|
||||||
# --module=med.wsgi:application \
|
--module=med.wsgi:application \
|
||||||
# --env DJANGO_SETTINGS_MODULE=med.settings \
|
--env DJANGO_SETTINGS_MODULE=med.settings \
|
||||||
# --master \
|
--master \
|
||||||
# --pidfile="$(pwd)/uwsgi.pid" \
|
--pidfile="$(pwd)/uwsgi.pid" \
|
||||||
# --socket="$(pwd)/uwsgi.sock" \
|
--socket="$(pwd)/uwsgi.sock" \
|
||||||
# --processes=5 \
|
--processes=5 \
|
||||||
# --chmod-socket=600 \
|
--chmod-socket=600 \
|
||||||
# --harakiri=20 \
|
--harakiri=20 \
|
||||||
# --max-requests=5000 \
|
--max-requests=5000 \
|
||||||
# --vacuum \
|
--vacuum \
|
||||||
# --daemonize="$(pwd)/uwsgi.log" \
|
--daemonize="$(pwd)/uwsgi.log" \
|
||||||
# --protocol=fastcgi
|
--protocol=fastcgi
|
|
@ -48,37 +48,40 @@ class MediaAdminForm(ModelForm):
|
||||||
data = data['ISBN:' + isbn]
|
data = data['ISBN:' + isbn]
|
||||||
if 'url' in data:
|
if 'url' in data:
|
||||||
# Fill the data
|
# Fill the data
|
||||||
self.cleaned_data['external_url'] = data['url']
|
self.parse_data_openlibrary(data)
|
||||||
if 'title' in data:
|
|
||||||
self.cleaned_data['title'] = data['title']
|
|
||||||
if 'subtitle' in data:
|
|
||||||
self.cleaned_data['subtitle'] = data['subtitle']
|
|
||||||
|
|
||||||
if 'number_of_pages' in data:
|
|
||||||
self.cleaned_data['number_of_pages'] = \
|
|
||||||
data['number_of_pages']
|
|
||||||
elif not self.cleaned_data['number_of_pages']:
|
|
||||||
self.cleaned_data['number_of_pages'] = 0
|
|
||||||
|
|
||||||
if 'publish_date' in data:
|
|
||||||
months = ['January', 'February', "March", "April", "Mai",
|
|
||||||
"June", "July", "August", "September",
|
|
||||||
"October", "November", "December"]
|
|
||||||
split = data['publish_date'].replace(',', '').split(' ')
|
|
||||||
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:
|
|
||||||
self.cleaned_data['authors'] = list()
|
|
||||||
for author in data['authors']:
|
|
||||||
author_obj = Auteur.objects.get_or_create(
|
|
||||||
name=author['name'])[0]
|
|
||||||
self.cleaned_data['authors'].append(author_obj)
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def parse_data_openlibrary(self, data):
|
||||||
|
self.cleaned_data['external_url'] = data['url']
|
||||||
|
if 'title' in data:
|
||||||
|
self.cleaned_data['title'] = data['title']
|
||||||
|
if 'subtitle' in data:
|
||||||
|
self.cleaned_data['subtitle'] = data['subtitle']
|
||||||
|
|
||||||
|
if 'number_of_pages' in data:
|
||||||
|
self.cleaned_data['number_of_pages'] = \
|
||||||
|
data['number_of_pages']
|
||||||
|
elif not self.cleaned_data['number_of_pages']:
|
||||||
|
self.cleaned_data['number_of_pages'] = 0
|
||||||
|
|
||||||
|
if 'publish_date' in data:
|
||||||
|
months = ['January', 'February', "March", "April", "Mai",
|
||||||
|
"June", "July", "August", "September",
|
||||||
|
"October", "November", "December"]
|
||||||
|
split = data['publish_date'].replace(',', '').split(' ')
|
||||||
|
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:
|
||||||
|
self.cleaned_data['authors'] = list()
|
||||||
|
for author in data['authors']:
|
||||||
|
author_obj = Auteur.objects.get_or_create(
|
||||||
|
name=author['name'])[0]
|
||||||
|
self.cleaned_data['authors'].append(author_obj)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""
|
"""
|
||||||
If user fetch ISBN data, then download data before validating the form
|
If user fetch ISBN data, then download data before validating the form
|
||||||
|
|
|
@ -9,6 +9,6 @@ python-stdnum==1.10
|
||||||
djangorestframework==3.9.2
|
djangorestframework==3.9.2
|
||||||
pyyaml==3.13
|
pyyaml==3.13
|
||||||
coreapi==2.3.3
|
coreapi==2.3.3
|
||||||
psycopg2
|
psycopg2==2.7.7
|
||||||
uwsgi==2.0.18
|
uwsgi==2.0.18
|
||||||
mysqlclient==1.4.3
|
mysqlclient==1.4.3
|
||||||
|
|
Loading…
Reference in New Issue