aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-11-27 17:23:11 +0100
committerAlban Gruin2017-11-27 17:23:11 +0100
commit8a71b0a55847e8783006b5a9514f64e0129578c9 (patch)
treeec8b6d6f014cd387c6de300942401ec43608aded
parenta5b0d082a728b06e5e02f4d64632ac0b0a572aec (diff)
Fonction pour formater les emplois du temps à partir d’une source
-rw-r--r--management/commands/listtimetables.py4
-rw-r--r--management/commands/timetables.py5
-rw-r--r--models.py4
3 files changed, 8 insertions, 5 deletions
diff --git a/management/commands/listtimetables.py b/management/commands/listtimetables.py
index 171fc2b..25f641b 100644
--- a/management/commands/listtimetables.py
+++ b/management/commands/listtimetables.py
@@ -29,8 +29,8 @@ class Command(BaseCommand):
sources = sources.order_by("id")
for source in sources:
- self.stdout.write("{0}\t: {1} (id: {2})".format(", ".join([str(timetable) for timetable in source.timetables.all()]),
- source, source.id))
+ self.stdout.write("{0}\t: {1} (id: {2})".format(source.formatted_timetables,
+ source, source.id))
self.stdout.write("")
self.stdout.write(self.style.SUCCESS("Done."))
diff --git a/management/commands/timetables.py b/management/commands/timetables.py
index 9734d13..86f389e 100644
--- a/management/commands/timetables.py
+++ b/management/commands/timetables.py
@@ -132,8 +132,7 @@ class Command(BaseCommand):
year = options["year"][0]
for source in Source.objects.all():
- timetables = ", ".join([str(timetable) for timetable in source.timetables.all()])
- self.stdout.write("Processing {0}".format(timetables))
+ self.stdout.write("Processing {0}".format(source.formatted_timetables))
try:
process_timetable(source, options["force"], year, weeks)
@@ -141,7 +140,7 @@ class Command(BaseCommand):
break
except Exception:
self.stderr.write(
- self.style.ERROR("Failed to process {0}:".format(timetables))
+ self.style.ERROR("Failed to process {0}:".format(source.formatted_timetables))
)
self.stderr.write(self.style.ERROR(traceback.format_exc()))
errcount += 1
diff --git a/models.py b/models.py
index b8c67d6..363cf33 100644
--- a/models.py
+++ b/models.py
@@ -56,6 +56,10 @@ class Source(models.Model):
def __str__(self):
return self.url
+ @property
+ def formatted_timetables(self):
+ return ", ".join([str(timetable) for timetable in self.timetables.iterator()])
+
class Meta:
verbose_name = "source d’emploi du temps"