Skip to content

Commit 7ed696d

Browse files
tdruezaayushkdev
authored andcommitted
Use html_name in place of field name attribute aboutcode-org#1743 (aboutcode-org#1744)
* Use `html_name` in place of field `name` attribute aboutcode-org#1743 Signed-off-by: tdruez <[email protected]> * Apply DISTINCT in the filter_run_status aboutcode-org#1743 Signed-off-by: tdruez <[email protected]> --------- Signed-off-by: tdruez <[email protected]>
1 parent 6fde4a6 commit 7ed696d

File tree

11 files changed

+41
-23
lines changed

11 files changed

+41
-23
lines changed

scanpipe/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def filter_run_status(self, queryset, name, value):
446446
"""Filter by Run status using the `RunQuerySet` methods."""
447447
run_queryset_method = value
448448
run_queryset = getattr(Run.objects, run_queryset_method)()
449-
return queryset.filter(runs__in=run_queryset)
449+
return queryset.filter(runs__in=run_queryset).distinct()
450450

451451

452452
class JSONContainsFilter(django_filters.CharFilter):

scanpipe/templates/scanpipe/forms/project_clone_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</div>
3737
<div class="field">
3838
<label class="checkbox" for="{{ form.execute_now.id_for_label }}-clone">
39-
<input type="checkbox" name="{{ form.execute_now.name }}" id="{{ form.execute_now.id_for_label }}-clone">
39+
<input type="checkbox" name="{{ form.execute_now.html_name }}" id="{{ form.execute_now.id_for_label }}-clone">
4040
{{ form.execute_now.label }}
4141
</label>
4242
<p class="help">{{ form.execute_now.help_text }}</p>

scanpipe/templates/scanpipe/forms/project_settings_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</div>
1212
</div>
1313
<div class="field">
14-
<label class="label" for="{{ form.name.id_for_label }}">
14+
<label class="label" for="{{ form.purl.id_for_label }}">
1515
PURL
1616
</label>
1717
<div class="control">

scanpipe/templates/scanpipe/includes/search_field.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% endif %}
55
<form method="get">
66
<p class="control has-icons-left">
7-
<input class="input {{ extra_class }}" type="search" placeholder="{% if placeholder %}{{ placeholder }}{% else %}Search {{ filter.verbose_name_plural }}{% endif %}" name="{{ filter.form.search.name }}" value="{{ filter.form.search.value|default_if_none:'' }}">
7+
<input class="input {{ extra_class }}" type="search" placeholder="{% if placeholder %}{{ placeholder }}{% else %}Search {{ filter.verbose_name_plural }}{% endif %}" name="{{ filter.form.search.html_name }}" value="{{ filter.form.search.value|default_if_none:'' }}">
88
<span class="icon is-small is-left">
99
<i class="fa-solid fa-search"></i>
1010
</span>

scanpipe/templates/scanpipe/modals/projects_archive_modal.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
<hr>
3939
<div class="field include-all-field">
4040
<label class="checkbox" for="{{ archive_form.select_across.id_for_label }}">
41-
<input type="checkbox" name="{{ archive_form.select_across.name }}" id="{{ archive_form.select_across.id_for_label }}">
41+
<input type="checkbox" name="{{ archive_form.select_across.html_name }}" id="{{ archive_form.select_across.id_for_label }}">
4242
Include all {{ paginator.count|intcomma }} projects
4343
</label>
4444
<p class="help">{{ outputs_download_form.select_across.help_text }}</p>
4545
</div>
4646
</div>
4747
{% endif %}
4848
</section>
49-
<input type="hidden" name="{{ archive_form.url_query.name }}" value="{{ request.GET.urlencode }}">
49+
<input type="hidden" name="{{ archive_form.url_query.html_name }}" value="{{ request.GET.urlencode }}">
5050
<input type="hidden" name="action" value="archive">
5151
<footer class="modal-card-foot is-justify-content-flex-end">
5252
<div class="buttons">

scanpipe/templates/scanpipe/modals/projects_delete_modal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</p>
2323
</section>
2424
<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 }}">
25+
<input type="hidden" name="{{ action_form.url_query.html_name }}" value="{{ request.GET.urlencode }}">
2626
<input type="hidden" name="action" value="delete">
2727
<footer class="modal-card-foot is-justify-content-flex-end">
2828
<div class="buttons">

scanpipe/templates/scanpipe/modals/projects_download_modal.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
<hr>
2020
<div class="field">
2121
<label class="checkbox" for="{{ outputs_download_form.select_across.id_for_label }}">
22-
<input type="checkbox" name="{{ outputs_download_form.select_across.name }}" id="{{ outputs_download_form.select_across.id_for_label }}">
22+
<input type="checkbox" name="{{ outputs_download_form.select_across.html_name }}" id="{{ outputs_download_form.select_across.id_for_label }}">
2323
Include all {{ paginator.count|intcomma }} projects
2424
</label>
2525
<p class="help">{{ outputs_download_form.select_across.help_text }}</p>
2626
</div>
2727
</div>
2828
{% endif %}
2929
</section>
30-
<input type="hidden" name="{{ outputs_download_form.url_query.name }}" value="{{ request.GET.urlencode }}">
30+
<input type="hidden" name="{{ outputs_download_form.url_query.html_name }}" value="{{ request.GET.urlencode }}">
3131
<input type="hidden" name="action" value="download">
3232
<footer class="modal-card-foot is-justify-content-flex-end">
3333
<div class="buttons">

scanpipe/templates/scanpipe/modals/projects_report_modal.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
<hr>
2020
<div class="field include-all-field">
2121
<label class="checkbox" for="{{ report_form.select_across.id_for_label }}">
22-
<input type="checkbox" name="{{ report_form.select_across.name }}" id="{{ report_form.select_across.id_for_label }}">
22+
<input type="checkbox" name="{{ report_form.select_across.html_name }}" id="{{ report_form.select_across.id_for_label }}">
2323
Include all {{ paginator.count|intcomma }} projects
2424
</label>
2525
<p class="help">{{ report_form.select_across.help_text }}</p>
2626
</div>
2727
</div>
2828
{% endif %}
2929
</section>
30-
<input type="hidden" name="{{ report_form.url_query.name }}" value="{{ request.GET.urlencode }}">
30+
<input type="hidden" name="{{ report_form.url_query.html_name }}" value="{{ request.GET.urlencode }}">
3131
<input type="hidden" name="action" value="report">
3232
<footer class="modal-card-foot is-justify-content-flex-end">
3333
<div class="buttons">

scanpipe/templates/scanpipe/modals/projects_reset_modal.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
<hr>
4141
<div class="field include-all-field">
4242
<label class="checkbox" for="{{ reset_form.select_across.id_for_label }}">
43-
<input type="checkbox" name="{{ reset_form.select_across.name }}" id="{{ reset_form.select_across.id_for_label }}">
43+
<input type="checkbox" name="{{ reset_form.select_across.html_name }}" id="{{ reset_form.select_across.id_for_label }}">
4444
Include all {{ paginator.count|intcomma }} projects
4545
</label>
4646
<p class="help">{{ outputs_download_form.select_across.help_text }}</p>
4747
</div>
4848
</div>
4949
{% endif %}
5050
</section>
51-
<input type="hidden" name="{{ action_form.url_query.name }}" value="{{ request.GET.urlencode }}">
51+
<input type="hidden" name="{{ reset_form.url_query.html_name }}" value="{{ request.GET.urlencode }}">
5252
<input type="hidden" name="action" value="reset">
5353
<footer class="modal-card-foot is-justify-content-flex-end">
5454
<div class="buttons">

scanpipe/tests/test_views.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ def test_scanpipe_views_project_list_state_of_filters_in_search_form(self):
151151
expected = '<input type="hidden" name="status" value="failed">'
152152
self.assertContains(response, expected, html=True)
153153

154+
def test_scanpipe_views_project_list_filter_by_status_distinct_results(self):
155+
url = reverse("project_list")
156+
pipeline1 = self.project1.add_pipeline(pipeline_name="scan_codebase")
157+
pipeline1.set_task_stopped()
158+
pipeline2 = self.project1.add_pipeline(pipeline_name="scan_codebase")
159+
pipeline2.set_task_stopped()
160+
161+
data = {"status": "failed"}
162+
response = self.client.get(url, data=data)
163+
self.assertEqual(1, len(response.context["object_list"]))
164+
154165
@mock.patch("scanpipe.views.ProjectListView.get_paginate_by")
155166
def test_scanpipe_views_project_list_filters_exclude_page(self, mock_paginate_by):
156167
url = reverse("project_list")
@@ -174,13 +185,22 @@ def test_scanpipe_views_project_list_modal_forms_include_url_query(self):
174185
url = reverse("project_list")
175186
response = self.client.get(url)
176187

177-
expected = '<input type="hidden" name="url_query" value="">'
178-
self.assertContains(response, expected, html=True)
188+
expected_html_names = [
189+
"url_query",
190+
"download-url_query",
191+
"report-url_query",
192+
"archive-url_query",
193+
"reset-url_query",
194+
]
195+
for html_name in expected_html_names:
196+
expected = f'<input type="hidden" name="{html_name}" value="">'
197+
self.assertContains(response, expected, html=True)
179198

180199
url_query = "name=search_value"
181200
response = self.client.get(url + "?" + url_query)
182-
expected = f'<input type="hidden" name="url_query" value="{url_query}">'
183-
self.assertContains(response, expected, html=True)
201+
for html_name in expected_html_names:
202+
expected = f'<input type="hidden" name="{html_name}" value="{url_query}">'
203+
self.assertContains(response, expected, html=True)
184204

185205
@mock.patch("scanpipe.views.ProjectListView.get_paginate_by")
186206
def test_scanpipe_views_project_list_modal_forms_include_show_on_all_checked(

0 commit comments

Comments
 (0)