Skip to content

Commit 5c080af

Browse files
committed
Filter by project name
1 parent 00b4a9e commit 5c080af

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

mise.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ run = "ruff check"
104104
description = "Check code formatting and linting"
105105

106106
[tasks.format]
107-
run = "ruff format"
107+
run = ["ruff format", "ruff check --fix"]
108108
description = "Format the code"
109109

110110
[tasks.clean]

src/ralph/admin/filters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,10 @@ def register_custom_filters():
601601
This function is called in AppConfig.ready() (ralph.admin.apps).
602602
"""
603603
field_filter_mapper = [
604-
(lambda f: bool(f.choices), ChoicesListFilter),
604+
(
605+
lambda f: bool(f.choices if hasattr(f, "choices") else False),
606+
ChoicesListFilter,
607+
),
605608
(
606609
lambda f: isinstance(f, (models.DecimalField, models.IntegerField)),
607610
NumberListFilter,
@@ -631,6 +634,5 @@ def register_custom_filters():
631634
),
632635
(lambda f: isinstance(f, TaggableManager), TagsListFilter),
633636
]
634-
635637
for func, filter_class in field_filter_mapper:
636638
FieldListFilter.register(func, filter_class, take_priority=True)

src/ralph/virtual/admin.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,16 @@ class CloudHostAdmin(
278278
"get_tags",
279279
]
280280
list_filter_prefix = [BaseObjectHostnameFilter]
281-
list_filter_postfix = ["cloudprovider", "cloudflavor", TagsListFilter, "hypervisor"]
281+
list_filter_postfix = [
282+
"parent__cloudproject__name",
283+
"cloudprovider",
284+
"cloudflavor",
285+
TagsListFilter,
286+
"hypervisor",
287+
]
282288
list_filter = generate_list_filter_with_common_fields(
283289
list_filter_prefix, list_filter_postfix
284-
)
290+
) # + ["parent__cloudproject__name"]
285291
list_select_related = [
286292
"cloudflavor",
287293
"cloudprovider",
@@ -356,7 +362,14 @@ def get_queryset(self, request):
356362
super()
357363
.get_queryset(request)
358364
.filter(visibility_scope_filter(request.user))
359-
.prefetch_related("tags", "ethernet_set__ipaddress")
365+
.polymorphic_prefetch_related(
366+
CloudHost=[
367+
"tags",
368+
"ethernet_set__ipaddress",
369+
"cloudflavor__virtualcomponent_set__model",
370+
"virtualcomponent_set__model",
371+
]
372+
)
360373
)
361374

362375
def has_delete_permission(self, request, obj=None):

src/ralph/virtual/api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ class CloudHostViewSet(BaseObjectViewSetMixin, RalphAPIViewSet):
274274
"service_env__service__id",
275275
]
276276

277+
extended_filter_fields = {
278+
"cloudproject__name": ["parent__cloudproject__name"],
279+
"cloudproject__id": ["parent__cloudproject__id"],
280+
}
281+
277282
def get_queryset(self):
278283
return super().get_queryset().filter(visibility_scope_filter(self.request.user))
279284

0 commit comments

Comments
 (0)