Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AlekSIS/official/AlekSIS-App-DashboardFeeds
  • sunweaver/AlekSIS-App-DashboardFeeds
2 results
Show changes
Commits on Source (3)
from django.contrib import admin from django.contrib import admin
from .models import DashboardWidget, RSSFeedWidget, ICalFeedWidget from .models import DashboardWidget, ICalFeedWidget, RSSFeedWidget
admin.site.register(DashboardWidget) admin.site.register(DashboardWidget)
admin.site.register(RSSFeedWidget) admin.site.register(RSSFeedWidget)
......
...@@ -3,7 +3,9 @@ from aleksis.core.util.apps import AppConfig ...@@ -3,7 +3,9 @@ from aleksis.core.util.apps import AppConfig
class DefaultConfig(AppConfig): class DefaultConfig(AppConfig):
name = "aleksis.apps.dashboardfeeds" name = "aleksis.apps.dashboardfeeds"
verbose_name = "AlekSIS — Dashboard Feeds (Feeds from external resources as dashboard widgets)" verbose_name = (
"AlekSIS — Dashboard Feeds (Feeds from external resources as dashboard widgets)"
)
urls = { urls = {
"Repository": "https://edugit.org/AlekSIS/official/AlekSIS-App-DashboardFeeds/", "Repository": "https://edugit.org/AlekSIS/official/AlekSIS-App-DashboardFeeds/",
......
# Generated by Django 3.0.2 on 2020-01-29 16:57 # Generated by Django 3.0.2 on 2020-01-29 16:57
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
...@@ -9,21 +9,37 @@ class Migration(migrations.Migration): ...@@ -9,21 +9,37 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('core', '0009_dashboard_widget'), ("core", "0009_dashboard_widget"),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='RSSFeedWidget', name="RSSFeedWidget",
fields=[ fields=[
('dashboardwidget_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.DashboardWidget')), (
('url', models.URLField(verbose_name='RSS Url')), "dashboardwidget_ptr",
('base_url', models.URLField(help_text='index url of the news website (as link for users)', verbose_name='Base URL')), models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="core.DashboardWidget",
),
),
("url", models.URLField(verbose_name="RSS Url")),
(
"base_url",
models.URLField(
help_text="index url of the news website (as link for users)",
verbose_name="Base URL",
),
),
], ],
options={ options={
'verbose_name': 'RSS Widget', "verbose_name": "RSS Widget",
'verbose_name_plural': 'RSS Widgets', "verbose_name_plural": "RSS Widgets",
}, },
bases=('core.dashboardwidget',), bases=("core.dashboardwidget",),
), ),
] ]
# Generated by Django 3.0.3 on 2020-03-13 15:42 # Generated by Django 3.0.3 on 2020-03-13 15:42
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('dashboardfeeds', '0001_initial'), ("dashboardfeeds", "0001_initial"),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='ICalFeedWidget', name="ICalFeedWidget",
fields=[ fields=[
('dashboardwidget_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.DashboardWidget')), (
('url', models.URLField(verbose_name='iCal URL')), "dashboardwidget_ptr",
('base_url', models.URLField(help_text='index url of the calendar (as link for users)', verbose_name='Base URL')), models.OneToOneField(
('events_count', models.IntegerField(default=5, verbose_name='number of displayed events')), auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="core.DashboardWidget",
),
),
("url", models.URLField(verbose_name="iCal URL")),
(
"base_url",
models.URLField(
help_text="index url of the calendar (as link for users)",
verbose_name="Base URL",
),
),
(
"events_count",
models.IntegerField(
default=5, verbose_name="number of displayed events"
),
),
], ],
options={ options={
'verbose_name': 'Ical Widget', "verbose_name": "Ical Widget",
'verbose_name_plural': 'Ical Widgets', "verbose_name_plural": "Ical Widgets",
}, },
bases=('core.dashboardwidget',), bases=("core.dashboardwidget",),
), ),
] ]
# Generated by Django 3.0.4 on 2020-03-18 12:12 # Generated by Django 3.0.4 on 2020-03-18 12:12
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('feeds', '0006_auto_20190901_1644'), ("feeds", "0006_auto_20190901_1644"),
('dashboardfeeds', '0002_icalfeedwidget'), ("dashboardfeeds", "0002_icalfeedwidget"),
] ]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='rssfeedwidget', model_name="rssfeedwidget",
name='rss_source', name="rss_source",
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='feeds.Source', verbose_name='Rss Source'), field=models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="feeds.Source",
verbose_name="Rss Source",
),
), ),
] ]
...@@ -6,13 +6,13 @@ from django.db import migrations, models ...@@ -6,13 +6,13 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('dashboardfeeds', '0003_rssfeedwidget_rss_source'), ("dashboardfeeds", "0003_rssfeedwidget_rss_source"),
] ]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='rssfeedwidget', model_name="rssfeedwidget",
name='text_only', name="text_only",
field=models.BooleanField(default=False, verbose_name='Text Only RSS Feed'), field=models.BooleanField(default=False, verbose_name="Text Only RSS Feed"),
), ),
] ]
import datetime import datetime
from typing import Optional
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
...@@ -15,12 +14,21 @@ class RSSFeedWidget(DashboardWidget): ...@@ -15,12 +14,21 @@ class RSSFeedWidget(DashboardWidget):
template = "dashboardfeeds/rss.html" template = "dashboardfeeds/rss.html"
url = models.URLField(verbose_name=_("RSS feed source URL")) url = models.URLField(verbose_name=_("RSS feed source URL"))
base_url = models.URLField(verbose_name=_("Base URL of related website"), base_url = models.URLField(
help_text=_("The widget will have a link to visit a related website to read more news")) verbose_name=_("Base URL of related website"),
text_only = models.BooleanField(verbose_name=_("Text only"), help_text=_("Do not show an image to depict the news item"), default=False) help_text=_(
"The widget will have a link to visit a related website to read more news"
rss_source = models.ForeignKey(Source, on_delete=models.CASCADE, editable=False, ),
null=True) )
text_only = models.BooleanField(
verbose_name=_("Text only"),
help_text=_("Do not show an image to depict the news item"),
default=False,
)
rss_source = models.ForeignKey(
Source, on_delete=models.CASCADE, editable=False, null=True
)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
# Update the linked RSS source object to transfer data into django-feeds # Update the linked RSS source object to transfer data into django-feeds
...@@ -64,9 +72,15 @@ class ICalFeedWidget(DashboardWidget): ...@@ -64,9 +72,15 @@ class ICalFeedWidget(DashboardWidget):
template = "dashboardfeeds/ical.html" template = "dashboardfeeds/ical.html"
url = models.URLField(verbose_name=_("iCalendar URL")) url = models.URLField(verbose_name=_("iCalendar URL"))
base_url = models.URLField(verbose_name=_("Base URL of related calendar"), base_url = models.URLField(
help_text=_("The widget will have a link to visit a related website to see more events")) verbose_name=_("Base URL of related calendar"),
events_count = models.IntegerField(verbose_name=_("Number of displayed events"), default=5) help_text=_(
"The widget will have a link to visit a related website to see more events"
),
)
events_count = models.IntegerField(
verbose_name=_("Number of displayed events"), default=5
)
def get_context(self): def get_context(self):
feed = { feed = {
......
INSTALLED_APPS = [ INSTALLED_APPS = [
'feeds', "feeds",
] ]
...@@ -5,6 +5,6 @@ from aleksis.core.util.core_helpers import celery_optional ...@@ -5,6 +5,6 @@ from aleksis.core.util.core_helpers import celery_optional
@celery_optional @celery_optional
def get_feeds(): def get_feeds():
""" Update RSS feeds through django-feeds """ """Update RSS feeds through django-feeds."""
return update_feeds(max_feeds=10) return update_feeds(max_feeds=10)
import logging import logging
import re
from django.utils import timezone, formats from django.utils import formats, timezone
from django.core.cache import cache
from ics import Calendar
from cache_memoize import cache_memoize
import requests import requests
from cache_memoize import cache_memoize
from ics import Calendar
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def get_current_events(calendar: Calendar, limit: int = 5) -> list: def get_current_events(calendar: Calendar, limit: int = 5) -> list:
""" Get upcoming events from a calendar (ICS) object """Get upcoming events from a calendar (ICS) object.
:param calendar: The calendar object :param calendar: The calendar object
:param limit: Count of events :param limit: Count of events
...@@ -52,22 +50,28 @@ def get_current_events(calendar: Calendar, limit: int = 5) -> list: ...@@ -52,22 +50,28 @@ def get_current_events(calendar: Calendar, limit: int = 5) -> list:
formatted = f"{begin_date_formatted}{end_date_formatted}" formatted = f"{begin_date_formatted}{end_date_formatted}"
else: else:
# Event has begin and end times # Event has begin and end times
formatted = f"{begin_date_formatted} {begin_time_formatted}{end_date_formatted} {end_time_formatted}" formatted = f(
"{begin_date_formatted} {begin_time_formatted} –"
events.append({ "{end_date_formatted} {end_time_formatted}"
"name": event.name, )
"begin_timestamp": event.begin.timestamp,
"end_timestamp": event.end.timestamp, events.append(
"date_formatted": formatted, {
}) "name": event.name,
"begin_timestamp": event.begin.timestamp,
"end_timestamp": event.end.timestamp,
"date_formatted": formatted,
}
)
return events return events
@cache_memoize(300) @cache_memoize(300)
def get_current_events_with_cal(calendar_url: str, limit: int = 5) -> list: def get_current_events_with_cal(calendar_url: str, limit: int = 5) -> list:
""" Download an iCalendar file from an URL, parse using the ICS library """
and return a limited number of events Download an iCalendar file from an URL, parse using the ICS library
and return a limited number of events.
""" """
try: try:
......
This diff is collapsed.