aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--feeds.py7
-rw-r--r--management/commands/timetables.py26
-rw-r--r--models.py6
-rw-r--r--templates/timetable_common.html2
4 files changed, 30 insertions, 11 deletions
diff --git a/feeds.py b/feeds.py
index 66be12e..aced5e6 100644
--- a/feeds.py
+++ b/feeds.py
@@ -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:
diff --git a/models.py b/models.py
index c546737..3af1c06 100644
--- a/models.py
+++ b/models.py
@@ -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 %} &ndash; 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 %}