Skip to content

Commit

Permalink
Refine the models rendering #1524
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jan 16, 2025
1 parent 750a4c5 commit 2292804
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 14 deletions.
36 changes: 29 additions & 7 deletions scanpipe/templates/scanpipe/modals/projects_archive_modal.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load humanize %}
<div class="modal" id="modal-projects-archive">
<div class="modal-background"></div>
<div class="modal-card">
Expand All @@ -9,18 +10,39 @@
<section class="modal-card-body">
<div class="notification is-warning has-text-weight-semibold">
The selected projects will be marked as archived and will become read-only.
Those will not appear in the project list by default anymore.
Those will not appear in the project list by default anymore.<br>
</div>
<p class="mb-2">
The selected directories will be removed:
</p>
<ul class="mb-5">
{{ archive_form.as_ul }}
</ul>
<p>
Are you sure you want to do this?
</p>
<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>
<hr>
<div class="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>
</section>
<input type="hidden" name="{{ archive_form.url_query.name }}" value="{{ request.GET.urlencode }}">
<input type="hidden" name="action" value="archive">
<footer class="modal-card-foot is-flex is-justify-content-space-between">
<button class="button has-text-weight-semibold" type="reset">No, Cancel</button>
Expand Down
2 changes: 2 additions & 0 deletions scanpipe/templates/scanpipe/modals/projects_delete_modal.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load humanize %}
<div class="modal" id="modal-projects-delete">
<div class="modal-background"></div>
<div class="modal-card">
Expand All @@ -21,6 +22,7 @@
</p>
</section>
<form action="{% url 'project_action' %}" method="post" id="delete-projects-form">{% csrf_token %}
<input type="hidden" name="{{ action_form.url_query.name }}" value="{{ request.GET.urlencode }}">
<input type="hidden" name="action" value="delete">
<footer class="modal-card-foot is-flex is-justify-content-space-between">
<button class="button has-text-weight-semibold" type="reset">No, Cancel</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{{ outputs_download_form.output_format }}
</div>
</div>
<hr>
<div class="field">
<label class="checkbox" for="{{ outputs_download_form.select_across.id_for_label }}">
<input type="checkbox" name="{{ outputs_download_form.select_across.name }}" id="{{ outputs_download_form.select_across.id_for_label }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{{ report_form.model_name }}
</div>
</div>
<hr>
<div class="field">
<label class="checkbox" for="{{ report_form.select_across.id_for_label }}">
<input type="checkbox" name="{{ report_form.select_across.name }}" id="{{ report_form.select_across.id_for_label }}">
Expand Down
2 changes: 2 additions & 0 deletions scanpipe/templates/scanpipe/modals/projects_reset_modal.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load humanize %}
<div class="modal" id="modal-projects-reset">
<div class="modal-background"></div>
<div class="modal-card">
Expand All @@ -17,6 +18,7 @@
</p>
</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 }}">
<input type="hidden" name="action" value="reset">
<footer class="modal-card-foot is-flex is-justify-content-space-between">
<button class="button has-text-weight-semibold" type="reset">No, Cancel</button>
Expand Down
4 changes: 0 additions & 4 deletions scanpipe/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ def test_scanpipe_views_project_actions_view(self):
self.assertRedirects(response, reverse("project_list"))
expected = '<div class="message-body">1 projects have been delete.</div>'
self.assertContains(response, expected, html=True)
expected = (
f'<div class="message-body">Project {random_uuid} does not exist.</div>'
)
self.assertContains(response, expected, html=True)

def test_scanpipe_views_project_action_report_view(self):
url = reverse("project_action")
Expand Down
13 changes: 10 additions & 3 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ class ProjectListView(

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["action_form"] = BaseProjectActionForm()
context["archive_form"] = ArchiveProjectForm()
context["outputs_download_form"] = ProjectOutputDownloadForm()
context["report_form"] = ProjectReportForm()
Expand Down Expand Up @@ -1192,7 +1193,11 @@ def post(self, request, *args, **kwargs):
raise Http404

action_form = self.get_action_form(action)
selected_project_ids = request.POST.get("selected_ids", "").split(",")
selected_project_ids = [
project_uuid
for project_uuid in request.POST.get("selected_ids", "").split(",")
if project_uuid
]
project_qs = self.get_project_queryset(selected_project_ids, action_form)

if action == "download":
Expand Down Expand Up @@ -1259,8 +1264,10 @@ def get_project_queryset(selected_project_ids=None, action_form=None):
if project_filterset.is_valid():
return project_filterset.qs

selected_project_ids = selected_project_ids or []
return Project.objects.filter(uuid__in=selected_project_ids)
if selected_project_ids:
return Project.objects.filter(uuid__in=selected_project_ids)

raise Http404

def get_export_xlsx_queryset(self):
model_name = self.action_form.cleaned_data["model_name"]
Expand Down

0 comments on commit 2292804

Please sign in to comment.