aboutsummaryrefslogtreecommitdiff
path: root/feeds.py
diff options
context:
space:
mode:
authorAlban Gruin2017-09-24 17:16:10 +0200
committerAlban Gruin2017-09-24 17:16:10 +0200
commite30b0c673cae607175c5bae6df6e87d8b100bdf3 (patch)
tree2ffc269ad5e56ff93e2ecd3bded5843a585c4fe7 /feeds.py
parent77748ec01d1ef59d8436597a9b52675b309e1c4d (diff)
Suppression du modèle LastUpdate, utilisation du champ last_update à
la place.
Diffstat (limited to 'feeds.py')
-rw-r--r--feeds.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/feeds.py b/feeds.py
index 6dfb851..d7f3ae3 100644
--- a/feeds.py
+++ b/feeds.py
@@ -16,7 +16,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.contrib.syndication.views import Feed
-from django.db.models import Q
+from django.db.models import Count, Max, Q
from django.db.models.functions import ExtractWeek, ExtractYear
from django.template import loader
from django.urls import reverse
@@ -24,7 +24,7 @@ from django.utils.feedgenerator import Atom1Feed, SyndicationFeed
from icalendar import Calendar, Event
-from .models import Course, Group, LastUpdate
+from .models import Course, Group
from .templatetags.rooms import format_rooms
from .utils import get_current_or_next_week, get_week, group_courses
@@ -70,13 +70,13 @@ class IcalFeed(Feed):
return ""
def items(self, obj):
- return Course.objects.get_courses_for_group(obj).annotate(year=ExtractYear("begin"), week=ExtractWeek("begin"))
+ return Course.objects.get_courses_for_group(obj)
def item_extra_kwargs(self, item):
return {"uid": "{0}@celcatsanitizer".format(item.id),
"dtstart": item.begin,
"dtend": item.end,
- "dtstamp": LastUpdate.objects.get(timetable=item.timetable, year=item.year, week=item.week).updated_at,
+ "dtstamp": item.last_update,
"summary": item.name,
"location": format_rooms(item.rooms.all())}
@@ -84,12 +84,14 @@ class IcalFeed(Feed):
class RSSFeed(Feed):
def get_object(self, request, year_slug, timetable_slug, group_slug):
year, week = get_current_or_next_week()
+ begin, end = get_week(year, week)
+
try:
group = Group.objects.get(timetable__year__slug=year_slug, timetable__slug=timetable_slug, slug=group_slug)
- updates = LastUpdate.objects.filter(Q(year=year, week__lte=week) | Q(year__lt=year), timetable__year__slug=year_slug, timetable__slug=timetable_slug).order_by("-year", "-week")[:5]
except:
raise ObjectDoesNotExist
else:
+ updates = Course.objects.get_courses_for_group(group, begin__lt=end).annotate(year=ExtractYear("begin"), week=ExtractWeek("begin")).values("year", "week").annotate(Count("year", distinct=True), Max("last_update")).order_by("-year", "-week")[:5]
return group, updates
def link(self, obj):
@@ -115,9 +117,9 @@ class RSSFeed(Feed):
group = obj[0]
for update in obj[1]:
- start, end = get_week(update.year, update.week)
+ start, end = get_week(update["year"], update["week"])
courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end)
- context = {"group": group, "courses": group_courses(courses), "last_update": update, "year": update.year, "week": update.week}
+ context = {"group": group, "courses": group_courses(courses), "last_update": update["last_update__max"], "year": update["year"], "week": update["week"]}
update.group = group
update.description = template.render(context)