Skip to content

Commit 727bbba

Browse files
committed
Add support for all models in XLSX report #1524
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 611520e commit 727bbba

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ v34.9.4 (unreleased)
3535
at once from a directory containing input files.
3636
https://github.com/aboutcode-org/scancode.io/issues/1437
3737

38+
- Add a "TODOS" sheet containing on REQUIRES_REVIEW resources in XLSX.
39+
https://github.com/aboutcode-org/scancode.io/issues/1524
40+
3841
v34.9.3 (2024-12-31)
3942
--------------------
4043

scanpipe/forms.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,67 @@ class ProjectOutputDownloadForm(forms.Form):
272272
)
273273

274274

275+
class ProjectReportForm(forms.Form):
276+
model_name = forms.ChoiceField(
277+
label="Choose the object type to include in the XLSX file",
278+
choices=[
279+
("discoveredpackage", "Packages"),
280+
("discovereddependency", "Dependencies"),
281+
("codebaseresource", "Resources"),
282+
("codebaserelation", "Relations"),
283+
("projectmessage", "Messages"),
284+
("todos", "TODOs"),
285+
],
286+
required=True,
287+
initial="discoveredpackage",
288+
widget=forms.RadioSelect,
289+
)
290+
291+
# TODO: Remove duplication
292+
def get_queryset(self):
293+
from scanpipe.models import CodebaseRelation
294+
from scanpipe.models import CodebaseResource
295+
from scanpipe.models import DiscoveredDependency
296+
from scanpipe.models import DiscoveredPackage
297+
from scanpipe.models import ProjectMessage
298+
from scanpipe.pipes import flag
299+
from scanpipe.pipes.output import TODO_FIELDS
300+
301+
querysets = {
302+
"discoveredpackage": (
303+
DiscoveredPackage.objects.order_by(
304+
"type",
305+
"namespace",
306+
"name",
307+
"version",
308+
)
309+
),
310+
"discovereddependency": (
311+
DiscoveredDependency.objects.prefetch_for_serializer().order_by(
312+
"type",
313+
"namespace",
314+
"name",
315+
"version",
316+
"datasource_id",
317+
)
318+
),
319+
"codebaseresource": (
320+
CodebaseResource.objects.without_symlinks().prefetch_for_serializer()
321+
),
322+
"codebaserelation": (
323+
CodebaseRelation.objects.select_related("from_resource", "to_resource")
324+
),
325+
"projectmessage": ProjectMessage.objects.all(),
326+
"todos": (
327+
CodebaseResource.objects.files()
328+
.status(flag.REQUIRES_REVIEW)
329+
# .only(*TODO_FIELDS)
330+
),
331+
}
332+
333+
return querysets.get(self.cleaned_data["model_name"])
334+
335+
275336
class ListTextarea(forms.CharField):
276337
"""
277338
A Django form field that displays as a textarea and converts each line of input

scanpipe/pipes/output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_todos_data(project):
116116
"""Return the list of Resources that requires review."""
117117
return (
118118
project.codebaseresources.files()
119-
.filter(status=flag.REQUIRES_REVIEW)
119+
.status(flag.REQUIRES_REVIEW)
120120
.values(*TODO_FIELDS)
121121
)
122122

scanpipe/templates/scanpipe/modals/projects_report_modal.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
</header>
88
<form action="{% url 'project_action' %}" method="post" id="report-projects-form">{% csrf_token %}
99
<section class="modal-card-body">
10-
<div class="notification is-info has-text-weight-semibold">
11-
All the packages for the selected projects will be included in an XLSX report.
12-
</div>
10+
<ul class="mb-3">
11+
{{ report_form.as_ul }}
12+
</ul>
1313
</section>
1414
<input type="hidden" name="action" value="report">
1515
<footer class="modal-card-foot is-flex is-justify-content-space-between">

scanpipe/views.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
from scanpipe.forms import ProjectCloneForm
8282
from scanpipe.forms import ProjectForm
8383
from scanpipe.forms import ProjectOutputDownloadForm
84+
from scanpipe.forms import ProjectReportForm
8485
from scanpipe.forms import ProjectSettingsForm
8586
from scanpipe.models import CodebaseRelation
8687
from scanpipe.models import CodebaseResource
@@ -598,6 +599,7 @@ def get_context_data(self, **kwargs):
598599
context = super().get_context_data(**kwargs)
599600
context["archive_form"] = ArchiveProjectForm()
600601
context["outputs_download_form"] = ProjectOutputDownloadForm()
602+
context["report_form"] = ProjectReportForm()
601603
return context
602604

603605
def get_queryset(self):
@@ -1220,10 +1222,13 @@ def get_projects_queryset(self):
12201222
return Project.objects.filter(pk__in=self.selected_project_ids)
12211223

12221224
def get_export_xlsx_queryset(self):
1225+
report_form = ProjectReportForm(self.request.POST)
1226+
if not report_form.is_valid():
1227+
return HttpResponseRedirect(self.success_url)
1228+
1229+
queryset = report_form.get_queryset()
12231230
projects = self.get_projects_queryset()
1224-
packages = DiscoveredPackage.objects.filter(project__in=projects)
1225-
packages = packages.select_related("project")
1226-
return packages
1231+
return queryset.filter(project__in=projects)
12271232

12281233
def get_export_xlsx_extra_fields(self):
12291234
return ["project"]

0 commit comments

Comments
 (0)