X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/73ce961f14509aabfa26536f847afd28111029c6..357027375ff8867f42ca34bcbfb5a78b5b185fc3:/apps/picture/forms.py?ds=sidebyside diff --git a/apps/picture/forms.py b/apps/picture/forms.py deleted file mode 100644 index 9d0c5a54b..000000000 --- a/apps/picture/forms.py +++ /dev/null @@ -1,35 +0,0 @@ -from django import forms -from django.utils.translation import ugettext_lazy as _ -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=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']: - if self.cleaned_data['picture_xml']: - self.cleaned_data['picture_xml_file'] = \ - 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): - return Picture.from_xml_file(self.cleaned_data['picture_xml_file'], image_file=self.cleaned_data['picture_image_file'], - overwrite=True, **kwargs)