Reformat portal/views.py

This commit is contained in:
2025-04-30 22:52:51 +02:00
parent 2e06e94fde
commit 40f42a9ee9

View File

@@ -490,11 +490,13 @@ class Manufacturers(GetData):
item_type = "manufacturer" item_type = "manufacturer"
def get_data(self, request): def get_data(self, request):
return Manufacturer.objects.filter( return (
self.filter Manufacturer.objects.filter(self.filter)
).annotate( .annotate(
num_items=Count("rollingstock") + Count("rollingclass"), num_items=Count("rollingstock") + Count("rollingclass"),
).order_by("name") )
.order_by("name")
)
# overload get method to filter by category # overload get method to filter by category
def get(self, request, category, page=1): def get(self, request, category, page=1):
@@ -510,19 +512,23 @@ class Companies(GetData):
item_type = "company" item_type = "company"
def get_data(self, request): def get_data(self, request):
return Company.objects.annotate( return (
Company.objects.annotate(
num_rollingstock=( num_rollingstock=(
Count( Count(
"rollingclass__rolling_class", "rollingclass__rolling_class",
filter=Q( filter=Q(
rollingclass__rolling_class__in=( rollingclass__rolling_class__in=(
RollingStock.objects.get_published(request.user) RollingStock.objects.get_published(
request.user
)
) )
), ),
distinct=True distinct=True,
) )
) )
).annotate( )
.annotate(
num_consists=( num_consists=(
Count( Count(
"consist", "consist",
@@ -531,12 +537,13 @@ class Companies(GetData):
Consist.objects.get_published(request.user) Consist.objects.get_published(request.user)
), ),
), ),
distinct=True distinct=True,
) )
) )
).annotate( )
num_items=F("num_rollingstock") + F("num_consists") .annotate(num_items=F("num_rollingstock") + F("num_consists"))
).order_by("name") .order_by("name")
)
class Scales(GetData): class Scales(GetData):
@@ -614,7 +621,7 @@ class GetBookCatalog(View):
"book": book, "book": book,
"documents": documents, "documents": documents,
"properties": properties, "properties": properties,
"type": selector "type": selector,
}, },
) )