aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin.py8
-rw-r--r--management/commands/timetables.py10
-rw-r--r--models.py13
3 files changed, 29 insertions, 2 deletions
diff --git a/admin.py b/admin.py
index 233ed1d..d49c123 100644
--- a/admin.py
+++ b/admin.py
@@ -1,5 +1,5 @@
from django.contrib import admin
-from edt.models import Timetable, Group, Room, Course
+from edt.models import Timetable, LastUpdate, Group, Room, Course
@admin.register(Timetable)
@@ -8,6 +8,12 @@ class TimetableAdmin(admin.ModelAdmin):
list_display = ("name", "url",)
+@admin.register(LastUpdate)
+class LastUpdateAdmin(admin.ModelAdmin):
+ list_display = ("timetable", "week", "year", "date",)
+ list_filter = ("timetable__name",)
+
+
@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
fieldsets = (
diff --git a/management/commands/timetables.py b/management/commands/timetables.py
index 6412b7e..21148c8 100644
--- a/management/commands/timetables.py
+++ b/management/commands/timetables.py
@@ -1,7 +1,7 @@
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from django.utils import timezone
-from edt.models import Timetable, Group, Room, Course
+from edt.models import Timetable, LastUpdate, Group, Room, Course
from bs4 import BeautifulSoup
@@ -25,6 +25,14 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup):
course.save()
+ date = timezone.make_aware(datetime.datetime.now())
+ try:
+ lastUpdate = LastUpdate.objects.get(timetable=timetable, year=year, week=week)
+ lastUpdate.date = date
+ except:
+ lastUpdate = LastUpdate(timetable=timetable, year=year, week=week, date=date)
+ lastUpdate.save()
+
def process_timetable(timetable, year, weeks):
soup = get_xml(timetable.url)
weeks_in_soup = get_weeks(soup)
diff --git a/models.py b/models.py
index 13ae3f4..d01dbf0 100644
--- a/models.py
+++ b/models.py
@@ -17,6 +17,19 @@ class Timetable(models.Model):
verbose_name_plural = "emplois du temps"
+class LastUpdate(models.Model):
+ timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps")
+ week = models.IntegerField(verbose_name="semaine")
+ year = models.IntegerField(verbose_name="année")
+ date = models.DateTimeField(verbose_name="date de mise à jour")
+
+
+ class Meta:
+ unique_together = ("timetable", "week", "year",)
+ verbose_name = "dernière mise à jour"
+ verbose_name_plural = "dernières mises à jour"
+
+
class Group(models.Model):
name = models.CharField(max_length=255, verbose_name="nom")
timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps")