def import_project(self, xml_root, request): try: user = request.user except User.DoesNotExist: log.info('Unable to detect user name. Import failed.') else: import_project(xml_root, user)
def handle(self, *args, **options): roottag, xmltree = validate_xml(options['xmlfile']) if roottag == 'conditions': import_conditions(xmltree) elif roottag == 'options': import_options(xmltree) elif roottag == 'domain': import_domain(xmltree) elif roottag == 'catalog': import_catalog(xmltree) elif roottag == 'tasks': import_tasks(xmltree) elif roottag == 'views': import_views(xmltree) elif roottag == 'project': try: user = User.objects.get(username=options['user']) except User.DoesNotExist: raise CommandError('Give a valid username using --user.') import_project(xmltree, user)
def post(self, request, *args, **kwargs): try: request.FILES['uploaded_file'] except KeyError: return HttpResponseRedirect(self.success_url) else: tempfilename = handle_uploaded_file(request.FILES['uploaded_file']) tree = read_xml_file(tempfilename) if tree is None: log.info('Xml parsing error. Import failed.') return render(request, self.parsing_error_template, status=400) else: import_project(request.user, tree) return HttpResponseRedirect(self.success_url)
def handle(self, *args, **options): tree = et.parse(options['xmlfile']) root = tree.getroot() if root.tag == 'rdmo': import_conditions(root) import_options(root) import_domain(root) import_questions(root) import_tasks(root) import_views(root) elif root.tag == 'project': try: user = User.objects.get(username=options['user']) except User.DoesNotExist: raise CommandError('Give a valid username using --user.') import_project(user, root)