From 6021f09c5336902fcf23d93d766216761d79d119 Mon Sep 17 00:00:00 2001 From: Julian Leucker <leuckerj@gmail.com> Date: Sun, 20 Mar 2022 21:23:34 +0100 Subject: [PATCH] Create basic extensible iCal feeds --- aleksis/core/feeds.py | 38 ++++++++++++++++++++++++++++++++++++++ pyproject.toml | 1 + 2 files changed, 39 insertions(+) create mode 100644 aleksis/core/feeds.py diff --git a/aleksis/core/feeds.py b/aleksis/core/feeds.py new file mode 100644 index 000000000..0ba3aed4d --- /dev/null +++ b/aleksis/core/feeds.py @@ -0,0 +1,38 @@ +from typing import Any + +from django.conf import settings +from django.core.handlers.wsgi import WSGIRequest +from django.utils.functional import classproperty +from django_ical.views import ICalFeed + +from aleksis.core.util.core_helpers import get_site_preferences + + +class PersonalICalFeedBase(ICalFeed): + @property + def product_id(self): + lang = self.request.LANGUAGE_CODE + return f"-//AlekSIS®//{get_site_preferences()['general__title']}//{lang}" + + link = settings.BASE_URL + timezone = settings.TIME_ZONE + person = None + request = None + + def get_object(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> None: + if kwargs.get("person"): + self.person = kwargs.pop("person") + self.request = request + return super().get_object(request, *args, **kwargs) + + @classproperty + def subclasses_list(cls): + return cls.__subclasses__() + + @classproperty + def subclasses_dict(cls): + return {subclass.__name__: subclass for subclass in cls.subclasses_list} + + @classproperty + def subclass_choices(cls): + return [(subclass.__name__, f"{subclass.title} – {subclass.description}") for subclass in cls.subclasses_list] diff --git a/pyproject.toml b/pyproject.toml index 5d3af51b6..5450eaeed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -126,6 +126,7 @@ python-gnupg = "^0.4.7" sentry-sdk = {version = "^1.4.3", optional = true} django-cte = "^1.1.5" pycountry = "^22.0.0" +django-ical = "^1.8.3" django-iconify = "^0.1.0" customidenticon = "^0.1.5" -- GitLab