Esempio n. 1
0
    def post(self, request, *args, **kwargs):
        # context = self.get_context_data(**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,
                'core/error.html', {
                    'title':
                    _('Import error'),
                    'error':
                    _('The content of the xml file does not consist of well formed data or markup.'
                      )
                },
                status=400)
        else:
            import_questions(tree)
            return HttpResponseRedirect(self.success_url)
Esempio n. 2
0
    def post(self, request):
        try:
            uploaded_file = request.FILES['uploaded_file']
        except KeyError:
            return HttpResponseRedirect(self.get_success_url())
        else:
            import_tmpfile_name = handle_uploaded_file(uploaded_file)

        root = read_xml_file(import_tmpfile_name)
        if root is None:
            logger.info('Xml parsing error. Import failed.')
            return render(
                request,
                'core/error.html', {
                    'title':
                    _('Import error'),
                    'errors': [
                        _('The content of the xml file does not consist of well formed data or markup.'
                          )
                    ]
                },
                status=400)

        else:
            try:
                elements = flat_xml_to_elements(root)
            except (KeyError, TypeError):
                return render(
                    request,
                    'core/error.html', {
                        'title': _('Import error'),
                        'errors': [_('This is not a RDMO XML file.')]
                    },
                    status=400)

            if check_permissions(elements, request.user):
                # store information in session for ProjectCreateImportView
                request.session['import_file_name'] = uploaded_file.name
                request.session['import_tmpfile_name'] = import_tmpfile_name
                request.session['import_success_url'] = self.get_success_url()

                return render(
                    request, 'management/upload.html', {
                        'file_name': uploaded_file.name,
                        'elements': import_elements(elements)
                    })
            else:
                return render(request,
                              'core/error.html', {
                                  'title': _('Import error'),
                                  'errors': [_('Forbidden.')]
                              },
                              status=403)
Esempio n. 3
0
    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_conditions(tree)
            return HttpResponseRedirect(self.success_url)
Esempio n. 4
0
    def post(self, request, *args, **kwargs):
        try:
            request.FILES['uploaded_file']
        except:
            return HttpResponseRedirect(self.success_url)
        else:
            tempfilename = handle_uploaded_file(request.FILES['uploaded_file'])

        roottag, xmltree = validate_xml(tempfilename)
        if roottag == 'views':
            import_views(xmltree)
            return HttpResponseRedirect(self.success_url)
        else:
            log.info('Xml parsing error. Import failed.')
            return render(request, self.parsing_error_template, status=400)
Esempio n. 5
0
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        current_project = self.object

        try:
            uploaded_file = request.FILES['uploaded_file']
        except KeyError:
            return HttpResponseRedirect(self.get_success_url())
        else:
            import_tmpfile_name = handle_uploaded_file(uploaded_file)

        for import_key, import_plugin in get_plugins(
                'PROJECT_IMPORTS').items():
            import_plugin.file_name = import_tmpfile_name
            import_plugin.current_project = current_project

            if import_plugin.check():
                try:
                    import_plugin.process()
                except ValidationError as e:
                    return render(request,
                                  'core/error.html', {
                                      'title': _('Import error'),
                                      'errors': e
                                  },
                                  status=400)

                # store information in session for ProjectCreateImportView
                request.session[
                    'update_import_tmpfile_name'] = import_tmpfile_name
                request.session['update_import_key'] = import_key

                return render(
                    request, 'projects/project_upload.html', {
                        'file_name': uploaded_file.name,
                        'current_project': current_project,
                        'values': import_plugin.values,
                        'tasks': import_plugin.tasks,
                        'views': import_plugin.views
                    })

        return render(
            request,
            'core/error.html', {
                'title': _('Import error'),
                'errors': [_('Files of this type cannot be imported.')]
            },
            status=400)
Esempio n. 6
0
    def post(self, request, *args, **kwargs):
        try:
            uploaded_file = request.FILES['uploaded_file']
        except KeyError:
            return HttpResponseRedirect(self.success_url)
        else:
            import_tmpfile_name = handle_uploaded_file(uploaded_file)

        for key, title, import_class_name in settings.PROJECT_IMPORTS:
            project_import = import_class(import_class_name)(
                import_tmpfile_name)

            if project_import.check():
                try:
                    project_import.process()
                except ValidationError as e:
                    return render(request,
                                  'core/error.html', {
                                      'title': _('Import error'),
                                      'errors': e
                                  },
                                  status=400)

                # store information in session for ProjectCreateImportView
                request.session[
                    'create_import_tmpfile_name'] = import_tmpfile_name
                request.session['create_import_class_name'] = import_class_name

                return render(
                    request, 'projects/project_upload.html', {
                        'create': True,
                        'file_name': uploaded_file.name,
                        'project': project_import.project,
                        'values': project_import.values,
                        'snapshots': project_import.snapshots,
                        'tasks': project_import.tasks,
                        'views': project_import.views
                    })

        return render(
            request,
            'core/error.html', {
                'title': _('Import error'),
                'errors': [_('Files of this type cannot be imported.')]
            },
            status=400)
Esempio n. 7
0
    def upload_file(self):
        try:
            uploaded_file = self.request.FILES['uploaded_file']
        except KeyError:
            return render(
                self.request,
                'core/error.html', {
                    'title': _('Import error'),
                    'errors': [_('There has been an error with your import.')]
                },
                status=400)
        else:
            self.request.session['import_file_name'] = handle_uploaded_file(
                uploaded_file)
            self.request.session['import_source_title'] = uploaded_file.name

            # redirect to the import form
            return redirect(self.request.path)
Esempio n. 8
0
    def upload_file(self):
        current_project = self.object

        try:
            uploaded_file = self.request.FILES['uploaded_file']
        except KeyError:
            return None
        else:
            import_tmpfile_name = handle_uploaded_file(uploaded_file)

        for import_key, import_plugin in get_plugins(
                'PROJECT_IMPORTS').items():
            import_plugin.file_name = import_tmpfile_name
            import_plugin.current_project = current_project

            if import_plugin.check():
                try:
                    import_plugin.process()
                except ValidationError as e:
                    return render(self.request,
                                  'core/error.html', {
                                      'title': _('Import error'),
                                      'errors': e
                                  },
                                  status=400)

                # store information in session for ProjectCreateImportView
                self.request.session[
                    'update_import_tmpfile_name'] = import_tmpfile_name
                self.request.session['update_import_key'] = import_key

                # attach questions and current values
                self.update_values(current_project, import_plugin.catalog,
                                   import_plugin.values,
                                   import_plugin.snapshots)

                return render(
                    self.request, 'projects/project_import.html', {
                        'method':
                        'import_file',
                        'current_project':
                        current_project,
                        'source_title':
                        uploaded_file.name,
                        'source_project':
                        import_plugin.project,
                        'values':
                        import_plugin.values,
                        'snapshots':
                        import_plugin.snapshots if current_project else None,
                        'tasks':
                        import_plugin.tasks,
                        'views':
                        import_plugin.views
                    })

        return render(
            self.request,
            'core/error.html', {
                'title': _('Import error'),
                'errors': [_('Files of this type cannot be imported.')]
            },
            status=400)