Skip to content

Commit

Permalink
Fix the failing test #1524
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jan 21, 2025
1 parent 1ddc903 commit b642451
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
7 changes: 7 additions & 0 deletions scanpipe/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 18 additions & 3 deletions scanpipe/templates/scanpipe/modals/project_archive_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@
<p class="mb-2">
The selected directories will be removed:
</p>
<ul class="mb-5">
{{ archive_form.as_ul }}
</ul>
<div class="field">
<label class="label">
{{ archive_form.remove_input }}
{{ archive_form.remove_input.label }}
</label>
</div>
<div class="field">
<label class="label">
{{ archive_form.remove_codebase }}
{{ archive_form.remove_codebase.label }}
</label>
</div>
<div class="field">
<label class="label">
{{ archive_form.remove_output }}
{{ archive_form.remove_output.label }}
</label>
</div>
<p>
Are you sure you want to do this?
</p>
Expand Down
12 changes: 12 additions & 0 deletions scanpipe/templates/scanpipe/modals/projects_reset_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
<p class="mb-5">
Are you sure you want to do this?
</p>
{% if page_obj.paginator.num_pages > 1 %}
<div class="show-on-all-checked">
<hr>
<div class="field include-all-field">
<label class="checkbox" for="{{ archive_form.select_across.id_for_label }}">
<input type="checkbox" name="{{ archive_form.select_across.name }}" id="{{ archive_form.select_across.id_for_label }}">
Include all {{ paginator.count|intcomma }} projects
</label>
<p class="help">{{ outputs_download_form.select_across.help_text }}</p>
</div>
</div>
{% endif %}
</section>
<form action="{% url 'project_action' %}" method="post" id="reset-projects-form">{% csrf_token %}
<input type="hidden" name="{{ action_form.url_query.name }}" value="{{ request.GET.urlencode }}">
Expand Down
42 changes: 21 additions & 21 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit b642451

Please sign in to comment.