1 # -*- coding: utf-8 -*-
2 from django.forms import Form, FileField, CharField, ValidationError
4 from catalogue.models import Lesson
7 class LessonImportForm(Form):
8 lesson_xml_file = FileField(required=False)
9 lesson_xml = CharField(required=False)
12 from django.core.files.base import ContentFile
14 if not self.cleaned_data['lesson_xml_file']:
15 if self.cleaned_data['lesson_xml']:
16 self.cleaned_data['lesson_xml_file'] = \
17 ContentFile(self.cleaned_data['lesson_xml'].encode('utf-8'))
19 raise ValidationError(u"Proszę dostarczyć XML.")
20 return super(LessonImportForm, self).clean()
22 def save(self, commit=True, **kwargs):
23 return Lesson.publish(self.cleaned_data['book_xml_file'])