Hide archived referentes on attribution view

This commit is contained in:
Claude Paroz 2016-01-19 12:16:27 +01:00
parent 5913c0588f
commit 970148e72b

View file

@ -80,11 +80,11 @@ class AttributionView(TemplateView):
def get_context_data(self, **kwargs):
context = super(AttributionView, self).get_context_data(**kwargs)
# Need 2 queries, because referents with no training item would not appear in the second query
referents = Referent.objects.all().order_by('last_name', 'first_name')
referents = Referent.objects.filter(archived=False).order_by('last_name', 'first_name')
# Populate each referent with the number of referencies done during the current school year
ref_counts = dict([(ref.id, ref.num_refs)
for ref in Referent.objects.filter(training__availability__period__end_date__gte=school_year_start()
for ref in Referent.objects.filter(archived=False, training__availability__period__end_date__gte=school_year_start()
).annotate(num_refs=Count('training'))])
for ref in referents:
ref.num_refs = ref_counts.get(ref.id, 0)