aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-10-01 16:54:42 +0200
committerAlban Gruin2017-10-01 16:54:42 +0200
commit5d59112a9c7badc2cc0a48d1a8e33d48e1e6e719 (patch)
tree86fe355ad1a3d0f086867dc585d202235f990db8
parentf0c61f1a3a26f8c76f43b21f7860d83041b7fe89 (diff)
Ajout d’une colonne pour cacher un groupe dans la liste des groupes.
Ajout d’actions personnalisées dans l’interface d’administration pour cacher et afficher plusieurs groupes à la fois. Filtrage des groupes cachés dans get_relevant_children() et get_relevant_groups().
-rw-r--r--admin.py14
-rw-r--r--models.py6
2 files changed, 16 insertions, 4 deletions
diff --git a/admin.py b/admin.py
index 8a409e3..e17948a 100644
--- a/admin.py
+++ b/admin.py
@@ -16,6 +16,14 @@
from django.contrib import admin
from .models import Timetable, Group, Room, Course, Year
+def make_hidden(modeladmin, request, queryset):
+ queryset.update(hidden=True)
+make_hidden.short_description = "Cacher les groupes sélectionnés"
+
+def make_visible(modeladmin, request, queryset):
+ queryset.update(hidden=False)
+make_visible.short_description = "Afficher les groupes sélectionnés"
+
@admin.register(Year)
class YearAdmin(admin.ModelAdmin):
@@ -35,12 +43,14 @@ class TimetableAdmin(admin.ModelAdmin):
@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
fieldsets = (
- (None, {"fields": ("name", "celcat_name", "timetable",)}),
+ (None, {"fields": ("name", "celcat_name", "timetable", "hidden",)}),
("Groupes", {"fields": ("mention", "subgroup", "td", "tp", "parent",)}),)
- list_display = ("name", "timetable",)
+ list_display = ("name", "timetable", "hidden",)
+ list_editable = ("hidden",)
list_filter = ("timetable",)
ordering = ("timetable",)
readonly_fields = ("celcat_name", "mention", "subgroup", "td", "tp",)
+ actions = (make_hidden, make_visible,)
@admin.register(Room)
diff --git a/models.py b/models.py
index 649368e..8bd2399 100644
--- a/models.py
+++ b/models.py
@@ -71,13 +71,13 @@ class GroupManager(Manager):
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) \
+ .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)
+ .filter(children_count=0, hidden=False)
class Group(models.Model):
@@ -99,6 +99,8 @@ class Group(models.Model):
slug = models.SlugField(max_length=64, default="")
+ hidden = models.BooleanField(verbose_name="caché", default=False)
+
def corresponds_to(self, timetable_id, mention, subgroup, td, tp):
return self.timetable.id == timetable_id and \
self.mention.startswith(mention) and \