diff options
-rw-r--r-- | admin.py | 2 | ||||
-rw-r--r-- | models.py | 8 | ||||
-rw-r--r-- | utils.py | 4 | ||||
-rw-r--r-- | views.py | 4 |
4 files changed, 13 insertions, 5 deletions
@@ -34,7 +34,7 @@ class LastUpdateAdmin(admin.ModelAdmin): class GroupAdmin(admin.ModelAdmin): fieldsets = ( (None, {"fields": ("name", "celcat_name", "timetable",)}), - ("Groupes", {"fields": ("mention", "subgroup", "td", "tp",)}),) + ("Groupes", {"fields": ("mention", "subgroup", "td", "tp", "parent_group",)}),) list_display = ("name", "timetable",) list_filter = ("timetable__name",) readonly_fields = ("celcat_name", "mention", "subgroup", "td", "tp",) @@ -56,7 +56,14 @@ class LastUpdate(models.Model): verbose_name_plural = "dernières mises à jour" +class GroupManager(Manager): + def get_relevant_groups(self): + return self.get_queryset().annotate(children_count=Count("children")).filter(children_count=0) + + class Group(models.Model): + objects = GroupManager() + name = models.CharField(max_length=255, verbose_name="nom") celcat_name = models.CharField(max_length=255, verbose_name="nom dans Celcat") timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps") @@ -65,6 +72,7 @@ class Group(models.Model): 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_group = models.ForeignKey("self", verbose_name="groupe parent", null=True, default=None, related_name="children") slug = models.SlugField(max_length=64, default="") @@ -54,8 +54,8 @@ def parse_group(name): # ([\w ]+?) correspond à au moins un caractère # (\s* zéro, un ou plusieurs espaces # (((CM)(\w))| correspond à CM suivi d'une lettre ou... - # ((TD)(\w)(\d))| ... à TD suivi d'une lettre et d'un chiffre ou... - # ((TP)(\w)(\d)(\d))) ... à TP suivi d'une lettre et de deux chiffres + # ((TD)(\w)(\d))| ... à TD suivi d’une lettre et d'un chiffre ou... + # ((TP)(\w)(\d)(\d))) ... à TP suivi d’une lettre et de deux chiffres # )? groupe optionel # $ fin de la ligne group_regex = re.compile("^([\w ]+?)(\s*(((CM)(\w))|((TD)(\w)(\d))|((TP)(\w)(\d)(\d))))?$") @@ -24,8 +24,8 @@ from .models import Timetable, LastUpdate, Group, Subscription, Course from .utils import get_current_week, get_week, group_courses def index(request): - timetables = Timetable.objects.all().order_by("name") - groups = Group.objects.filter(tp__isnull=False).order_by("name") + timetables = Timetable.objects.order_by("name") + groups = Group.objects.get_relevant_groups().order_by("name") year, week = get_current_week() start, _ = get_week(year, week) |