diff --git a/home/admin.py b/home/admin.py index f6292ebeb4075caf98370bee59e851a3e93ca9f2..0d9b2607bca160f287b06f121cf9b5f3981b0bf1 100644 --- a/home/admin.py +++ b/home/admin.py @@ -28,7 +28,8 @@ class InterludesActivityAdmin(ExportCsvMixin, admin.ModelAdmin): "display", "room", "start", "on_planning", - "notes" + "notes", + "canonical", ) list_per_page = 100 save_as = True # Allow to duplicate models diff --git a/home/models.py b/home/models.py index 2e6e16c6d18d0c76575b7672fee978ce8f259cb4..72200864d944bdf0532f81c4b8d7d559c8a22cfc 100644 --- a/home/models.py +++ b/home/models.py @@ -69,6 +69,14 @@ class InterludesActivity(models.Model): start = models.DateTimeField("début", null=True, blank=True) room = models.CharField("salle", max_length=100, null=True, blank=True) + canonical = models.ForeignKey("self", + on_delete=models.SET_NULL, null=True, blank=True, + verbose_name="Représentant canonique", + help_text="Si plusieurs copie d'une activité existe (pour plusieurs crénaux), " + "et une seule est affichée, sélectionner là dans les copie pour réparer les liens " + "du planning vers la description" + ) + notes = models.TextField("Notes privées", max_length=2000, blank=True) @property @@ -106,6 +114,14 @@ class InterludesActivity(models.Model): status_repr = "présentiel" return "{} ({})".format(type, status_repr) + @property + def slug(self) -> str: + """Returns the planning/display slug for this activity""" + id = self.id + if self.canonical: + id = self.canonical.id + return "act-{}".format(id) + def conflicts(self, other: "InterludesActivity") -> bool: """Check whether these activites overlap""" if self.end is None or other.end is None: diff --git a/home/templates/activites.html b/home/templates/activites.html index 19d824645146dacec9a1772e087d8f71ca8ef6f8..fe74bbe32662b7bb817669a0ea61ee53eee343ad 100644 --- a/home/templates/activites.html +++ b/home/templates/activites.html @@ -28,7 +28,7 @@ {% for act in planning %} { id: {{ act.id }}, - content: '<a class="hidden" href="#act-{{act.id}}"><div><strong>{{ act.title }}</strong><br>{{ act.room }}</div></a>', + content: '<a class="hidden" href="#{{ act.slug }}"><div><strong>{{ act.title }}</strong><br>{{ act.room }}</div></a>', title: '<strong>{{ act.title }}</strong><br>{{ act.room }}', start: '{{ settings.date_start|date:"Y-m-d"}} {{ act.start|date:"H:i:s" }}', align: 'left', @@ -97,7 +97,7 @@ {% endif %} {% for activity in activities %} - <h3 id="act-{{ activity.id }}">{{ activity.title }}</h3> + <h3 id="{{ activity.slug }}">{{ activity.title }}</h3> <dl> <dt>Durée :</dt><dd>{{ activity.pretty_duration }}</dd>