From dc272aad09f15273a930345f33943580b2a8a1f3 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 19:54:03 +0200 Subject: Ajout d’un champ permettant de stocker la date de mise à jour du calendrier celcat dans le modèle LastUpdate, ainsi que de quoi la lire depuis le XML --- management/commands/_private.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'management') diff --git a/management/commands/_private.py b/management/commands/_private.py index c31eb34..f7f8435 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -21,6 +21,8 @@ from edt.models import Group, Room, Course from edt.utils import get_week import datetime +import re + import requests @@ -122,6 +124,29 @@ def get_events(timetable, year, week, soup, weeks_in_soup): yield title, type_, groups, rooms, notes, begin, end +def get_update_date(soup): + # Explication de la regex + # + # (\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+) + # (\d+) au moins un nombre + # / un slash + # (\d+) au moins un nombre + # / un slash + # (\d+) au moins un nombre + # \s+ au moins un espace + # (\d+) au moins un nombre + # : un deux-points + # (\d+) au moins un nombre + # : un deux-points + # (\d+) au moins un nombre + datetime_regex = re.compile("(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)") + search = datetime_regex.search(soup.footer.text) + if search is None: + return None + + day, month, year, hour, minute, second = [int(v) for v in search.groups()] + return datetime.datetime(year, month, day, hour, minute, second) + def get_weeks(soup): weeks = {} for span in soup.find_all("span"): -- cgit v1.2.1 From bd236d267bfa6857d062733899ca6db5231ddd1d Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 20:04:10 +0200 Subject: On rend la date de MàJ retournée au courant de la tz --- management/commands/_private.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'management') diff --git a/management/commands/_private.py b/management/commands/_private.py index f7f8435..d54d81b 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -145,7 +145,8 @@ def get_update_date(soup): return None day, month, year, hour, minute, second = [int(v) for v in search.groups()] - return datetime.datetime(year, month, day, hour, minute, second) + date = datetime.datetime(year, month, day, hour, minute, second) + return timezone.make_aware(date) def get_weeks(soup): weeks = {} -- cgit v1.2.1 From 1a605b7390fadd1ad65128590aca9d30743a0510 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 20:22:55 +0200 Subject: On ne parse pas le contenu de l’emploi du temps si la date de mise à jour est égale ou inférieure à celle stockée en base de données. --- management/commands/timetables.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'management') diff --git a/management/commands/timetables.py b/management/commands/timetables.py index d596233..7f33be1 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -17,16 +17,29 @@ from django.core.management.base import BaseCommand from django.db import transaction from django.utils import timezone -from edt.models import Timetable, LastUpdate, Course -from ._private import delete_courses_in_week, get_events, get_weeks, get_xml +from edt.models import Timetable, LastUpdate, Course +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): + last_update_date = None + new_update_date = get_update_date(soup) + try: + last_update = LastUpdate.objects.get(timetable=timetable, year=year, week=week) + last_update_date = last_update.updated_at + except: + last_update = LastUpdate.objects(timetable=timetable, year=year, week=week) + + if last_update_date is not None and new_update_date is not None and \ + last_update_date >= new_update_date: + return + 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): + 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.name = name course.type = type_ @@ -38,14 +51,9 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): course.save() - date = timezone.make_aware(datetime.datetime.now()) - try: - last_update = LastUpdate.objects.get(timetable=timetable, year=year, week=week) - last_update.date = date - except: - last_update = LastUpdate(timetable=timetable, year=year, week=week, date=date) - finally: - last_update.save() + last_update.date = timezone.make_aware(datetime.datetime.now()) + last_update.updated_at = new_update_date + last_update.save() def process_timetable(timetable, year, weeks): soup = get_xml(timetable.url) -- cgit v1.2.1 From 702ed90e13396bd999079d22f03a40e4daf93a54 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 20:28:48 +0200 Subject: Correction de la création de l’objet LastUpdate --- management/commands/timetables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'management') diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 7f33be1..64dd6f6 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -31,7 +31,7 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): last_update = LastUpdate.objects.get(timetable=timetable, year=year, week=week) last_update_date = last_update.updated_at except: - last_update = LastUpdate.objects(timetable=timetable, year=year, week=week) + last_update = LastUpdate(timetable=timetable, year=year, week=week) if last_update_date is not None and new_update_date is not None and \ last_update_date >= new_update_date: -- cgit v1.2.1 From 49e56d97e5a126f66d1d52b5de45befe603893b2 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 23:31:54 +0200 Subject: Remplacement de la licence GPL 2 par la licence AGPL 3 --- management/commands/_private.py | 13 ++++++------- management/commands/cleancourses.py | 13 ++++++------- management/commands/listtimetables.py | 13 ++++++------- management/commands/sendmails.py | 13 ++++++------- management/commands/timetables.py | 13 ++++++------- 5 files changed, 30 insertions(+), 35 deletions(-) (limited to 'management') diff --git a/management/commands/_private.py b/management/commands/_private.py index d54d81b..17896c4 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -1,18 +1,17 @@ # Copyright (C) 2017 Alban Gruin # -# celcatsanitizer is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # celcatsanitizer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with celcatsanitizer; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see . from bs4 import BeautifulSoup from django.utils import timezone diff --git a/management/commands/cleancourses.py b/management/commands/cleancourses.py index 5f71861..ca2ef94 100644 --- a/management/commands/cleancourses.py +++ b/management/commands/cleancourses.py @@ -1,18 +1,17 @@ # Copyright (C) 2017 Alban Gruin # -# celcatsanitizer is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # celcatsanitizer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with celcatsanitizer; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see . from django.core.management.base import BaseCommand from django.db import transaction diff --git a/management/commands/listtimetables.py b/management/commands/listtimetables.py index e4b782f..a82db23 100644 --- a/management/commands/listtimetables.py +++ b/management/commands/listtimetables.py @@ -1,18 +1,17 @@ # Copyright (C) 2017 Alban Gruin # -# celcatsanitizer is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # celcatsanitizer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with celcatsanitizer; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see . from django.core.management.base import BaseCommand from edt.models import Timetable diff --git a/management/commands/sendmails.py b/management/commands/sendmails.py index c7725b7..e81980b 100644 --- a/management/commands/sendmails.py +++ b/management/commands/sendmails.py @@ -1,18 +1,17 @@ # Copyright (C) 2017 Alban Gruin # -# celcatsanitizer is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # celcatsanitizer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with celcatsanitizer; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see . from django.core.management.base import BaseCommand from django.core.mail import send_mass_mail diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 64dd6f6..c82b0e4 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -1,18 +1,17 @@ # Copyright (C) 2017 Alban Gruin # -# celcatsanitizer is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # celcatsanitizer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with celcatsanitizer; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see . from django.core.management.base import BaseCommand from django.db import transaction -- cgit v1.2.1 From 5e6049ca24670f41f9fa6335ea49c389c3133b86 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 8 Sep 2017 12:05:34 +0200 Subject: Le tri du nom des emplois du temps est fait en fonction de l’année puis de la mention --- management/commands/listtimetables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'management') diff --git a/management/commands/listtimetables.py b/management/commands/listtimetables.py index a82db23..6df7ba5 100644 --- a/management/commands/listtimetables.py +++ b/management/commands/listtimetables.py @@ -28,7 +28,7 @@ class Command(BaseCommand): if options["order_by_id"]: timetables = timetables.order_by("id") else: - timetables = timetables.order_by("name") + timetables = timetables.order_by("year__name", "name") for timetable in timetables: self.stdout.write("{0} (id: {1})".format(timetable, timetable.id)) -- cgit v1.2.1 From 7eee2b573efd3eefb89545f6d6682216801c9126 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 8 Sep 2017 12:07:41 +0200 Subject: Suppression des .name dans sendmails --- management/commands/sendmails.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'management') diff --git a/management/commands/sendmails.py b/management/commands/sendmails.py index e81980b..3c0fab0 100644 --- a/management/commands/sendmails.py +++ b/management/commands/sendmails.py @@ -58,7 +58,7 @@ class Command(BaseCommand): if not options["test"]: context = Context({"admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN}) mail_content = content[subscription.group.id] + footer.render(context) - mails.append(("{0} - {1} - Semaine {2}".format(subscription.group.timetable.name, subscription.group.name, week), mail_content, settings.DEFAULT_FROM_EMAIL, [subscription.email],)) + mails.append(("{0} - {1} - Semaine {2}".format(subscription.group.timetable, subscription.group, week), mail_content, settings.DEFAULT_FROM_EMAIL, [subscription.email],)) if not options["test"]: print("Sending mails...") -- cgit v1.2.1 From c7fce37ad4c8dee76f5d58eafefd0c73a03ea00c Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 9 Sep 2017 14:56:17 +0200 Subject: Suppression de l’envoi des mails --- management/commands/sendmails.py | 67 ---------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 management/commands/sendmails.py (limited to 'management') diff --git a/management/commands/sendmails.py b/management/commands/sendmails.py deleted file mode 100644 index 3c0fab0..0000000 --- a/management/commands/sendmails.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (C) 2017 Alban Gruin -# -# celcatsanitizer is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# celcatsanitizer is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with celcatsanitizer. If not, see . - -from django.core.management.base import BaseCommand -from django.core.mail import send_mass_mail -from django.utils import translation -from django.template import Context, loader -from django.conf import settings - -from edt.models import Course, Subscription -from edt.utils import get_current_or_next_week, get_week, group_courses - - -class Command(BaseCommand): - help = "Sends emails to subscribed users" - - def add_arguments(self, parser): - parser.add_argument("--test", help="Print the content of mails instead of sending them", action="store_true") - - def handle(self, *args, **options): - translation.activate(settings.LANGUAGE_CODE) - - year, week = get_current_or_next_week() - start, end = get_week(year, week) - - subscriptions = Subscription.objects.filter(active=True) - content = {} - mails = [] - - footer = loader.get_template("mail/mail_footer.txt") - timetable = loader.get_template("mail/mail_timetable.txt") - - print("Generating messages...") - for subscription in subscriptions: - if subscription.group.id not in content: - courses = Course.objects.get_courses_for_group(subscription.group, begin__gte=start, begin__lt=end) - - grouped_courses = group_courses(courses) - context = Context({"courses": grouped_courses, "group": subscription.group, "week": week}) - content[subscription.group.id] = timetable.render(context) - - if options["test"]: - print(subscription.group) - print(content[subscription.group.id]) - - if not options["test"]: - context = Context({"admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN}) - mail_content = content[subscription.group.id] + footer.render(context) - mails.append(("{0} - {1} - Semaine {2}".format(subscription.group.timetable, subscription.group, week), mail_content, settings.DEFAULT_FROM_EMAIL, [subscription.email],)) - - if not options["test"]: - print("Sending mails...") - send_mass_mail(mails) - - self.stdout.write(self.style.SUCCESS("Done.")) -- cgit v1.2.1