From 781ba0419a5e7bba423c922180c2c2db2327543a Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 19 Oct 2017 19:04:23 +0200 Subject: Suppressions des champs td, tp et parents --- models.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'models.py') diff --git a/models.py b/models.py index fbbf877..bfc026b 100644 --- a/models.py +++ b/models.py @@ -92,11 +92,6 @@ class Group(models.Model): mention = models.CharField(max_length=128) subgroup = models.CharField(max_length=1, verbose_name="sous-groupe", null=True) - td = models.IntegerField(verbose_name="groupe de TD", null=True) - tp = models.IntegerField(verbose_name="groupe de TP", null=True) - parent = models.ForeignKey("self", verbose_name="groupe parent", null=True, - default=None, related_name="children") - slug = models.SlugField(max_length=64, default="") hidden = models.BooleanField(verbose_name="caché", default=False) @@ -110,7 +105,7 @@ class Group(models.Model): @property def group_info(self): - return self.timetable.id, self.mention, self.subgroup, self.td, self.tp + return self.timetable.id, self.mention, self.subgroup def __str__(self): return self.name @@ -120,12 +115,12 @@ class Group(models.Model): self.name = self.celcat_name self.slug = slugify(self.name) - self.mention, self.subgroup, self.td, self.tp = parse_group(self.name) + self.mention, self.subgroup = parse_group(self.name) super(Group, self).save() class Meta: - index_together = ("mention", "subgroup", "td", "tp",) + index_together = ("mention", "subgroup",) unique_together = (("name", "timetable",), ("celcat_name", "timetable",), ("slug", "timetable",),) -- cgit v1.2.1 From e983619333a715bbc35deecf019a95addb5b6009 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 19 Oct 2017 21:38:40 +0200 Subject: Suppression des champs retirés de l’interface d’administration. La longueur du champ sous-groupe est maintenant fixée à 16. --- models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'models.py') diff --git a/models.py b/models.py index bfc026b..868cbd1 100644 --- a/models.py +++ b/models.py @@ -90,8 +90,9 @@ class Group(models.Model): verbose_name="emploi du temps") mention = models.CharField(max_length=128) - subgroup = models.CharField(max_length=1, verbose_name="sous-groupe", + subgroup = models.CharField(max_length=16, verbose_name="sous-groupe", null=True) + slug = models.SlugField(max_length=64, default="") hidden = models.BooleanField(verbose_name="caché", default=False) -- cgit v1.2.1 From 9efb1796aed00f4c7a8c9cd7e6b8a169318b1be0 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 19 Oct 2017 21:48:39 +0200 Subject: Adaptation de corresponds_to() et des tests de parsage --- models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'models.py') diff --git a/models.py b/models.py index 868cbd1..c69bec3 100644 --- a/models.py +++ b/models.py @@ -97,12 +97,15 @@ class Group(models.Model): hidden = models.BooleanField(verbose_name="caché", default=False) - def corresponds_to(self, timetable_id, mention, subgroup, td, tp): + def corresponds_to(self, timetable_id, mention, subgroup): + subgroup_corresponds = True + if self.subgroup is not None and subgroup is not None: + subgroup_corresponds = subgroup.startswith(self.subgroup) or \ + self.subgroup.startswith(subgroup) + return self.timetable.id == timetable_id and \ self.mention.startswith(mention) and \ - (self.subgroup == subgroup or self.subgroup is None) and \ - (self.td == td or self.td is None or td is None) and \ - (self.tp == tp or self.tp is None or tp is None) + subgroup_corresponds @property def group_info(self): -- cgit v1.2.1 From acc4475efca6326f59673d88865eecbef0511755 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 19 Oct 2017 22:14:28 +0200 Subject: Changement de la logique de récupération des cours pour un groupe adaptée à la nouvelle structure du modèle Group. --- models.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'models.py') diff --git a/models.py b/models.py index c69bec3..fe285ac 100644 --- a/models.py +++ b/models.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with celcatsanitizer. If not, see . +from functools import reduce + from django.db import models from django.db.models import Count, Manager, Q from django.db.models.functions import ExtractWeek, ExtractYear @@ -147,17 +149,13 @@ class Room(models.Model): class CourseManager(Manager): def get_courses_for_group(self, group, **criteria): - groups_criteria = [] - if group.subgroup is not None: - groups_criteria.append(Q(groups__subgroup__isnull=True) | \ - Q(groups__subgroup=group.subgroup)) - if group.td is not None: - groups_criteria.append(Q(groups__td__isnull=True) | Q(groups__td=group.td)) - if group.tp is not None: - groups_criteria.append(Q(groups__tp__isnull=True) | Q(groups__tp=group.tp)) + groups_criteria = reduce(lambda x, y: x | y, + [Q(groups__subgroup=group.subgroup[:i]) + for i in range(1, len(group.subgroup))]) | \ + Q(groups__subgroup__isnull=True) return self.get_queryset() \ - .filter(*groups_criteria, + .filter(groups_criteria, groups__mention=group.mention, timetable=group.timetable, **criteria) \ .order_by("begin") -- cgit v1.2.1 From 276dc9017b414404539b20f32bcc65959fd32adb Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 19 Oct 2017 22:48:16 +0200 Subject: Adaptation des vues, correction du critère de sélection des groupes --- models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models.py') diff --git a/models.py b/models.py index fe285ac..db9e262 100644 --- a/models.py +++ b/models.py @@ -151,7 +151,7 @@ class CourseManager(Manager): def get_courses_for_group(self, group, **criteria): groups_criteria = reduce(lambda x, y: x | y, [Q(groups__subgroup=group.subgroup[:i]) - for i in range(1, len(group.subgroup))]) | \ + for i in range(1, len(group.subgroup) + 1)]) | \ Q(groups__subgroup__isnull=True) return self.get_queryset() \ -- cgit v1.2.1 From 07e9a1d1e6c77d64e5c3daf0324ae751117f168e Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 20 Oct 2017 13:29:07 +0200 Subject: Modification de la requête qui sélectionne les groupes pertinents. --- models.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'models.py') diff --git a/models.py b/models.py index db9e262..74fab9e 100644 --- a/models.py +++ b/models.py @@ -16,7 +16,8 @@ from functools import reduce from django.db import models -from django.db.models import Count, Manager, Q +from django.db.models import Count, Manager, Q, Subquery +from django.db.models.expressions import OuterRef from django.db.models.functions import ExtractWeek, ExtractYear from django.utils import timezone from django.utils.text import slugify @@ -69,17 +70,13 @@ class Timetable(SlugModel): class GroupManager(Manager): - def get_relevant_children(self, group): - parent_in = self.get_queryset().filter(parent=group) - return self.get_queryset().filter(Q(parent=group) | Q(parent__in=parent_in)) \ - .annotate(children_count=Count("children")) \ - .filter(children_count=0, hidden=False) \ - .order_by("name") - - def get_relevant_groups(self, *args, **criteria): - return self.get_queryset().filter(*args, **criteria) \ - .annotate(children_count=Count("children")) \ - .filter(children_count=0, hidden=False) + def get_relevant_groups(self, timetable, *args, **criteria): + sub = Group.objects.filter(timetable=timetable,mention=OuterRef("mention"), + subgroup__startswith=OuterRef("subgroup")) \ + .order_by().values("mention").annotate(c=Count("*")).values("c") + return Group.objects.filter(*args, timetable=timetable, hidden=False, **criteria) \ + .annotate(nbsub=Subquery(sub, output_field=models.IntegerField())) \ + .filter(nbsub=1).order_by("name") class Group(models.Model): -- cgit v1.2.1