From 600ba15faa13e7aa71a97fca24557ee2931002ae Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 13 Sep 2021 19:02:54 +0200 Subject: [PATCH] [WEI] Display suggested 1A number in a bus in repartition view Signed-off-by: Yohann D'ANELLO --- apps/wei/models.py | 8 ++++++++ apps/wei/templates/wei/attribute_bus_1A.html | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/wei/models.py b/apps/wei/models.py index 7ab56f57..6b7272b4 100644 --- a/apps/wei/models.py +++ b/apps/wei/models.py @@ -7,6 +7,7 @@ from datetime import date from django.conf import settings from django.contrib.auth.models import User from django.db import models +from django.db.models import Q from django.utils.translation import gettext_lazy as _ from phonenumber_field.modelfields import PhoneNumberField from member.models import Club, Membership @@ -98,6 +99,13 @@ class Bus(models.Model): """ self.information_json = json.dumps(information, indent=2) + @property + def suggested_first_year(self): + registrations = WEIRegistration.objects.filter(Q(membership__isnull=True) | Q(membership__bus__isnull=True), + first_year=True, wei=self.wei) + registrations = [r for r in registrations if 'selected_bus_pk' in r.information] + return sum(1 for r in registrations if r.information['selected_bus_pk'] == self.pk) + def __str__(self): return self.name diff --git a/apps/wei/templates/wei/attribute_bus_1A.html b/apps/wei/templates/wei/attribute_bus_1A.html index 32cc27dd..3305981b 100644 --- a/apps/wei/templates/wei/attribute_bus_1A.html +++ b/apps/wei/templates/wei/attribute_bus_1A.html @@ -50,7 +50,7 @@ {% for bus, score in survey.ordered_buses %} {% endfor %}