X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/003a3fab503e3c8362b14f8f8c7306f305d9cc39..d66b8ae1ad69a5111e7dd6c1fbd5124f4db142e5:/catalogue/forms.py?ds=sidebyside diff --git a/catalogue/forms.py b/catalogue/forms.py new file mode 100644 index 0000000..834785f --- /dev/null +++ b/catalogue/forms.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from django.forms import Form, FileField, CharField, ValidationError + +from catalogue.models import Lesson + + +class LessonImportForm(Form): + lesson_xml_file = FileField(required=False) + lesson_xml = CharField(required=False) + + def clean(self): + from django.core.files.base import ContentFile + + if not self.cleaned_data['lesson_xml_file']: + if self.cleaned_data['lesson_xml']: + self.cleaned_data['lesson_xml_file'] = \ + ContentFile(self.cleaned_data['lesson_xml'].encode('utf-8')) + else: + raise ValidationError(u"Proszę dostarczyć XML.") + return super(LessonImportForm, self).clean() + + def save(self, commit=True, **kwargs): + return Lesson.publish(self.cleaned_data['book_xml_file'])