From b30e868485c315792f1c37e4677bd3cc77b54922 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Mon, 6 Jun 2016 16:07:34 +0200 Subject: [PATCH] fix&simplify lesson import form --- catalogue/forms.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/catalogue/forms.py b/catalogue/forms.py index 834785f..84f2e43 100644 --- a/catalogue/forms.py +++ b/catalogue/forms.py @@ -1,23 +1,12 @@ # -*- coding: utf-8 -*- -from django.forms import Form, FileField, CharField, ValidationError +from django.forms import Form, CharField +from librarian import IOFile 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() + lesson_xml = CharField() def save(self, commit=True, **kwargs): - return Lesson.publish(self.cleaned_data['book_xml_file']) + return Lesson.publish(IOFile.from_string(self.cleaned_data['lesson_xml'])) -- 2.20.1