From f9c36c8f99de3d80d4a2ebd8c2fbdd2448ff0dc7 Mon Sep 17 00:00:00 2001 From: Sli Date: Mon, 24 Feb 2025 19:05:18 +0100 Subject: [PATCH] Apply review comments --- com/calendar.py | 8 ++++---- .../bundled/com/components/ics-calendar-index.ts | 10 +++++----- tsconfig.json | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/com/calendar.py b/com/calendar.py index dfe8fe6a..cf35a522 100644 --- a/com/calendar.py +++ b/com/calendar.py @@ -5,7 +5,7 @@ from typing import final import requests from dateutil.relativedelta import relativedelta from django.conf import settings -from django.db.models import QuerySet +from django.db.models import F, QuerySet from django.urls import reverse from django.utils import timezone from ical.calendar import Calendar @@ -80,11 +80,11 @@ class IcsCalendar: ) @classmethod - def ics_from_queryset(cls, queryset: QuerySet) -> bytes: + def ics_from_queryset(cls, queryset: QuerySet[NewsDate]) -> bytes: calendar = Calendar() - for news_date in queryset.prefetch_related("news"): + for news_date in queryset.annotate(news_title=F("news__title")): event = Event( - summary=news_date.news.title, + summary=news_date.news_title, start=news_date.start_date, end=news_date.end_date, url=reverse("com:news_detail", kwargs={"news_id": news_date.news.id}), diff --git a/com/static/bundled/com/components/ics-calendar-index.ts b/com/static/bundled/com/components/ics-calendar-index.ts index 742a679d..21019a4c 100644 --- a/com/static/bundled/com/components/ics-calendar-index.ts +++ b/com/static/bundled/com/components/ics-calendar-index.ts @@ -68,7 +68,6 @@ export class IcsCalendar extends inheritHtmlElement("div") { } getNewsId(event: EventImpl) { - // return Number.parseInt(event.url.split("/").pop()); return Number.parseInt( event.url .toString() @@ -80,6 +79,9 @@ export class IcsCalendar extends inheritHtmlElement("div") { async refreshEvents() { this.click(); // Remove focus from popup + // We can't just refresh events because some ics files are in + // local browser cache (especially internal.ics) + // To invalidate the cache, we need to remove the source and add it again this.calendar.removeAllEventSources(); for (const source of await this.getEventSources()) { this.calendar.addEventSource(source); @@ -198,7 +200,7 @@ export class IcsCalendar extends inheritHtmlElement("div") { }; const makePopupTools = (event: EventImpl) => { - if (event.source.internalEventSource.ui.classNames.indexOf("external") >= 0) { + if (event.source.internalEventSource.ui.classNames.includes("external")) { return null; } if (!(this.canDelete || this.canModerate)) { @@ -207,9 +209,7 @@ export class IcsCalendar extends inheritHtmlElement("div") { const newsId = this.getNewsId(event); const div = document.createElement("div"); if (this.canModerate) { - if ( - event.source.internalEventSource.ui.classNames.indexOf("unmoderated") >= 0 - ) { + if (event.source.internalEventSource.ui.classNames.includes("unmoderated")) { const button = document.createElement("button"); button.innerHTML = `${gettext("Moderate")}`; button.setAttribute("class", "btn btn-green"); diff --git a/tsconfig.json b/tsconfig.json index aaee9330..a93da92a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,6 +12,7 @@ "esModuleInterop": true, "resolveJsonModule": true, "types": ["jquery", "alpinejs"], + "lib": ["es7"], "paths": { "#openapi": ["./staticfiles/generated/openapi/index.ts"], "#core:*": ["./core/static/bundled/*"],