aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-01-19 14:31:46 +0100
committerAlban Gruin2017-01-19 14:31:46 +0100
commit0c939d8e893b55ac16168725709adea6512f3f86 (patch)
treec75b3a1fe4adc63ed56d78c7a9329f243616a204
parentd5707a7293d68eb064f9e407531d7f1817b3c6dd (diff)
La commande peut traiter plusieurs semaines choisies manuellement par l'administrateur
-rw-r--r--management/commands/timetables.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py
index 60c9eb5..50382ed 100644
--- a/management/commands/timetables.py
+++ b/management/commands/timetables.py
@@ -11,23 +11,37 @@ import requests
class Command(BaseCommand):
- help = "Fetches the specified celcat timetable"
+ help = "Fetches registered celcat timetables"
+
+ def add_arguments(self, parser):
+ parser.add_argument("--week", type=int, choices=range(1, 54), nargs="+")
+
+ def __get_weeks(self, weeks):
+ if weeks is None:
+ year, week, day = timezone.now().isocalendar()
+ if day >= 6:
+ year, week, _ = (timezone.now() + datetime.timedelta(weeks=1)).isocalendar()
+
+ yield year, week
+ else:
+ year = timezone.now().year
+ for week in weeks:
+ yield year, week
def handle(self, *args, **options):
- year, week, day = timezone.now().isocalendar()
- if day >= 6:
- year, week, _ = (timezone.now() + datetime.timedelta(weeks=1)).isocalendar()
+ for year, week in self.__get_weeks(options["week"]):
+ delete_courses_in_week(year, week)
- delete_courses_in_week(year, week)
+ for timetable in Timetable.objects.all():
+ self.stdout.write("Processing {0}, week {1}".format(timetable, week))
- for timetable in Timetable.objects.all():
- soup = get_xml(timetable.url)
- weeks = get_weeks(soup)
+ soup = get_xml(timetable.url)
+ weeks = get_weeks(soup)
- for name, type_, groups, rooms, begin, end in get_events(soup, weeks, week, timetable):
- course = Course.objects.create(name=name, type=type_, timetable=timetable, begin=begin, end=end)
- course.groups.add(*groups)
- course.rooms.add(*rooms)
- course.save()
+ for name, type_, groups, rooms, begin, end in get_events(soup, weeks, week, timetable):
+ course = Course.objects.create(name=name, type=type_, timetable=timetable, begin=begin, end=end)
+ course.groups.add(*groups)
+ course.rooms.add(*rooms)
+ course.save()
self.stdout.write(self.style.SUCCESS("Done."))