aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--templatetags/rooms.py14
-rw-r--r--tests.py34
2 files changed, 35 insertions, 13 deletions
diff --git a/templatetags/rooms.py b/templatetags/rooms.py
index f0e1b2e..d8b0e23 100644
--- a/templatetags/rooms.py
+++ b/templatetags/rooms.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017 Alban Gruin
+# Copyright (C) 2017, 2019 Alban Gruin
#
# celcatsanitizer is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
@@ -18,11 +18,17 @@ from django import template
register = template.Library()
+def __filter_room_name(name):
+ if '/' in name:
+ return name.split('/')[1].strip()
+ return name
+
+
@register.filter
def format_rooms(rooms):
- amphi_list = [room.name for room in rooms if room.name.startswith("Amphi")]
- room_list = [room.name for room in rooms
- if not room.name.startswith("Amphi")]
+ names = [__filter_room_name(room.name) for room in rooms]
+ amphi_list = [name for name in names if name.startswith("Amphi")]
+ room_list = [name for name in names if not name.startswith("Amphi")]
amphis = ", ".join(amphi_list)
joined = ", ".join(room_list)
diff --git a/tests.py b/tests.py
index b411db3..1e80b48 100644
--- a/tests.py
+++ b/tests.py
@@ -341,6 +341,16 @@ class RoomTestCase(TestCase):
for i in range(5, 7)
]
+ # On n’insère pas ces salles dans la base de données, elles ne
+ # servent que pour le test de formatage.
+ self.formatted_rooms = [
+ Room(name="FSI / {}".format(str(i)))
+ for i in range(5)
+ ] + [
+ Room(name="FSI / Amphi {}".format(str(i)))
+ for i in range(5, 7)
+ ]
+
hours = [({"begin": datetime.time(hour=14, minute=0)},),
({"begin": datetime.time(hour=16, minute=0)},),
({"begin": datetime.time(hour=13, minute=30)},
@@ -364,23 +374,29 @@ class RoomTestCase(TestCase):
course.groups.add(group)
course.rooms.add(room)
- def test_format(self):
- amphis = self.rooms[-2:]
-
+ def __test_format(self, rooms, amphis):
self.assertEqual(format_rooms([]), "")
- self.assertEqual(format_rooms(self.rooms[:1]), "Salle 0")
- self.assertEqual(format_rooms(self.rooms[:2]), "Salles 0, 1")
+ self.assertEqual(format_rooms(rooms[:1]), "Salle 0")
+ self.assertEqual(format_rooms(rooms[:2]), "Salles 0, 1")
self.assertEqual(format_rooms([amphis[0]]), "Amphi 5")
self.assertEqual(format_rooms(amphis), "Amphi 5, Amphi 6")
- self.assertEqual(format_rooms([amphis[0]] + self.rooms[:1]),
+ self.assertEqual(format_rooms([amphis[0]] + rooms[:1]),
"Amphi 5, salle 0")
- self.assertEqual(format_rooms([amphis[0]] + self.rooms[:2]),
+ self.assertEqual(format_rooms([amphis[0]] + rooms[:2]),
"Amphi 5, salles 0, 1")
- self.assertEqual(format_rooms(amphis + self.rooms[:1]),
+ self.assertEqual(format_rooms(amphis + rooms[:1]),
"Amphi 5, Amphi 6, salle 0")
- self.assertEqual(format_rooms(amphis + self.rooms[:2]),
+ self.assertEqual(format_rooms(amphis + rooms[:2]),
"Amphi 5, Amphi 6, salles 0, 1")
+ def test_format(self):
+ amphis = self.rooms[-2:]
+ self.__test_format(self.rooms, amphis)
+
+ def test_reformat(self):
+ amphis = self.formatted_rooms[-2:]
+ self.__test_format(self.formatted_rooms, amphis)
+
def test_qsjps(self):
begin = timezone.make_aware(datetime.datetime.combine(
self.day, datetime.time(hour=15, minute=0)))