aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin.py2
-rw-r--r--models.py8
-rw-r--r--utils.py4
-rw-r--r--views.py4
4 files changed, 13 insertions, 5 deletions
diff --git a/admin.py b/admin.py
index f818865..1c8606a 100644
--- a/admin.py
+++ b/admin.py
@@ -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",)
diff --git a/models.py b/models.py
index 876160b..53bcef7 100644
--- a/models.py
+++ b/models.py
@@ -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="")
diff --git a/utils.py b/utils.py
index 8dc386f..8630036 100644
--- a/utils.py
+++ b/utils.py
@@ -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))))?$")
diff --git a/views.py b/views.py
index 9365695..176f174 100644
--- a/views.py
+++ b/views.py
@@ -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)