def post(self, request, *args, **kwargs): ''' Processes file upload as a phylogeny import if form is valid. ''' form_class = self.get_form_class() form = self.get_form(form_class) if form.is_valid(): file_format = form.cleaned_data.get('file_format') try: importer = importer_registry.get_by_format_name(file_format) for file_field in request.FILES: importer.save(import_from=request.FILES[file_field]) except PhylogenyImportMergeConflict as exception: form._errors['file_field'] = form.error_class(['%s' % exception]) return self.render_to_response({'form': form}) except: form._errors['file_field'] = form.error_class([_('An error occurred during import. Please verify the file format and file contents. If the error persists, try importing a different file or format.')]) return self.render_to_response({'form': form}) messages.success(request, _('Successfully imported phylogeny.')) return HttpResponse(''' <script type="text/javascript"> opener.location=opener.location; window.close(); </script> ''')
def handle(self, *args, **options): try: path = args[0] except: raise CommandError(_('Phylogeny path missing. For more information type:\npython manage.py help import-phylogeny')) format_name = options['format'] importer = importer_registry.get_by_format_name(format_name) importer.save(import_from=path) self.stdout.write(_('Successfully imported tree from "%(path)s" in format "%(format)s"\n') % {'path': path, 'format': format_name})