1 from django import forms
2 from django.utils.translation import ugettext_lazy as _
3 from picture.models import Picture
6 class PictureImportForm(forms.Form):
7 picture_xml_file = forms.FileField(required=False)
8 picture_xml = forms.CharField(required=False)
9 picture_image_file = forms.FileField(required=True)
12 from django.core.files.base import ContentFile
14 if not self.cleaned_data['picture_xml_file']:
15 if self.cleaned_data['picture_xml']:
16 self.cleaned_data['picture_xml_file'] = \
17 ContentFile(self.cleaned_data['picture_xml'].encode('utf-8'))
19 raise forms.ValidationError(_("Please supply an XML."))
20 return super(PictureImportForm, self).clean()
22 def save(self, commit=True, **kwargs):
23 return Picture.from_xml_file(self.cleaned_data['picture_xml_file'], image_file=self.cleaned_data['picture_image_file'],
24 overwrite=True, **kwargs)