diff options
author | Alban Gruin | 2017-11-06 08:26:46 +0100 |
---|---|---|
committer | Alban Gruin | 2017-11-06 08:26:46 +0100 |
commit | 60b2ceaa43d01e34514f3e68f45585619807d1cf (patch) | |
tree | cf8763dfd9bbbe48a5383a5f49ca07437916c7a6 | |
parent | 771f4ebb8f1e27212bfce413ea664a73c7a86965 (diff) | |
parent | 37a95855076035470e7484804ed48b779ed22277 (diff) |
Merge branch 'dev/alban'
-rw-r--r-- | feeds.py | 7 | ||||
-rw-r--r-- | management/commands/timetables.py | 26 | ||||
-rw-r--r-- | models.py | 6 | ||||
-rw-r--r-- | templates/timetable_common.html | 2 |
4 files changed, 30 insertions, 11 deletions
@@ -75,6 +75,11 @@ class IcalFeed(Feed): def item_link(self, item): return "" + def item_summary(self, item): + if item.type is not None: + return item.name + " (" + item.type + ")" + return item.name + def items(self, obj): return Course.objects.get_courses_for_group(obj) @@ -83,7 +88,7 @@ class IcalFeed(Feed): "dtstart": item.begin, "dtend": item.end, "dtstamp": item.last_update, - "summary": item.name + " (" + item.type + ")", + "summary": self.item_summary(item), "location": format_rooms(item.rooms.all())} diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 2d8a17e..b254788 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -14,6 +14,7 @@ # along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>. import datetime +import traceback from django.core.management.base import BaseCommand from django.db import transaction @@ -25,17 +26,28 @@ from ._private import delete_courses_in_week, get_events, get_update_date, get_w @transaction.atomic def process_timetable_week(timetable, soup, weeks_in_soup, force, year=None, week=None): - begin, end = get_week(year, week) + if year is not None and week is not None: + begin, end = get_week(year, week) + # Si on force la mise à jour, on définit de moment # de la mise à jour au début de la semaine - if force: + if force and year is not None and week is not None: today = begin + elif force: + # Si la mise à jour est faite sur tout l’emploi du temps, + # alors la date de début est indéfinie. + today = None else: today = tz_now() # On récupère la mise à jour la plus ancienne dans les cours de l’emploi du temps - # commençant à partir de maintenant - last_update_date = Course.objects.filter(timetable=timetable, begin__gte=today) + last_update_date = Course.objects.filter(timetable=timetable) + + if today is not None: + # Cette date concerne les éléments commençant à partir d’aujourd’hui si la valeur + # n’est pas nulle. + last_update_date = last_update_date.filter(begin__gte=today) + if year is not None and week is not None: # Si jamais on traite une semaine spécifique, on limite les cours sélectionnés # à ceux qui commencent entre le début du traitement et la fin de la semaine @@ -124,9 +136,11 @@ class Command(BaseCommand): try: process_timetable(timetable, options["force"], year, weeks) - except Exception as exc: + except Exception: self.stderr.write( - self.style.ERROR("Failed to process {0}: {1}".format(timetable, exc))) + self.style.ERROR("Failed to process {0}:".format(timetable)) + ) + self.stderr.write(self.style.ERROR(traceback.format_exc())) errcount += 1 if errcount == 0: @@ -71,7 +71,7 @@ class Timetable(SlugModel): class GroupManager(Manager): def get_parents(self, group): - groups_criteria = Q(subgroup__isnull=True) | \ + groups_criteria = Q(subgroup__isnull=True) | Q(subgroup__startswith=group.subgroup) | \ reduce(lambda x, y: x | y, [Q(subgroup=group.subgroup[:i]) for i in range(1, len(group.subgroup) + 1)]) @@ -80,13 +80,13 @@ class GroupManager(Manager): timetable=group.timetable) def get_relevant_groups(self, timetable, *args, **criteria): - sub = Group.objects.filter(timetable=timetable,mention=OuterRef("mention"), + sub = self.get_queryset().filter(timetable=timetable, mention=OuterRef("mention"), subgroup__startswith=OuterRef("subgroup")) \ .order_by().values("mention").annotate(c=Count("*")).values("c") return self.get_queryset().filter(*args, timetable=timetable, hidden=False, **criteria) \ .annotate(nbsub=Subquery(sub, output_field=models.IntegerField())) \ - .filter(nbsub=1).order_by("name") + .filter(Q(nbsub=1) | Q(nbsub__isnull=True)).order_by("name") class Group(models.Model): diff --git a/templates/timetable_common.html b/templates/timetable_common.html index 9a2c27e..62b1d71 100644 --- a/templates/timetable_common.html +++ b/templates/timetable_common.html @@ -4,7 +4,7 @@ <h3>{% filter title %}{{ day.0.begin|date:"l j F o" }}{% endfilter %} – de {{ day.0.begin|date:"H:i" }} à {% with day|last as last %}{{ last.end|date:"H:i" }}{% endwith %}</h3> <ul>{% for course in day %} <li class="course"> - <b>{{ course }}</b> ({{ course.type }}), de {{ course.begin|date:"H:i" }} à {{ course.end|date:"H:i" }}{% if course.rooms.all|length > 0 %}<br /> + <b>{{ course }}</b>{% if course.type %} ({{ course.type }}){% endif %}, de {{ course.begin|date:"H:i" }} à {{ course.end|date:"H:i" }}{% if course.rooms.all|length > 0 %}<br /> <em>{{ course.rooms.all|format_rooms }}</em>{% endif %}{% if course.notes %}<br /> <small>Remarques : {{ course.notes }}</small>{% endif %} </li>{% endfor %} |