X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/f59e7c3de6bd0f85a61a4d9481db60cd7369ae92..062a80b51a89bf2361930461c0ad7ae5e36a2bdd:/apps/picture/forms.py?ds=sidebyside diff --git a/apps/picture/forms.py b/apps/picture/forms.py index ad5096bf5..2ad47b0b8 100644 --- a/apps/picture/forms.py +++ b/apps/picture/forms.py @@ -1,3 +1,7 @@ +# -*- 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 django import forms from django.utils.translation import ugettext_lazy as _ from picture.models import Picture @@ -6,9 +10,11 @@ from picture.models import Picture class PictureImportForm(forms.Form): picture_xml_file = forms.FileField(required=False) picture_xml = forms.CharField(required=False) - picture_image_file = forms.FileField(required=True) + picture_image_file = forms.FileField(required=False) + picture_image_data = forms.CharField(required=False) def clean(self): + from base64 import b64decode from django.core.files.base import ContentFile if not self.cleaned_data['picture_xml_file']: @@ -17,6 +23,15 @@ class PictureImportForm(forms.Form): ContentFile(self.cleaned_data['picture_xml'].encode('utf-8')) else: raise forms.ValidationError(_("Please supply an XML.")) + + if not self.cleaned_data['picture_image_file']: + if self.cleaned_data['picture_image_data']: + self.cleaned_data['picture_image_file'] = \ + ContentFile(b64decode( + self.cleaned_data['picture_image_data'])) + else: + raise forms.ValidationError(_("Please supply an image.")) + return super(PictureImportForm, self).clean() def save(self, commit=True, **kwargs):