Skip to content

Commit fecc9a6

Browse files
authored
Fix the ProductDependencyAdmin form (#287)
Signed-off-by: tdruez <[email protected]>
1 parent d4aa383 commit fecc9a6

File tree

5 files changed

+64
-14
lines changed

5 files changed

+64
-14
lines changed

component_catalog/admin.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,17 @@ class PackageAdmin(
774774
"get_dataspace",
775775
)
776776
list_display_links = ("identifier",)
777-
search_fields = ("filename", "download_url", "project")
777+
search_fields = (
778+
"type",
779+
"namespace",
780+
"name",
781+
"version",
782+
"filename",
783+
"download_url",
784+
"sha1",
785+
"md5",
786+
"project",
787+
)
778788
ordering = ("-last_modified_date",)
779789
list_filter = (
780790
("component", HierarchyRelatedLookupListFilter),
@@ -912,6 +922,7 @@ def get_queryset(self, request):
912922
return (
913923
super()
914924
.get_queryset(request)
925+
.annotate_sortable_identifier()
915926
.select_related(
916927
"usage_policy",
917928
)
@@ -938,6 +949,16 @@ def get_urls(self):
938949

939950
return urls + super().get_urls()
940951

952+
def get_search_results(self, request, queryset, search_term):
953+
"""Add searching on provided PackageURL identifier."""
954+
use_distinct = False
955+
956+
is_purl = "/" in search_term
957+
if is_purl:
958+
return queryset.for_package_url(search_term), use_distinct
959+
960+
return super().get_search_results(request, queryset, search_term)
961+
941962
def changeform_view(self, request, object_id=None, form_url="", extra_context=None):
942963
"""
943964
Add the `show_save_and_collect_data` in the context.
@@ -1053,6 +1074,10 @@ def inferred_url(self, obj):
10531074
return urlize_target_blank(inferred_url)
10541075
return ""
10551076

1077+
@admin.display(ordering="sortable_identifier")
1078+
def identifier(self, obj):
1079+
return obj.identifier
1080+
10561081
def save_formset(self, request, form, formset, change):
10571082
"""
10581083
Update the completion_level on the related Component at the end of the saving process.

dejacode/static/css/dejacode_bootstrap.css

+10-8
Original file line numberDiff line numberDiff line change
@@ -426,19 +426,22 @@ table.vulnerabilities-table .column-summary {
426426

427427
/* -- Dependency tab -- */
428428
#tab_dependencies .column-for_package {
429-
width: 250px;
429+
min-width: 300px;
430430
}
431431
#tab_dependencies .column-resolved_to_package {
432-
width: 250px;
432+
min-width: 300px;
433433
}
434434
#tab_dependencies .column-is_runtime {
435-
width: 100px;
435+
width: 85px;
436+
font-size: 0.75rem;
436437
}
437-
#tab_dependencies .column-column-is_optional {
438-
width: 100px;
438+
#tab_dependencies .column-is_optional {
439+
width: 85px;
440+
font-size: 0.75rem;
439441
}
440-
#tab_dependencies .column-column-is_pinned {
441-
width: 88px;
442+
#tab_dependencies .column-is_pinned {
443+
width: 80px;
444+
font-size: 0.75rem;
442445
}
443446

444447
/* -- Package Details -- */
@@ -661,7 +664,6 @@ td.sub-header {
661664
.table thead tr th a.sort:hover {
662665
color: #ccc;
663666
text-decoration: none;
664-
margin-left: 0;
665667
}
666668
.table thead tr th a.sort.active {
667669
color: var(--bs-body-color);

dje/templates/includes/object_list_table_header.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load i18n %}
2+
{% spaceless %}
23
<thead class="text-break-initial">
34
<tr>
45
{% if is_grouping_active %}
@@ -27,10 +28,10 @@
2728
{% with query_no_sort=filter.get_query_no_sort %}
2829
{% if filter.form.sort.data and header.field_name in filter.form.sort.data.0 %}
2930
{# The sort for this field is currently active #}
30-
<a href="?{% if query_no_sort %}{{ query_no_sort }}&{% endif %}{% if tab_id %}{{ tab_id }}-{% endif %}sort={% if '-' not in filter.form.sort.data.0 %}-{% endif %}{{ header.field_name }}{% if tab_id %}#{{ tab_id }}{% endif %}" class="sort active" aria-label="Sort"><i class="fas fa-sort-{% if '-' not in filter.form.sort.data.0 %}up{% else %}down{% endif %}"></i></a>
31+
<a href="?{% if query_no_sort %}{{ query_no_sort }}&{% endif %}{% if tab_id %}{{ tab_id }}-{% endif %}sort={% if '-' not in filter.form.sort.data.0 %}-{% endif %}{{ header.field_name }}{% if tab_id %}#{{ tab_id }}{% endif %}" class="sort active ms-1" aria-label="Sort"><i class="fas fa-sort-{% if '-' not in filter.form.sort.data.0 %}up{% else %}down{% endif %}"></i></a>
3132
{% else %}
3233
{# The sort for this field is NOT active #}
33-
<a href="?{% if query_no_sort %}{{ query_no_sort }}&{% endif %}{% if tab_id %}{{ tab_id }}-{% endif %}sort={{ header.field_name }}{% if tab_id %}#{{ tab_id }}{% endif %}" class="sort" aria-label="Sort"><i class="fas fa-sort"></i></a>
34+
<a href="?{% if query_no_sort %}{{ query_no_sort }}&{% endif %}{% if tab_id %}{{ tab_id }}-{% endif %}sort={{ header.field_name }}{% if tab_id %}#{{ tab_id }}{% endif %}" class="sort ms-1" aria-label="Sort"><i class="fas fa-sort"></i></a>
3435
{% endif %}
3536
{% endwith %}
3637
{% endif %}
@@ -40,4 +41,5 @@
4041
<th class="column-action" scope="col"></th>
4142
{% endif %}
4243
</tr>
43-
</thead>
44+
</thead>
45+
{% endspaceless %}

product_portfolio/admin.py

+23
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,28 @@ class ProductDependencyAdmin(ProductRelatedAdminMixin):
814814
"is_direct",
815815
"get_dataspace",
816816
)
817+
fieldsets = (
818+
(None, {"fields": ["product"]}),
819+
(
820+
None,
821+
{
822+
"fields": [
823+
"dependency_uid",
824+
"for_package",
825+
"resolved_to_package",
826+
"declared_dependency",
827+
"extracted_requirement",
828+
"scope",
829+
"datasource_id",
830+
"is_runtime",
831+
"is_optional",
832+
"is_pinned",
833+
"is_direct",
834+
]
835+
},
836+
),
837+
get_additional_information_fieldset(),
838+
)
817839
raw_id_fields = [
818840
"product",
819841
"for_package",
@@ -832,6 +854,7 @@ class ProductDependencyAdmin(ProductRelatedAdminMixin):
832854
ReportingQueryListFilter,
833855
)
834856
actions_to_remove = ["copy_to", "compare_with"]
857+
form = ProductRelatedAdminForm
835858

836859
def get_queryset(self, request):
837860
return (

product_portfolio/models.py

-2
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,6 @@ class ProductDependency(HistoryFieldsMixin, DataspacedModel):
16021602
related_name="declared_dependencies",
16031603
help_text=_("The package that declares this dependency."),
16041604
on_delete=models.CASCADE,
1605-
editable=False,
16061605
blank=True,
16071606
null=True,
16081607
)
@@ -1614,7 +1613,6 @@ class ProductDependency(HistoryFieldsMixin, DataspacedModel):
16141613
"If empty, it indicates the dependency is unresolved."
16151614
),
16161615
on_delete=models.SET_NULL,
1617-
editable=False,
16181616
blank=True,
16191617
null=True,
16201618
)

0 commit comments

Comments
 (0)