From 020d204d393ebf8c7f2bc9f6848cd4892b278f70 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 24 Sep 2017 18:13:44 +0200 Subject: Récupération de la dernière mise à jour en filtrant par emploi du temps Changement de la valeur par défaut de last_update, qui posait problème get_week, pas get_weeks --- management/commands/timetables.py | 5 +++-- models.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/management/commands/timetables.py b/management/commands/timetables.py index efdd611..e136f53 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -19,15 +19,16 @@ from django.db.models import Max from django.utils import timezone 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_weeks(year, week) + begin, end = get_week(year, week) - last_update_date = Course.objects.filter(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 \ diff --git a/models.py b/models.py index e284c28..b1d6d27 100644 --- a/models.py +++ b/models.py @@ -16,6 +16,7 @@ from django.db import models from django.db.models import Count, Manager, Q from django.db.models.functions import ExtractWeek, ExtractYear +from django.utils import timezone from django.utils.text import slugify from .utils import parse_group @@ -143,7 +144,7 @@ class Course(models.Model): begin = models.DateTimeField(verbose_name="début du cours", db_index=True) end = models.DateTimeField(verbose_name="fin du cours") - last_update = models.DateTimeField(verbose_name="dernière mise à jour", auto_now_add=True) + last_update = models.DateTimeField(verbose_name="dernière mise à jour", default=timezone.now) def __str__(self): return self.name -- cgit v1.2.1