X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/538526fc82b771cbc149743f129d8b1ae7e3cba2..f7323c314c42bdc6ff17ec6f3804d6acc9a481ee:/src/isbn/forms.py diff --git a/src/isbn/forms.py b/src/isbn/forms.py index 2acc34a8e..7d47fb5be 100644 --- a/src/isbn/forms.py +++ b/src/isbn/forms.py @@ -1,6 +1,9 @@ -# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from datetime import date -from urllib2 import urlopen +import json +from urllib.request import urlopen from django import forms from django.utils.translation import ugettext_lazy as _ @@ -13,8 +16,8 @@ from librarian.parser import WLDocument class WLISBNForm(forms.Form): - platform_url = forms.URLField(label=u'Adres na platformie') - publishing_date = forms.DateField(label=u'Data publikacji', initial=date.today) + platform_url = forms.URLField(label='Adres na platformie') + publishing_date = forms.DateField(label='Data publikacji', initial=date.today) def prepare_data(self): platform_url = self.cleaned_data['platform_url'] @@ -48,7 +51,7 @@ class WLConfirmForm(WLISBNForm): for file_format in data['formats']: data['product_form'] = PRODUCT_FORMS[file_format] data['product_form_detail'] = PRODUCT_FORM_DETAILS[file_format] - data['contributors'] = self.contributors(data) + data['contributors'] = json.dumps(self.contributors(data)) ONIXRecord.new_record(purpose=ISBNPool.PURPOSE_WL, data=data) return data @@ -63,20 +66,20 @@ class FNPISBNForm(forms.Form): ('SOFT', _('Soft cover book')), ) LANGUAGE_CHOICES = ( - ('pol', u'polski'), - ('eng', u'angielski'), - ('ger', u'niemiecki'), - ('fre', u'francuski'), + ('pol', 'polski'), + ('eng', 'angielski'), + ('ger', 'niemiecki'), + ('fre', 'francuski'), ) title = forms.CharField() - authors = forms.CharField(help_text=u'wartości oddzielone przecinkami lub „Wielu autorów”') + authors = forms.CharField(help_text='wartości oddzielone przecinkami lub „Wielu autorów”') formats = forms.MultipleChoiceField(choices=FORMAT_CHOICES) language = forms.ChoiceField(choices=LANGUAGE_CHOICES) publishing_date = forms.DateField() def prepare_author(self, name): - if name == u'Wielu autorów': + if name == 'Wielu autorów': return {'role': 'A01', 'unnamed': '04'} if ' ' in name: first_name, last_name = [s.strip() for s in name.rsplit(' ', 1)] @@ -93,7 +96,7 @@ class FNPISBNForm(forms.Form): 'title': self.cleaned_data['title'], 'language': self.cleaned_data['language'], 'publishing_date': self.cleaned_data['publishing_date'], - 'contributors': [self.prepare_author(a) for a in self.cleaned_data['authors'].split(',')], + 'contributors': json.dumps([self.prepare_author(a) for a in self.cleaned_data['authors'].split(',')]), 'edition_type': 'NED', 'imprint': 'Fundacja Nowoczesna Polska', 'dc_slug': self.slug(),