def clean_file(self): f = self.cleaned_data['file'] from ecs.core.serializer import Serializer serializer = Serializer() try: with transaction.atomic(): self.submission_form = serializer.read(self.cleaned_data['file']) except Exception as e: import_error_logger.debug('invalid ecx file') self.add_error('file', _('This file is not a valid ECX archive.')) f.seek(0) return f
def handle(self, **options): if options['output_type'] not in ['html', 'pdf']: raise CommandError('Error: --type must be one of "html", "pdf"') if not options['outfile']: raise CommandError( 'Error: Outputfile "-o filename" must be specified') ecxf = Serializer() tpl = get_template('docs/ecx/base.html') html = tpl.render({ 'version': ecxf.version, 'fields': ecxf.docs(), }) with open(options['outfile'], 'wb') as f: if options['output_type'] == "html": f.write(html.encode('utf-8')) else: f.write(html2pdf(html))