ref(stats): utilise les relations façon django
Parent
92b581857a
révision
c0368ecd2e
|
@ -689,24 +689,13 @@ class AssociationStatsPage(
|
|||
def test_func(self):
|
||||
return self.association.can_access_statistics(self.request.user)
|
||||
|
||||
def get_engagements(self):
|
||||
return models.Engagement.objects.filter(association=self.association)
|
||||
|
||||
def get_benevalos(self, year=None):
|
||||
return super().get_benevalos(year).filter(association=self.association)
|
||||
|
||||
def get_categories(self):
|
||||
categories = models.Category.objects.all()
|
||||
return categories.filter(association=self.association)
|
||||
|
||||
def get_projects(self):
|
||||
return models.Project.objects.filter(association=self.association)
|
||||
|
||||
def get_levels(self):
|
||||
return models.Level.objects.filter(association=self.association)
|
||||
if not year:
|
||||
return self.association.benevalo_set.all()
|
||||
return self.association.benevalo_set.filter(execution_date__year=year)
|
||||
|
||||
def get_engagement_count(self):
|
||||
return self.get_engagements().count()
|
||||
return self.association.engagement_set.count()
|
||||
|
||||
def get_categories_counts(self):
|
||||
data = {
|
||||
|
@ -717,7 +706,9 @@ class AssociationStatsPage(
|
|||
self.get_total_duration_for_category(None, id),
|
||||
self.get_total_distance_for_category(None, id),
|
||||
]
|
||||
for id, name in self.get_categories().values_list('id', 'name')
|
||||
for id, name in self.association.category_set.values_list(
|
||||
'id', 'name'
|
||||
)
|
||||
}
|
||||
}
|
||||
data.update(
|
||||
|
@ -729,7 +720,7 @@ class AssociationStatsPage(
|
|||
self.get_total_duration_for_category(year, id),
|
||||
self.get_total_distance_for_category(year, id),
|
||||
]
|
||||
for id, name in self.get_categories().values_list(
|
||||
for id, name in self.association.category_set.values_list(
|
||||
'id', 'name'
|
||||
)
|
||||
}
|
||||
|
@ -773,7 +764,7 @@ class AssociationStatsPage(
|
|||
) or 0
|
||||
|
||||
def get_projects_counts(self):
|
||||
if not self.get_projects():
|
||||
if not self.association.project_set.exists():
|
||||
return None
|
||||
data = {
|
||||
"total": {
|
||||
|
@ -783,7 +774,9 @@ class AssociationStatsPage(
|
|||
self.get_total_duration_for_project(None, id),
|
||||
self.get_total_distance_for_project(None, id),
|
||||
]
|
||||
for id, name in self.get_projects().values_list('id', 'name')
|
||||
for id, name in self.association.project_set.values_list(
|
||||
'id', 'name'
|
||||
)
|
||||
}
|
||||
}
|
||||
data.update(
|
||||
|
@ -795,7 +788,7 @@ class AssociationStatsPage(
|
|||
self.get_total_duration_for_project(year, id),
|
||||
self.get_total_distance_for_project(year, id),
|
||||
]
|
||||
for id, name in self.get_projects().values_list(
|
||||
for id, name in self.association.project_set.values_list(
|
||||
'id', 'name'
|
||||
)
|
||||
}
|
||||
|
@ -839,7 +832,7 @@ class AssociationStatsPage(
|
|||
) or 0
|
||||
|
||||
def get_levels_counts(self):
|
||||
if not self.get_levels():
|
||||
if not self.association.level_set.exists():
|
||||
return None
|
||||
data = {
|
||||
"total": {
|
||||
|
@ -849,7 +842,9 @@ class AssociationStatsPage(
|
|||
self.get_total_duration_for_level(None, id),
|
||||
self.get_total_distance_for_level(None, id),
|
||||
]
|
||||
for id, name in self.get_levels().values_list('id', 'name')
|
||||
for id, name in self.association.level_set.values_list(
|
||||
'id', 'name'
|
||||
)
|
||||
}
|
||||
}
|
||||
data.update(
|
||||
|
@ -861,7 +856,9 @@ class AssociationStatsPage(
|
|||
self.get_total_duration_for_level(year, id),
|
||||
self.get_total_distance_for_level(year, id),
|
||||
]
|
||||
for id, name in self.get_levels().values_list('id', 'name')
|
||||
for id, name in self.association.level_set.values_list(
|
||||
'id', 'name'
|
||||
)
|
||||
}
|
||||
for year in self.get_active_years()
|
||||
}
|
||||
|
|
Chargement…
Référencer dans un nouveau ticket