Commit 5ad9cc0e authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Merge branch '66-lenteur-de-events' into 'master'

Resolve "Lenteur de /events/"

Closes #66

See merge request !63
parents 765baa25 f838738c
......@@ -90,14 +90,35 @@ class Event(models.Model):
def to_come(user):
events = [event for event in Event.objects.filter(
Q(inscriptions__user=user) | Q(private=False)
.annotate(reg_nb=(Count('inscriptions', distinct=True) + Count('extern_inscriptions', distinct=True) + Count('invitations', distinct=True)))
.extra(select={'ins': "(SELECT COUNT(*) FROM events_inscription WHERE AND events_inscription.user_id=%d)" %})]
return [(event.ins, event) for event in events]
events = list(
Q(inscriptions__user=user) | Q(private=False)
# Pour savoir si l'utilisateur actuel est inscrit
'ins': "(SELECT COUNT(*) FROM events_inscription "
"AND events_inscription.user_id=%d)" %
events_by_id = { [e, 0] for e in events}
counts_ins = Event.objects.filter(pk__in=events_by_id.keys()).annotate(ins_cnt=Count('inscriptions'))
counts_ext = Event.objects.filter(pk__in=events_by_id.keys()).annotate(ext_cnt=Count('extern_inscriptions'))
counts_inv = Event.objects.filter(pk__in=events_by_id.keys()).annotate(inv_cnt=Count('invitations'))
for e in counts_ins:
events_by_id[][1] += e.ins_cnt
for e in counts_ext:
events_by_id[][1] += e.ext_cnt
for e in counts_inv:
events_by_id[][1] += e.inv_cnt
for e, cnt in events_by_id.values():
e.reg_nb = cnt
return [(e.ins, e) for e in events]
def formulas_json(self):
res = { "{} <br>(Cotisant: {}€ / Non cotisant: {}€)".format(, f.price_contributor, f.price_non_contributor) for f in self.formulas.all()}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment