We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Nested projects: cancel button actually imports data
### Description / Beschreibung

In nested projects if someone opens the import from parent project and then decides not to import anything by clicking <kbd>Cancel</kbd> the data will be imported anyway.

### Expected behaviour / Erwartetes Verhalten

Expected behaviour is to get back to the project details view without any changes to the answers, i.e. not importing anything from the parent project.

### Steps to reproduce / Schritte zum Reproduzieren

1. Create a project and add some answers
2. Create a child project
3. In the child project go the import from parent project view
4. Click <kbd>Cancel</kbd> button
5. Answers are imported to the child project.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `rdmo/projects/mixins.py`
Content:
```
1 from collections import defaultdict
2 from pathlib import Path
3 
4 from django.contrib.sites.shortcuts import get_current_site
5 from django.core.exceptions import ValidationError
6 from django.http import HttpResponseRedirect, Http404, HttpResponse
7 from django.shortcuts import get_object_or_404, render, redirect
8 from django.utils.translation import gettext_lazy as _
9 
10 from rdmo.core.imports import handle_uploaded_file, file_path_exists
11 from rdmo.core.plugins import get_plugin, get_plugins
12 from rdmo.questions.models import Question
13 
14 from .models import Membership, Project
15 from .utils import (save_import_snapshot_values, save_import_tasks,
16                     save_import_values, save_import_views)
17 
18 
19 class ProjectImportMixin(object):
20 
21     def get_current_values(self, current_project):
22         queryset = current_project.values.filter(snapshot=None).select_related('attribute', 'option')
23 
24         current_values = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list))))
25         for value in queryset:
26             current_values[value.attribute.uri][value.set_prefix][value.set_index][value.collection_index] = value
27         return current_values
28 
29     def get_questions(self, catalog):
30         queryset = Question.objects.filter(questionset__section__catalog=catalog) \
31                                    .select_related('attribute') \
32                                    .order_by('attribute__uri')
33 
34         questions = {}
35         for question in queryset:
36             if question.attribute and question.attribute.uri not in questions:
37                 questions[question.attribute.uri] = question
38         return questions
39 
40     def update_values(self, current_project, catalog, values, snapshots=[]):
41         questions = self.get_questions(catalog)
42         current_values = self.get_current_values(current_project) if current_project else {}
43 
44         for value in values:
45             if value.attribute:
46                 value.pk = None
47                 value.question = questions.get(value.attribute.uri)
48                 value.current = current_values.get(value.attribute.uri, {}) \
49                                               .get(value.set_prefix, {}) \
50                                               .get(value.set_index, {}) \
51                                               .get(value.collection_index)
52 
53         for snapshot in snapshots:
54             snapshot.pk = None
55 
56             for value in snapshot.snapshot_values:
57                 if value.attribute:
58                     value.pk = None
59                     value.question = questions.get(value.attribute.uri)
60                     value.current = current_values.get(value.attribute.uri, {}) \
61                                                   .get(value.set_prefix, {}) \
62                                                   .get(value.set_index, {}) \
63                                                   .get(value.collection_index)
64 
65     def get_import_plugin(self, key, current_project=None):
66         import_plugin = get_plugin('PROJECT_IMPORTS', key)
67         if import_plugin is None:
68             raise Http404
69 
70         import_plugin.request = self.request
71         import_plugin.current_project = current_project
72 
73         return import_plugin
74 
75     def upload_file(self):
76         try:
77             uploaded_file = self.request.FILES['uploaded_file']
78         except KeyError:
79             return render(self.request, 'core/error.html', {
80                 'title': _('Import error'),
81                 'errors': [_('There has been an error with your import.')]
82             }, status=400)
83         else:
84             self.request.session['import_file_name'] = handle_uploaded_file(uploaded_file)
85             self.request.session['import_source_title'] = uploaded_file.name
86 
87             # redirect to the import form
88             return redirect(self.request.path)
89 
90     def import_form(self):
91         current_project = self.object
92 
93         import_file_name = self.request.session.get('import_file_name')
94         import_source_title = self.request.session.get('import_source_title')
95         if import_file_name is None or not Path(import_file_name).is_file():
96             return render(self.request, 'core/error.html', {
97                 'title': _('Import error'),
98                 'errors': [_('There has been an error with your import. No uploaded or retrieved file could be found.')]
99             }, status=400)
100 
101         for import_key, import_plugin in get_plugins('PROJECT_IMPORTS').items():
102             import_plugin.current_project = current_project
103             import_plugin.file_name = import_file_name
104             import_plugin.source_title = import_source_title
105 
106             if import_plugin.upload and import_plugin.check():
107                 try:
108                     import_plugin.process()
109                 except ValidationError as e:
110                     return render(self.request, 'core/error.html', {
111                         'title': _('Import error'),
112                         'errors': e
113                     }, status=400)
114 
115                 # store information in session for ProjectCreateImportView
116                 self.request.session['import_key'] = import_key
117 
118                 # attach questions and current values
119                 self.update_values(current_project, import_plugin.catalog, import_plugin.values, import_plugin.snapshots)
120 
121                 return render(self.request, 'projects/project_import.html', {
122                     'method': 'import_file',
123                     'current_project': current_project,
124                     'source_title': import_plugin.source_title,
125                     'source_project': import_plugin.project,
126                     'values': import_plugin.values,
127                     'snapshots': import_plugin.snapshots if not current_project else None,
128                     'tasks': import_plugin.tasks,
129                     'views': import_plugin.views
130                 })
131 
132         return render(self.request, 'core/error.html', {
133             'title': _('Import error'),
134             'errors': [_('Files of this type cannot be imported.')]
135         }, status=400)
136 
137     def import_file(self):
138         current_project = self.object
139 
140         if 'cancel' in self.request.POST:
141             if current_project:
142                 return HttpResponseRedirect(current_project.get_absolute_url())
143             else:
144                 return HttpResponseRedirect(self.success_url)
145 
146         try:
147             import_tmpfile_name = self.request.session.pop('import_file_name')
148             import_key = self.request.session.pop('import_key')
149         except KeyError:
150             return render(self.request, 'core/error.html', {
151                 'title': _('Import error'),
152                 'errors': [_('There has been an error with your import.')]
153             }, status=400)
154 
155         checked = [key for key, value in self.request.POST.items() if 'on' in value]
156 
157         if import_tmpfile_name and import_key:
158             import_plugin = self.get_import_plugin(import_key, current_project)
159             import_plugin.file_name = import_tmpfile_name
160 
161             if import_plugin.check():
162                 try:
163                     import_plugin.process()
164                 except ValidationError as e:
165                     return render(self.request, 'core/error.html', {
166                         'title': _('Import error'),
167                         'errors': e
168                     }, status=400)
169 
170                 # attach questions and current values
171                 self.update_values(current_project, import_plugin.catalog, import_plugin.values, import_plugin.snapshots)
172 
173                 if current_project:
174                     save_import_values(self.object, import_plugin.values, checked)
175                     save_import_tasks(self.object, import_plugin.tasks)
176                     save_import_views(self.object, import_plugin.views)
177 
178                     return HttpResponseRedirect(current_project.get_absolute_url())
179 
180                 else:
181                     # add current site and save project
182                     import_plugin.project.site = get_current_site(self.request)
183                     import_plugin.project.save()
184 
185                     # add user to project
186                     membership = Membership(project=import_plugin.project, user=self.request.user, role='owner')
187                     membership.save()
188 
189                     for value in import_plugin.values:
190                         value.current = None
191 
192                     save_import_values(import_plugin.project, import_plugin.values, checked)
193                     save_import_snapshot_values(import_plugin.project, import_plugin.snapshots, checked)
194                     save_import_tasks(import_plugin.project, import_plugin.tasks)
195                     save_import_views(import_plugin.project, import_plugin.views)
196 
197                     return HttpResponseRedirect(import_plugin.project.get_absolute_url())
198 
199         return render(self.request, 'core/error.html', {
200             'title': _('Import error'),
201             'errors': [_('There has been an error with your import.')]
202         }, status=400)
203 
204     def import_project(self):
205         current_project = self.object
206 
207         # get the original project
208         project = get_object_or_404(Project.objects.all(), id=self.request.POST.get('source'))
209 
210         # check if the user has the permission to access the original project
211         if not self.request.user.has_perm('projects.view_project_object', project):
212             self.handle_no_permission()
213 
214         values = project.values.filter(snapshot=None) \
215                                .select_related('attribute', 'option')
216 
217         # attach questions and current values
218         self.update_values(current_project, current_project.catalog, values)
219 
220         checked = [key for key, value in self.request.POST.items() if 'on' in value]
221         if checked:
222             save_import_values(current_project, values, checked)
223             return HttpResponseRedirect(current_project.get_absolute_url())
224 
225         else:
226             return render(self.request, 'projects/project_import.html', {
227                 'method': 'import_project',
228                 'source': project.id,
229                 'source_title': project.title,
230                 'current_project': current_project,
231                 'values': values,
232             })
233
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/rdmo/projects/mixins.py b/rdmo/projects/mixins.py
--- a/rdmo/projects/mixins.py
+++ b/rdmo/projects/mixins.py
@@ -204,6 +204,12 @@
     def import_project(self):
         current_project = self.object
 
+        if 'cancel' in self.request.POST:
+            if current_project:
+                return HttpResponseRedirect(current_project.get_absolute_url())
+            else:
+                return HttpResponseRedirect(self.success_url)
+
         # get the original project
         project = get_object_or_404(Project.objects.all(), id=self.request.POST.get('source'))

{"golden_diff": "diff --git a/rdmo/projects/mixins.py b/rdmo/projects/mixins.py\n--- a/rdmo/projects/mixins.py\n+++ b/rdmo/projects/mixins.py\n@@ -204,6 +204,12 @@\n     def import_project(self):\n         current_project = self.object\n \n+        if 'cancel' in self.request.POST:\n+            if current_project:\n+                return HttpResponseRedirect(current_project.get_absolute_url())\n+            else:\n+                return HttpResponseRedirect(self.success_url)\n+\n         # get the original project\n         project = get_object_or_404(Project.objects.all(), id=self.request.POST.get('source'))\n", "issue": "Nested projects: cancel button actually imports data\n### Description / Beschreibung\r\n\r\nIn nested projects if someone opens the import from parent project and then decides not to import anything by clicking <kbd>Cancel</kbd> the data will be imported anyway.\r\n\r\n### Expected behaviour / Erwartetes Verhalten\r\n\r\nExpected behaviour is to get back to the project details view without any changes to the answers, i.e. not importing anything from the parent project.\r\n\r\n### Steps to reproduce / Schritte zum Reproduzieren\r\n\r\n1. Create a project and add some answers\r\n2. Create a child project\r\n3. In the child project go the import from parent project view\r\n4. Click <kbd>Cancel</kbd> button\r\n5. Answers are imported to the child project.\r\n\r\n\n", "before_files": [{"content": "from collections import defaultdict\nfrom pathlib import Path\n\nfrom django.contrib.sites.shortcuts import get_current_site\nfrom django.core.exceptions import ValidationError\nfrom django.http import HttpResponseRedirect, Http404, HttpResponse\nfrom django.shortcuts import get_object_or_404, render, redirect\nfrom django.utils.translation import gettext_lazy as _\n\nfrom rdmo.core.imports import handle_uploaded_file, file_path_exists\nfrom rdmo.core.plugins import get_plugin, get_plugins\nfrom rdmo.questions.models import Question\n\nfrom .models import Membership, Project\nfrom .utils import (save_import_snapshot_values, save_import_tasks,\n                    save_import_values, save_import_views)\n\n\nclass ProjectImportMixin(object):\n\n    def get_current_values(self, current_project):\n        queryset = current_project.values.filter(snapshot=None).select_related('attribute', 'option')\n\n        current_values = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list))))\n        for value in queryset:\n            current_values[value.attribute.uri][value.set_prefix][value.set_index][value.collection_index] = value\n        return current_values\n\n    def get_questions(self, catalog):\n        queryset = Question.objects.filter(questionset__section__catalog=catalog) \\\n                                   .select_related('attribute') \\\n                                   .order_by('attribute__uri')\n\n        questions = {}\n        for question in queryset:\n            if question.attribute and question.attribute.uri not in questions:\n                questions[question.attribute.uri] = question\n        return questions\n\n    def update_values(self, current_project, catalog, values, snapshots=[]):\n        questions = self.get_questions(catalog)\n        current_values = self.get_current_values(current_project) if current_project else {}\n\n        for value in values:\n            if value.attribute:\n                value.pk = None\n                value.question = questions.get(value.attribute.uri)\n                value.current = current_values.get(value.attribute.uri, {}) \\\n                                              .get(value.set_prefix, {}) \\\n                                              .get(value.set_index, {}) \\\n                                              .get(value.collection_index)\n\n        for snapshot in snapshots:\n            snapshot.pk = None\n\n            for value in snapshot.snapshot_values:\n                if value.attribute:\n                    value.pk = None\n                    value.question = questions.get(value.attribute.uri)\n                    value.current = current_values.get(value.attribute.uri, {}) \\\n                                                  .get(value.set_prefix, {}) \\\n                                                  .get(value.set_index, {}) \\\n                                                  .get(value.collection_index)\n\n    def get_import_plugin(self, key, current_project=None):\n        import_plugin = get_plugin('PROJECT_IMPORTS', key)\n        if import_plugin is None:\n            raise Http404\n\n        import_plugin.request = self.request\n        import_plugin.current_project = current_project\n\n        return import_plugin\n\n    def upload_file(self):\n        try:\n            uploaded_file = self.request.FILES['uploaded_file']\n        except KeyError:\n            return render(self.request, 'core/error.html', {\n                'title': _('Import error'),\n                'errors': [_('There has been an error with your import.')]\n            }, status=400)\n        else:\n            self.request.session['import_file_name'] = handle_uploaded_file(uploaded_file)\n            self.request.session['import_source_title'] = uploaded_file.name\n\n            # redirect to the import form\n            return redirect(self.request.path)\n\n    def import_form(self):\n        current_project = self.object\n\n        import_file_name = self.request.session.get('import_file_name')\n        import_source_title = self.request.session.get('import_source_title')\n        if import_file_name is None or not Path(import_file_name).is_file():\n            return render(self.request, 'core/error.html', {\n                'title': _('Import error'),\n                'errors': [_('There has been an error with your import. No uploaded or retrieved file could be found.')]\n            }, status=400)\n\n        for import_key, import_plugin in get_plugins('PROJECT_IMPORTS').items():\n            import_plugin.current_project = current_project\n            import_plugin.file_name = import_file_name\n            import_plugin.source_title = import_source_title\n\n            if import_plugin.upload and import_plugin.check():\n                try:\n                    import_plugin.process()\n                except ValidationError as e:\n                    return render(self.request, 'core/error.html', {\n                        'title': _('Import error'),\n                        'errors': e\n                    }, status=400)\n\n                # store information in session for ProjectCreateImportView\n                self.request.session['import_key'] = import_key\n\n                # attach questions and current values\n                self.update_values(current_project, import_plugin.catalog, import_plugin.values, import_plugin.snapshots)\n\n                return render(self.request, 'projects/project_import.html', {\n                    'method': 'import_file',\n                    'current_project': current_project,\n                    'source_title': import_plugin.source_title,\n                    'source_project': import_plugin.project,\n                    'values': import_plugin.values,\n                    'snapshots': import_plugin.snapshots if not current_project else None,\n                    'tasks': import_plugin.tasks,\n                    'views': import_plugin.views\n                })\n\n        return render(self.request, 'core/error.html', {\n            'title': _('Import error'),\n            'errors': [_('Files of this type cannot be imported.')]\n        }, status=400)\n\n    def import_file(self):\n        current_project = self.object\n\n        if 'cancel' in self.request.POST:\n            if current_project:\n                return HttpResponseRedirect(current_project.get_absolute_url())\n            else:\n                return HttpResponseRedirect(self.success_url)\n\n        try:\n            import_tmpfile_name = self.request.session.pop('import_file_name')\n            import_key = self.request.session.pop('import_key')\n        except KeyError:\n            return render(self.request, 'core/error.html', {\n                'title': _('Import error'),\n                'errors': [_('There has been an error with your import.')]\n            }, status=400)\n\n        checked = [key for key, value in self.request.POST.items() if 'on' in value]\n\n        if import_tmpfile_name and import_key:\n            import_plugin = self.get_import_plugin(import_key, current_project)\n            import_plugin.file_name = import_tmpfile_name\n\n            if import_plugin.check():\n                try:\n                    import_plugin.process()\n                except ValidationError as e:\n                    return render(self.request, 'core/error.html', {\n                        'title': _('Import error'),\n                        'errors': e\n                    }, status=400)\n\n                # attach questions and current values\n                self.update_values(current_project, import_plugin.catalog, import_plugin.values, import_plugin.snapshots)\n\n                if current_project:\n                    save_import_values(self.object, import_plugin.values, checked)\n                    save_import_tasks(self.object, import_plugin.tasks)\n                    save_import_views(self.object, import_plugin.views)\n\n                    return HttpResponseRedirect(current_project.get_absolute_url())\n\n                else:\n                    # add current site and save project\n                    import_plugin.project.site = get_current_site(self.request)\n                    import_plugin.project.save()\n\n                    # add user to project\n                    membership = Membership(project=import_plugin.project, user=self.request.user, role='owner')\n                    membership.save()\n\n                    for value in import_plugin.values:\n                        value.current = None\n\n                    save_import_values(import_plugin.project, import_plugin.values, checked)\n                    save_import_snapshot_values(import_plugin.project, import_plugin.snapshots, checked)\n                    save_import_tasks(import_plugin.project, import_plugin.tasks)\n                    save_import_views(import_plugin.project, import_plugin.views)\n\n                    return HttpResponseRedirect(import_plugin.project.get_absolute_url())\n\n        return render(self.request, 'core/error.html', {\n            'title': _('Import error'),\n            'errors': [_('There has been an error with your import.')]\n        }, status=400)\n\n    def import_project(self):\n        current_project = self.object\n\n        # get the original project\n        project = get_object_or_404(Project.objects.all(), id=self.request.POST.get('source'))\n\n        # check if the user has the permission to access the original project\n        if not self.request.user.has_perm('projects.view_project_object', project):\n            self.handle_no_permission()\n\n        values = project.values.filter(snapshot=None) \\\n                               .select_related('attribute', 'option')\n\n        # attach questions and current values\n        self.update_values(current_project, current_project.catalog, values)\n\n        checked = [key for key, value in self.request.POST.items() if 'on' in value]\n        if checked:\n            save_import_values(current_project, values, checked)\n            return HttpResponseRedirect(current_project.get_absolute_url())\n\n        else:\n            return render(self.request, 'projects/project_import.html', {\n                'method': 'import_project',\n                'source': project.id,\n                'source_title': project.title,\n                'current_project': current_project,\n                'values': values,\n            })\n", "path": "rdmo/projects/mixins.py"}], "after_files": [{"content": "from collections import defaultdict\nfrom pathlib import Path\n\nfrom django.contrib.sites.shortcuts import get_current_site\nfrom django.core.exceptions import ValidationError\nfrom django.http import HttpResponseRedirect, Http404, HttpResponse\nfrom django.shortcuts import get_object_or_404, render, redirect\nfrom django.utils.translation import gettext_lazy as _\n\nfrom rdmo.core.imports import handle_uploaded_file, file_path_exists\nfrom rdmo.core.plugins import get_plugin, get_plugins\nfrom rdmo.questions.models import Question\n\nfrom .models import Membership, Project\nfrom .utils import (save_import_snapshot_values, save_import_tasks,\n                    save_import_values, save_import_views)\n\n\nclass ProjectImportMixin(object):\n\n    def get_current_values(self, current_project):\n        queryset = current_project.values.filter(snapshot=None).select_related('attribute', 'option')\n\n        current_values = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list))))\n        for value in queryset:\n            current_values[value.attribute.uri][value.set_prefix][value.set_index][value.collection_index] = value\n        return current_values\n\n    def get_questions(self, catalog):\n        queryset = Question.objects.filter(questionset__section__catalog=catalog) \\\n                                   .select_related('attribute') \\\n                                   .order_by('attribute__uri')\n\n        questions = {}\n        for question in queryset:\n            if question.attribute and question.attribute.uri not in questions:\n                questions[question.attribute.uri] = question\n        return questions\n\n    def update_values(self, current_project, catalog, values, snapshots=[]):\n        questions = self.get_questions(catalog)\n        current_values = self.get_current_values(current_project) if current_project else {}\n\n        for value in values:\n            if value.attribute:\n                value.pk = None\n                value.question = questions.get(value.attribute.uri)\n                value.current = current_values.get(value.attribute.uri, {}) \\\n                                              .get(value.set_prefix, {}) \\\n                                              .get(value.set_index, {}) \\\n                                              .get(value.collection_index)\n\n        for snapshot in snapshots:\n            snapshot.pk = None\n\n            for value in snapshot.snapshot_values:\n                if value.attribute:\n                    value.pk = None\n                    value.question = questions.get(value.attribute.uri)\n                    value.current = current_values.get(value.attribute.uri, {}) \\\n                                                  .get(value.set_prefix, {}) \\\n                                                  .get(value.set_index, {}) \\\n                                                  .get(value.collection_index)\n\n    def get_import_plugin(self, key, current_project=None):\n        import_plugin = get_plugin('PROJECT_IMPORTS', key)\n        if import_plugin is None:\n            raise Http404\n\n        import_plugin.request = self.request\n        import_plugin.current_project = current_project\n\n        return import_plugin\n\n    def upload_file(self):\n        try:\n            uploaded_file = self.request.FILES['uploaded_file']\n        except KeyError:\n            return render(self.request, 'core/error.html', {\n                'title': _('Import error'),\n                'errors': [_('There has been an error with your import.')]\n            }, status=400)\n        else:\n            self.request.session['import_file_name'] = handle_uploaded_file(uploaded_file)\n            self.request.session['import_source_title'] = uploaded_file.name\n\n            # redirect to the import form\n            return redirect(self.request.path)\n\n    def import_form(self):\n        current_project = self.object\n\n        import_file_name = self.request.session.get('import_file_name')\n        import_source_title = self.request.session.get('import_source_title')\n        if import_file_name is None or not Path(import_file_name).is_file():\n            return render(self.request, 'core/error.html', {\n                'title': _('Import error'),\n                'errors': [_('There has been an error with your import. No uploaded or retrieved file could be found.')]\n            }, status=400)\n\n        for import_key, import_plugin in get_plugins('PROJECT_IMPORTS').items():\n            import_plugin.current_project = current_project\n            import_plugin.file_name = import_file_name\n            import_plugin.source_title = import_source_title\n\n            if import_plugin.upload and import_plugin.check():\n                try:\n                    import_plugin.process()\n                except ValidationError as e:\n                    return render(self.request, 'core/error.html', {\n                        'title': _('Import error'),\n                        'errors': e\n                    }, status=400)\n\n                # store information in session for ProjectCreateImportView\n                self.request.session['import_key'] = import_key\n\n                # attach questions and current values\n                self.update_values(current_project, import_plugin.catalog, import_plugin.values, import_plugin.snapshots)\n\n                return render(self.request, 'projects/project_import.html', {\n                    'method': 'import_file',\n                    'current_project': current_project,\n                    'source_title': import_plugin.source_title,\n                    'source_project': import_plugin.project,\n                    'values': import_plugin.values,\n                    'snapshots': import_plugin.snapshots if not current_project else None,\n                    'tasks': import_plugin.tasks,\n                    'views': import_plugin.views\n                })\n\n        return render(self.request, 'core/error.html', {\n            'title': _('Import error'),\n            'errors': [_('Files of this type cannot be imported.')]\n        }, status=400)\n\n    def import_file(self):\n        current_project = self.object\n\n        if 'cancel' in self.request.POST:\n            if current_project:\n                return HttpResponseRedirect(current_project.get_absolute_url())\n            else:\n                return HttpResponseRedirect(self.success_url)\n\n        try:\n            import_tmpfile_name = self.request.session.pop('import_file_name')\n            import_key = self.request.session.pop('import_key')\n        except KeyError:\n            return render(self.request, 'core/error.html', {\n                'title': _('Import error'),\n                'errors': [_('There has been an error with your import.')]\n            }, status=400)\n\n        checked = [key for key, value in self.request.POST.items() if 'on' in value]\n\n        if import_tmpfile_name and import_key:\n            import_plugin = self.get_import_plugin(import_key, current_project)\n            import_plugin.file_name = import_tmpfile_name\n\n            if import_plugin.check():\n                try:\n                    import_plugin.process()\n                except ValidationError as e:\n                    return render(self.request, 'core/error.html', {\n                        'title': _('Import error'),\n                        'errors': e\n                    }, status=400)\n\n                # attach questions and current values\n                self.update_values(current_project, import_plugin.catalog, import_plugin.values, import_plugin.snapshots)\n\n                if current_project:\n                    save_import_values(self.object, import_plugin.values, checked)\n                    save_import_tasks(self.object, import_plugin.tasks)\n                    save_import_views(self.object, import_plugin.views)\n\n                    return HttpResponseRedirect(current_project.get_absolute_url())\n\n                else:\n                    # add current site and save project\n                    import_plugin.project.site = get_current_site(self.request)\n                    import_plugin.project.save()\n\n                    # add user to project\n                    membership = Membership(project=import_plugin.project, user=self.request.user, role='owner')\n                    membership.save()\n\n                    for value in import_plugin.values:\n                        value.current = None\n\n                    save_import_values(import_plugin.project, import_plugin.values, checked)\n                    save_import_snapshot_values(import_plugin.project, import_plugin.snapshots, checked)\n                    save_import_tasks(import_plugin.project, import_plugin.tasks)\n                    save_import_views(import_plugin.project, import_plugin.views)\n\n                    return HttpResponseRedirect(import_plugin.project.get_absolute_url())\n\n        return render(self.request, 'core/error.html', {\n            'title': _('Import error'),\n            'errors': [_('There has been an error with your import.')]\n        }, status=400)\n\n    def import_project(self):\n        current_project = self.object\n\n        if 'cancel' in self.request.POST:\n            if current_project:\n                return HttpResponseRedirect(current_project.get_absolute_url())\n            else:\n                return HttpResponseRedirect(self.success_url)\n\n        # get the original project\n        project = get_object_or_404(Project.objects.all(), id=self.request.POST.get('source'))\n\n        # check if the user has the permission to access the original project\n        if not self.request.user.has_perm('projects.view_project_object', project):\n            self.handle_no_permission()\n\n        values = project.values.filter(snapshot=None) \\\n                               .select_related('attribute', 'option')\n\n        # attach questions and current values\n        self.update_values(current_project, current_project.catalog, values)\n\n        checked = [key for key, value in self.request.POST.items() if 'on' in value]\n        if checked:\n            save_import_values(current_project, values, checked)\n            return HttpResponseRedirect(current_project.get_absolute_url())\n\n        else:\n            return render(self.request, 'projects/project_import.html', {\n                'method': 'import_project',\n                'source': project.id,\n                'source_title': project.title,\n                'current_project': current_project,\n                'values': values,\n            })\n", "path": "rdmo/projects/mixins.py"}]}