Skip to content

Commit 2292804

Browse files
committed
Refine the models rendering #1524
Signed-off-by: tdruez <[email protected]>
1 parent 750a4c5 commit 2292804

7 files changed

+45
-14
lines changed

scanpipe/templates/scanpipe/modals/projects_archive_modal.html

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load humanize %}
12
<div class="modal" id="modal-projects-archive">
23
<div class="modal-background"></div>
34
<div class="modal-card">
@@ -9,18 +10,39 @@
910
<section class="modal-card-body">
1011
<div class="notification is-warning has-text-weight-semibold">
1112
The selected projects will be marked as archived and will become read-only.
12-
Those will not appear in the project list by default anymore.
13+
Those will not appear in the project list by default anymore.<br>
1314
</div>
1415
<p class="mb-2">
1516
The selected directories will be removed:
1617
</p>
17-
<ul class="mb-5">
18-
{{ archive_form.as_ul }}
19-
</ul>
20-
<p>
21-
Are you sure you want to do this?
22-
</p>
18+
<div class="field">
19+
<label class="label">
20+
{{ archive_form.remove_input }}
21+
{{ archive_form.remove_input.label }}
22+
</label>
23+
</div>
24+
<div class="field">
25+
<label class="label">
26+
{{ archive_form.remove_codebase }}
27+
{{ archive_form.remove_codebase.label }}
28+
</label>
29+
</div>
30+
<div class="field">
31+
<label class="label">
32+
{{ archive_form.remove_output }}
33+
{{ archive_form.remove_output.label }}
34+
</label>
35+
</div>
36+
<hr>
37+
<div class="field">
38+
<label class="checkbox" for="{{ archive_form.select_across.id_for_label }}">
39+
<input type="checkbox" name="{{ archive_form.select_across.name }}" id="{{ archive_form.select_across.id_for_label }}">
40+
Include all {{ paginator.count|intcomma }} projects
41+
</label>
42+
<p class="help">{{ outputs_download_form.select_across.help_text }}</p>
43+
</div>
2344
</section>
45+
<input type="hidden" name="{{ archive_form.url_query.name }}" value="{{ request.GET.urlencode }}">
2446
<input type="hidden" name="action" value="archive">
2547
<footer class="modal-card-foot is-flex is-justify-content-space-between">
2648
<button class="button has-text-weight-semibold" type="reset">No, Cancel</button>

scanpipe/templates/scanpipe/modals/projects_delete_modal.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load humanize %}
12
<div class="modal" id="modal-projects-delete">
23
<div class="modal-background"></div>
34
<div class="modal-card">
@@ -21,6 +22,7 @@
2122
</p>
2223
</section>
2324
<form action="{% url 'project_action' %}" method="post" id="delete-projects-form">{% csrf_token %}
25+
<input type="hidden" name="{{ action_form.url_query.name }}" value="{{ request.GET.urlencode }}">
2426
<input type="hidden" name="action" value="delete">
2527
<footer class="modal-card-foot is-flex is-justify-content-space-between">
2628
<button class="button has-text-weight-semibold" type="reset">No, Cancel</button>

scanpipe/templates/scanpipe/modals/projects_download_modal.html

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{{ outputs_download_form.output_format }}
1515
</div>
1616
</div>
17+
<hr>
1718
<div class="field">
1819
<label class="checkbox" for="{{ outputs_download_form.select_across.id_for_label }}">
1920
<input type="checkbox" name="{{ outputs_download_form.select_across.name }}" id="{{ outputs_download_form.select_across.id_for_label }}">

scanpipe/templates/scanpipe/modals/projects_report_modal.html

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{{ report_form.model_name }}
1515
</div>
1616
</div>
17+
<hr>
1718
<div class="field">
1819
<label class="checkbox" for="{{ report_form.select_across.id_for_label }}">
1920
<input type="checkbox" name="{{ report_form.select_across.name }}" id="{{ report_form.select_across.id_for_label }}">

scanpipe/templates/scanpipe/modals/projects_reset_modal.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load humanize %}
12
<div class="modal" id="modal-projects-reset">
23
<div class="modal-background"></div>
34
<div class="modal-card">
@@ -17,6 +18,7 @@
1718
</p>
1819
</section>
1920
<form action="{% url 'project_action' %}" method="post" id="reset-projects-form">{% csrf_token %}
21+
<input type="hidden" name="{{ action_form.url_query.name }}" value="{{ request.GET.urlencode }}">
2022
<input type="hidden" name="action" value="reset">
2123
<footer class="modal-card-foot is-flex is-justify-content-space-between">
2224
<button class="button has-text-weight-semibold" type="reset">No, Cancel</button>

scanpipe/tests/test_views.py

-4
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@ def test_scanpipe_views_project_actions_view(self):
187187
self.assertRedirects(response, reverse("project_list"))
188188
expected = '<div class="message-body">1 projects have been delete.</div>'
189189
self.assertContains(response, expected, html=True)
190-
expected = (
191-
f'<div class="message-body">Project {random_uuid} does not exist.</div>'
192-
)
193-
self.assertContains(response, expected, html=True)
194190

195191
def test_scanpipe_views_project_action_report_view(self):
196192
url = reverse("project_action")

scanpipe/views.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ class ProjectListView(
606606

607607
def get_context_data(self, **kwargs):
608608
context = super().get_context_data(**kwargs)
609+
context["action_form"] = BaseProjectActionForm()
609610
context["archive_form"] = ArchiveProjectForm()
610611
context["outputs_download_form"] = ProjectOutputDownloadForm()
611612
context["report_form"] = ProjectReportForm()
@@ -1192,7 +1193,11 @@ def post(self, request, *args, **kwargs):
11921193
raise Http404
11931194

11941195
action_form = self.get_action_form(action)
1195-
selected_project_ids = request.POST.get("selected_ids", "").split(",")
1196+
selected_project_ids = [
1197+
project_uuid
1198+
for project_uuid in request.POST.get("selected_ids", "").split(",")
1199+
if project_uuid
1200+
]
11961201
project_qs = self.get_project_queryset(selected_project_ids, action_form)
11971202

11981203
if action == "download":
@@ -1259,8 +1264,10 @@ def get_project_queryset(selected_project_ids=None, action_form=None):
12591264
if project_filterset.is_valid():
12601265
return project_filterset.qs
12611266

1262-
selected_project_ids = selected_project_ids or []
1263-
return Project.objects.filter(uuid__in=selected_project_ids)
1267+
if selected_project_ids:
1268+
return Project.objects.filter(uuid__in=selected_project_ids)
1269+
1270+
raise Http404
12641271

12651272
def get_export_xlsx_queryset(self):
12661273
model_name = self.action_form.cleaned_data["model_name"]

0 commit comments

Comments
 (0)