Skip to content
Snippets Groups Projects
Commit 8b6dc217 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch 'prepare-release-2.0rc1' into 'release/2.0'

Prepare release 2.0rc1

See merge request !56
parents e9188376 3f175713
No related branches found
No related tags found
1 merge request!56Prepare release 2.0rc1
Pipeline #18857 passed
......@@ -6,6 +6,19 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog`_,
and this project adheres to `Semantic Versioning`_.
`2.0rc1`_ - 2021-06-23
----------------------
Changed
~~~~~~~
* Increase cache time for events to one hour.
Fixed
~~~~~
* Don't delete cache if there was an error while receiving the events.
`2.0b0`_ - 2021-05-21
---------------------
......@@ -37,5 +50,6 @@ Added
.. _2.0a2: https://edugit.org/AlekSIS/Official/AlekSIS-App-DashboardFeeds/-/tags/2.0a2
.. _2.0b0: https://edugit.org/AlekSIS/Official/AlekSIS-App-DashboardFeeds/-/tags/2.0b0
.. _2.0rc1: https://edugit.org/AlekSIS/Official/AlekSIS-App-DashboardFeeds/-/tags/2.0rc1
import datetime
import logging
from django.contrib import messages
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver
......@@ -11,6 +13,8 @@ from aleksis.core.models import DashboardWidget
from .util.event_feed import get_current_events_with_cal
logger = logging.getLogger(__name__)
class RSSFeedWidget(DashboardWidget):
template = "dashboardfeeds/rss.html"
......@@ -82,10 +86,16 @@ class ICalFeedWidget(DashboardWidget):
events_count = models.IntegerField(verbose_name=_("Number of displayed events"), default=5)
def get_context(self, request):
events, errors = get_current_events_with_cal(self.url, self.events_count, request)
if errors:
try:
events = get_current_events_with_cal(self.url, self.events_count)
except Exception as e:
events = []
logger.error(str(e))
self.broken = True
self.save()
if request:
messages.error(request, _("There was an error getting your calendar."))
feed = {
"base_url": self.base_url,
"feed_events": events,
......
import logging
from datetime import timedelta
from typing import Optional, Tuple
from django.contrib import messages
from django.http import HttpRequest
from django.utils import formats, timezone
from django.utils.translation import gettext_lazy as _
import requests
from cache_memoize import cache_memoize
from ics import Calendar
logger = logging.getLogger(__name__)
def get_current_events(calendar: Calendar, limit: int = 5) -> list:
"""Get upcoming events from a calendar (ICS) object.
......@@ -75,27 +68,13 @@ def get_current_events(calendar: Calendar, limit: int = 5) -> list:
return events
@cache_memoize(300)
def get_current_events_with_cal(
calendar_url: str, limit: int = 5, request: Optional[HttpRequest] = None
) -> Tuple[list, list]:
@cache_memoize(3600)
def get_current_events_with_cal(calendar_url: str, limit: int = 5) -> list:
"""Get current events.
Download an iCalendar file from an URL, parse using the ICS library
and return a limited number of events.
"""
try:
content = requests.get(calendar_url, timeout=3)
except requests.RequestException as e:
logger.error(str(e))
return [], [str(e)]
try:
calendar: Calendar = Calendar(content.text)
except Exception as e:
logger.error(str(e))
if request:
messages.error(request, _("There was an error getting your calendar"))
return [], [str(e)]
return get_current_events(calendar, limit), []
content = requests.get(calendar_url, timeout=3)
calendar: Calendar = Calendar(content.text)
return get_current_events(calendar, limit)
This diff is collapsed.
[tool.poetry]
name = "AlekSIS-App-DashboardFeeds"
version = "2.0b0"
version = "2.0rc1"
packages = [
{ include = "aleksis" }
]
......@@ -32,9 +32,9 @@ secondary = true
[tool.poetry.dependencies]
python = "^3.9"
feedparser = "^6.0.0"
django-feed-reader = "^0.3.0"
django-feed-reader = "^1.0.0"
ics = "^0.7"
aleksis-core = "^2.0b0"
aleksis-core = "^2.0rc"
[tool.poetry.dev-dependencies]
aleksis-builddeps = "*"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment