mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-12-24 17:42:23 +00:00
Clean code
This commit is contained in:
parent
7fd8e92371
commit
d3a4a246d9
@ -43,6 +43,7 @@ class MediaAdminForm(ModelForm):
|
||||
"&format=json&jscmd=data".format(isbn)
|
||||
with urllib.request.urlopen(api_url) as url:
|
||||
data = json.loads(url.read().decode())
|
||||
|
||||
if data and data['ISBN:' + isbn]:
|
||||
data = data['ISBN:' + isbn]
|
||||
if 'url' in data:
|
||||
@ -52,19 +53,22 @@ class MediaAdminForm(ModelForm):
|
||||
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"]
|
||||
"October", "November", "December"]
|
||||
split = data['publish_date'].replace(',', '').split(' ')
|
||||
self.cleaned_data['publish_date'] = "{}-{:02d}-{:02d}"\
|
||||
.format(split[2], months.index(split[0])+1,
|
||||
.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()
|
||||
@ -99,8 +103,8 @@ class MediaAdminForm(ModelForm):
|
||||
self.cleaned_data['title'].upper(), )
|
||||
|
||||
if self.cleaned_data['subtitle']:
|
||||
start = self.cleaned_data['subtitle'] \
|
||||
.split(' ')[0].replace('.', '')
|
||||
start = self.cleaned_data['subtitle'].split(' ')[0] \
|
||||
.replace('.', '')
|
||||
|
||||
if start.isnumeric():
|
||||
side_identifier += " {:0>2}".format(start, )
|
||||
|
Loading…
Reference in New Issue
Block a user