From b64245143b162f39eecda9fe6c645dfc7a897876 Mon Sep 17 00:00:00 2001 From: tdruez Date: Tue, 21 Jan 2025 13:45:21 +0900 Subject: [PATCH] Fix the failing test #1524 Signed-off-by: tdruez --- scanpipe/forms.py | 7 ++++ .../modals/project_archive_modal.html | 21 ++++++++-- .../scanpipe/modals/projects_reset_modal.html | 12 ++++++ scanpipe/views.py | 42 +++++++++---------- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/scanpipe/forms.py b/scanpipe/forms.py index 35d638784..94ce46428 100644 --- a/scanpipe/forms.py +++ b/scanpipe/forms.py @@ -269,6 +269,13 @@ class ArchiveProjectForm(BaseProjectActionForm): required=False, ) + def get_action_kwargs(self): + return { + "remove_input": self.cleaned_data["remove_input"], + "remove_codebase": self.cleaned_data["remove_codebase"], + "remove_output": self.cleaned_data["remove_output"], + } + class ProjectOutputDownloadForm(BaseProjectActionForm): output_format = forms.ChoiceField( diff --git a/scanpipe/templates/scanpipe/modals/project_archive_modal.html b/scanpipe/templates/scanpipe/modals/project_archive_modal.html index 09bb2f706..5fe738843 100644 --- a/scanpipe/templates/scanpipe/modals/project_archive_modal.html +++ b/scanpipe/templates/scanpipe/modals/project_archive_modal.html @@ -14,9 +14,24 @@

The selected directories will be removed:

- +
+ +
+
+ +
+
+ +

Are you sure you want to do this?

diff --git a/scanpipe/templates/scanpipe/modals/projects_reset_modal.html b/scanpipe/templates/scanpipe/modals/projects_reset_modal.html index 9d62a2f33..c74067972 100644 --- a/scanpipe/templates/scanpipe/modals/projects_reset_modal.html +++ b/scanpipe/templates/scanpipe/modals/projects_reset_modal.html @@ -16,6 +16,18 @@

Are you sure you want to do this?

+ {% if page_obj.paginator.num_pages > 1 %} +
+
+
+ +

{{ outputs_download_form.select_across.help_text }}

+
+
+ {% endif %}
{% csrf_token %} diff --git a/scanpipe/views.py b/scanpipe/views.py index 17f7aaf7b..702c0e8ba 100644 --- a/scanpipe/views.py +++ b/scanpipe/views.py @@ -1147,7 +1147,7 @@ def form_valid(self, form): project = self.get_object() try: - project.archive(**form.cleaned_data) + project.archive(**form.get_action_kwargs()) except RunInProgressError as error: messages.error(self.request, error) return redirect(project) @@ -1156,6 +1156,23 @@ def form_valid(self, form): return response +class ProjectResetView(ConditionalLoginRequired, generic.DeleteView): + model = Project + success_message = 'All data, except inputs, for the "{}" project have been removed.' + + def form_valid(self, form): + """Call the reset() method on the project.""" + project = self.get_object() + try: + project.reset(keep_input=True) + except RunInProgressError as error: + messages.error(self.request, error) + else: + messages.success(self.request, self.success_message.format(project.name)) + + return redirect(project) + + class ProjectDeleteView(ConditionalLoginRequired, generic.DeleteView): model = Project success_url = reverse_lazy("project_list") @@ -1210,11 +1227,11 @@ def post(self, request, *args, **kwargs): return self.export_xlsx_file_response() if action == "archive": - action_kwargs = action_form.cleaned_data + action_kwargs = action_form.get_action_kwargs() count = 0 for project in project_qs: - if self.perform_action(action, project, action_kwargs): + if self.perform_action(project, action, action_kwargs): count += 1 if count: @@ -1279,7 +1296,7 @@ def get_export_xlsx_prepend_fields(self): return ["project"] def get_export_xlsx_worksheet_name(self): - if self.report_form.cleaned_data.get("model_name") == "todo": + if self.action_form.cleaned_data.get("model_name") == "todo": return "TODOS" def get_export_xlsx_filename(self): @@ -1307,23 +1324,6 @@ def download_outputs_zip_response(project_qs, action_form): ) -class ProjectResetView(ConditionalLoginRequired, generic.DeleteView): - model = Project - success_message = 'All data, except inputs, for the "{}" project have been removed.' - - def form_valid(self, form): - """Call the reset() method on the project.""" - project = self.get_object() - try: - project.reset(keep_input=True) - except RunInProgressError as error: - messages.error(self.request, error) - else: - messages.success(self.request, self.success_message.format(project.name)) - - return redirect(project) - - class HTTPResponseHXRedirect(HttpResponseRedirect): status_code = 200