From aa7ccf13a8735f162e2ea859ad1d8ebe9f34f657 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Mon, 25 Sep 2017 16:08:01 +0200 Subject: Utilisation de pylint pour améliorer la qualité du code --- management/commands/timetables.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'management/commands/timetables.py') diff --git a/management/commands/timetables.py b/management/commands/timetables.py index e136f53..f01ac3c 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with celcatsanitizer. If not, see . +import datetime + from django.core.management.base import BaseCommand from django.db import transaction from django.db.models import Max @@ -22,13 +24,15 @@ from edt.models import Timetable, Course from edt.utils import get_week from ._private import delete_courses_in_week, get_events, get_update_date, get_weeks, get_xml -import datetime - @transaction.atomic def process_timetable_week(timetable, year, week, soup, weeks_in_soup): begin, end = get_week(year, week) - last_update_date = Course.objects.filter(timetable=timetable, begin__gte=begin, begin__lt=end).aggregate(Max("last_update"))["last_update__max"] + last_update_date = Course.objects.filter(timetable=timetable, + begin__gte=begin, + begin__lt=end) \ + .aggregate(Max("last_update")) \ + ["last_update__max"] new_update_date = get_update_date(soup) if last_update_date is not None and new_update_date is not None and \ @@ -38,7 +42,9 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): delete_courses_in_week(timetable, year, week) for name, type_, groups, rooms, notes, begin, end in \ get_events(timetable, year, week, soup, weeks_in_soup): - course = Course.objects.create(timetable=timetable, begin=begin, end=end) + course = Course.objects.create(timetable=timetable, + begin=begin, + end=end) course.name = name course.type = type_ course.notes = notes @@ -86,8 +92,9 @@ class Command(BaseCommand): try: process_timetable(timetable, year, weeks) - except Exception as e: - self.stderr.write(self.style.ERROR("Failed to process {0}: {1}".format(timetable, e))) + except Exception as exc: + self.stderr.write( + self.style.ERROR("Failed to process {0}: {1}".format(timetable, exc))) errcount += 1 if errcount == 0: -- cgit v1.2.1