Commit 93155b4c authored by Julien Palard's avatar Julien Palard
Browse files

Have 3.5 in production, have to use OrderedDict here.

parent cb701231
from collections import OrderedDict
from itertools import groupby
from django.contrib.auth.decorators import login_required
......@@ -139,23 +140,31 @@ class StatsDetailView(UserPassesTestMixin, DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["stats"] = {
user.username: [
{
"is_tried": exercice.nb_anwser > 0,
"is_valid": exercice.nb_valid_anwser > 0,
"exercice_id": exercice.id,
}
for exercice in Exercise.objects.annotate(
nb_anwser=Count("answers", filter=Q(answers__user_id=user.id)),
nb_valid_anwser=Count(
"answers",
filter=Q(answers__is_valid=True) & Q(answers__user_id=user.id),
),
).order_by("position")
context["stats"] = OrderedDict(
[
(
user.username,
[
{
"is_tried": exercice.nb_anwser > 0,
"is_valid": exercice.nb_valid_anwser > 0,
"exercice_id": exercice.id,
}
for exercice in Exercise.objects.annotate(
nb_anwser=Count(
"answers", filter=Q(answers__user_id=user.id)
),
nb_valid_anwser=Count(
"answers",
filter=Q(answers__is_valid=True)
& Q(answers__user_id=user.id),
),
).order_by("position")
],
)
for user in User.objects.filter(groups=context["object"]).order_by(
"username"
)
]
for user in User.objects.filter(groups=context["object"]).order_by(
"username"
)
}
)
return context
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