+ docx = self.cleaned_data['docx']
+ if docx is not None:
+ try:
+ text, meta = xml_from_docx(docx)
+ except Exception as e:
+ raise forms.ValidationError(e)
+ else:
+ self.cleaned_data['text'] = text
+ if not self.cleaned_data['title']:
+ self.cleaned_data['title'] = meta.get('title', '')
+ if not self.cleaned_data['slug']:
+ self.cleaned_data['slug'] = slugify(meta.get('title', ''))
+
+ if not self.cleaned_data["title"]:
+ self._errors["title"] = self.error_class([_("Title not set")])
+
+ if not self.cleaned_data["slug"]:
+ self._errors["slug"] = self.error_class([_("Slug not set")])
+