Skip to content

Commit 6b9b437

Browse files
committed
Refine the implementation of select_across #1524
Signed-off-by: tdruez <[email protected]>
1 parent 2714268 commit 6b9b437

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

scanpipe/forms.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,20 @@ def save(self, project):
238238
return input_source
239239

240240

241+
class BaseProjectActionForm(forms.Form):
242+
select_across = forms.BooleanField(
243+
label="",
244+
required=False,
245+
initial=0,
246+
help_text="All project matching current search and filters will be included.",
247+
)
248+
url_query = forms.CharField(
249+
widget=forms.HiddenInput,
250+
required=False,
251+
help_text="Stores the current URL filters.",
252+
)
253+
254+
241255
class ArchiveProjectForm(forms.Form):
242256
remove_input = forms.BooleanField(
243257
label="Remove inputs",
@@ -256,7 +270,7 @@ class ArchiveProjectForm(forms.Form):
256270
)
257271

258272

259-
class ProjectOutputDownloadForm(forms.Form):
273+
class ProjectOutputDownloadForm(BaseProjectActionForm):
260274
output_format = forms.ChoiceField(
261275
label="Choose the output format to include in the ZIP file",
262276
choices=[
@@ -272,7 +286,7 @@ class ProjectOutputDownloadForm(forms.Form):
272286
)
273287

274288

275-
class ProjectReportForm(forms.Form):
289+
class ProjectReportForm(BaseProjectActionForm):
276290
model_name = forms.ChoiceField(
277291
label="Choose the object type to include in the XLSX file",
278292
choices=[
@@ -287,12 +301,6 @@ class ProjectReportForm(forms.Form):
287301
initial="discoveredpackage",
288302
widget=forms.RadioSelect,
289303
)
290-
select_across = forms.BooleanField(
291-
label="",
292-
required=False,
293-
initial=0,
294-
help_text="All project matching current search and filters will be included.",
295-
)
296304

297305

298306
class ListTextarea(forms.CharField):

scanpipe/pipes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def collect_and_create_codebase_resources(project, batch_size=5000):
113113
Collect and create codebase resources including the "to/" and "from/" context using
114114
the resource tag field.
115115
116-
The default ``batch_size`` can be overriden, although the benefits of a value
116+
The default ``batch_size`` can be overridden, although the benefits of a value
117117
greater than 5000 objects are usually not significant.
118118
"""
119119
model_class = CodebaseResource

scanpipe/templates/scanpipe/modals/projects_download_modal.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load humanize %}
12
<div class="modal" id="modal-projects-download">
23
<div class="modal-background"></div>
34
<div class="modal-card">
@@ -7,10 +8,21 @@
78
</header>
89
<form action="{% url 'project_action' %}" method="post" id="download-projects-form">{% csrf_token %}
910
<section class="modal-card-body">
10-
<ul class="mb-3">
11-
{{ outputs_download_form.as_ul }}
12-
</ul>
11+
<div class="field">
12+
<label class="label">{{ outputs_download_form.output_format.label }}</label>
13+
<div class="control">
14+
{{ outputs_download_form.output_format }}
15+
</div>
16+
</div>
17+
<div class="field">
18+
<label class="checkbox" for="{{ outputs_download_form.select_across.id_for_label }}">
19+
<input type="checkbox" name="{{ outputs_download_form.select_across.name }}" id="{{ outputs_download_form.select_across.id_for_label }}">
20+
Include all {{ paginator.count|intcomma }} projects
21+
</label>
22+
<p class="help">{{ outputs_download_form.select_across.help_text }}</p>
23+
</div>
1324
</section>
25+
<input type="hidden" name="{{ outputs_download_form.url_query.name }}" value="{{ request.GET.urlencode }}">
1426
<input type="hidden" name="action" value="download">
1527
<footer class="modal-card-foot is-flex is-justify-content-space-between">
1628
<button class="button has-text-weight-semibold" type="reset">Cancel</button>

scanpipe/templates/scanpipe/modals/projects_report_modal.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<p class="help">{{ report_form.select_across.help_text }}</p>
2323
</div>
2424
</section>
25+
<input type="hidden" name="{{ report_form.url_query.name }}" value="{{ request.GET.urlencode }}">
2526
<input type="hidden" name="action" value="report">
2627
<footer class="modal-card-foot is-flex is-justify-content-space-between">
2728
<button class="button has-text-weight-semibold" type="reset">Cancel</button>

scanpipe/views.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from collections import Counter
2929
from contextlib import suppress
3030
from pathlib import Path
31-
from urllib.parse import urlparse
3231

3332
from django.apps import apps
3433
from django.conf import settings
@@ -1234,22 +1233,23 @@ def export_xlsx_file_response(self):
12341233

12351234
return super().export_xlsx_file_response()
12361235

1237-
def get_projects_queryset(self, select_across=False):
1238-
if select_across:
1239-
# TODO: We could store the previous URL in the Action form instead
1240-
if referrer_url := self.request.META.get("HTTP_REFERER", ""):
1241-
url_query = urlparse(referrer_url).query
1242-
project_filterset = ProjectFilterSet(data=QueryDict(url_query))
1243-
if project_filterset.is_valid():
1244-
return project_filterset.qs
1236+
def get_projects_queryset(self, select_across=False, url_query=""):
1237+
if select_across and url_query:
1238+
project_filterset = ProjectFilterSet(data=QueryDict(url_query))
1239+
if project_filterset.is_valid():
1240+
return project_filterset.qs
12451241

12461242
return Project.objects.filter(pk__in=self.selected_project_ids)
12471243

12481244
def get_export_xlsx_queryset(self):
12491245
model_name = self.report_form.cleaned_data["model_name"]
1246+
# TODO: Make th 2 following fields available in all actions
12501247
select_across = self.report_form.cleaned_data["select_across"]
1248+
url_query = self.report_form.cleaned_data["url_query"]
12511249
queryset = output.get_queryset(project=None, model_name=model_name)
1252-
projects = self.get_projects_queryset(select_across=select_across)
1250+
projects = self.get_projects_queryset(
1251+
select_across=select_across, url_query=url_query
1252+
)
12531253
return queryset.filter(project__in=projects)
12541254

12551255
def get_export_xlsx_prepend_fields(self):

0 commit comments

Comments
 (0)