summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example_project/settings.py1
-rw-r--r--ishtar_common/templates/index.html6
-rw-r--r--ishtar_common/utils.py37
-rw-r--r--ishtar_common/views.py2
-rw-r--r--requirements.txt4
-rw-r--r--requirements_rtd.txt1
-rw-r--r--scss/custom.scss6
7 files changed, 54 insertions, 3 deletions
diff --git a/example_project/settings.py b/example_project/settings.py
index cc2e44b3d..6d293ca36 100644
--- a/example_project/settings.py
+++ b/example_project/settings.py
@@ -268,6 +268,7 @@ LIBREOFFICE_HOST = "localhost"
# Ishtar custom
+ISHTAR_FEED_URL = "https://discourse.ishtar-archeo.net/latest.rss"
ISHTAR_MAP_MAX_ITEMS = 50000
ISHTAR_QRCODE_VERSION = 6 # density of the QR code
ISHTAR_QRCODE_SCALE = 2 # scale of the QR code
diff --git a/ishtar_common/templates/index.html b/ishtar_common/templates/index.html
index 69bc52617..eaaf7dd54 100644
--- a/ishtar_common/templates/index.html
+++ b/ishtar_common/templates/index.html
@@ -2,6 +2,12 @@
{% load i18n %}
{% block content %}<div id="welcome" class="container">
<h2>{{welcome_title}}</h2>
+ {% if news_feed %}
+ <div id="news-feed" class="card p-3 mb-4">
+ <h3><i class="fa fa-newspaper-o" aria-hidden="true"></i> &nbsp;{% trans "Latest news" %}</h3>
+ {{ news_feed|safe }}
+ </div>
+ {% endif %}
<div class="row">
{% if display_random_image %}
{{random_image}}
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 95a7ebbaa..bf64339e4 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
@@ -20,6 +19,7 @@
from cairosvg import svg2png
from csv import QUOTE_ALL
import datetime
+import feedparser
from functools import wraps
from itertools import chain
from inspect import currentframe, getframeinfo
@@ -34,6 +34,7 @@ import locale
import math
import numpy
import os
+import pytz
import random
import re
import requests
@@ -2827,6 +2828,40 @@ class EachCharacterTypeValidator:
) + str(_("."))
+def get_news_feed():
+ cache_key = f"{settings.PROJECT_SLUG}-news_feed"
+ news_feed = cache.get(cache_key)
+ if news_feed is None:
+ news_feed = update_news_feed()
+ cache.set(cache_key, news_feed, timeout=settings.CACHE_TIMEOUT)
+ return news_feed
+
+
+def update_news_feed():
+ feed = feedparser.parse(settings.ISHTAR_FEED_URL)
+ news_feed = []
+ if "entries" in feed:
+ for entry in feed["entries"][:5]:
+ published = entry.published
+ try:
+ locale.setlocale(locale.LC_TIME, "en_GB")
+ d = datetime.datetime.strptime(published, "%a, %d %b %Y %H:%M:%S %z")
+ d_aware = d.replace(tzinfo=pytz.timezone(settings.TIME_ZONE))
+ lang_code = settings.LANGUAGE_CODE.split("-")
+ lang_code = lang_code[0] + "_" + lang_code[1].upper()
+ locale.setlocale(locale.LC_TIME, lang_code)
+ published = d_aware.strftime("%d %b %Y %H:%M")
+ except ValueError:
+ published = "&ndash;"
+ desc = f"""<div class="row">
+ <div class="col-3 date">{published}</div>
+ <div class="col-9"><a href="{entry['link']}" target="_blank">{entry['title']}</a></div>
+</div>
+"""
+ news_feed.append(desc)
+ return "".join(news_feed)
+
+
# picked from Django 3.2 to assure 128 bites salt - should be removed on upgrade
class Argon2PasswordHasher(BaseArgon2PasswordHasher):
salt_entropy = 128
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index a6c3b373d..557fb1412 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -82,6 +82,7 @@ from ishtar_common.utils import (
get_field_labels_from_path,
get_person_gdpr_log,
get_random_item_image_link,
+ get_news_feed,
shortify,
dict_to_tuple,
put_session_message,
@@ -207,6 +208,7 @@ def index(request):
)
)
authenticated = request.user.is_authenticated
+ dct["news_feed"] = get_news_feed()
display_random_image = authenticated and profile.homepage_random_image_available
if display_random_image:
dct["display_random_image"] = True
diff --git a/requirements.txt b/requirements.txt
index d5344e5b0..22c9a4a2d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -70,6 +70,8 @@ pandas==1.1.5
django-ipware==3.0.0
django-axes==5.4.3
num2words==0.5.9
+feedparser==6.0.11
+# debian bullseye is feedparser==5.2.1 but with python3.9 backport
-# TODO v5: python3-pathvalidate -> libreoffice.py \ No newline at end of file
+# TODO v5: python3-pathvalidate -> libreoffice.py
diff --git a/requirements_rtd.txt b/requirements_rtd.txt
index b5b1f127f..31c781b47 100644
--- a/requirements_rtd.txt
+++ b/requirements_rtd.txt
@@ -1,2 +1 @@
-sphinx_rtd_theme
sphinx-book-theme
diff --git a/scss/custom.scss b/scss/custom.scss
index 6e27c8ddf..58b81cae2 100644
--- a/scss/custom.scss
+++ b/scss/custom.scss
@@ -747,6 +747,12 @@ div#validation-bar{
width: 100%;
}
+#news-feed {
+ .date {
+ color: $gray-600;
+ }
+}
+
.container.changelog{
padding-left: 170px;
h1 .fa, .version .date {