Skip to content

Commit

Permalink
Show release notes in CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
timobrembeck committed Mar 22, 2023
1 parent 84cdddb commit 5b48e1d
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 16 deletions.
5 changes: 4 additions & 1 deletion integreat_cms/cms/templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@
{% endif %}
{% endif %}
</div>
<div class="p-2 text-center absolute inset-x-0 bottom-0 bg-gray-600">{% translate "Version" %}: {{ version }}</div>
<div class="p-2 text-center absolute inset-x-0 bottom-0 bg-gray-600">
<a href="{% if request.region %}{% url "release_notes" region_slug=request.region.slug %}{% else %}{% url "release_notes" %}{% endif %}"
class="hover:underline">{% translate "Version" %}: {{ version }}</a>
</div>
</nav>
<main class="relative min-h-screen flex lg:pl-72 pt-14 bg-gray-100">
<div class="flex-1 min-w-0 p-6">
Expand Down
5 changes: 5 additions & 0 deletions integreat_cms/cms/templates/dashboard/admin_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ <h1 class="heading">{% translate "Admin Dashboard" %}</h1>
{% if chat_form %}
{% include "chat/_chat_widget.html" with box_id="dashboard-chat" %}
{% endif %}
{% for year, versions in release_notes.items %}
{% for version, notes in versions.items %}
{% include "release_notes/latest_release_widget.html" with box_id="latest-release" %}
{% endfor %}
{% endfor %}
</div>
<div class="xl:w-1/2">
<!-- Feedback Widget -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "_collapsible_box.html" %}
{% load i18n %}
{% load static %}
{% block collapsible_box_icon %}
scroll
{% endblock collapsible_box_icon %}
{% block collapsible_box_title %}
{% if version == "unreleased" %}
{% translate "Changes that will be released soon" %}
{% else %}
{% blocktranslate trimmed %}
What's new in version {{ version}}?
{% endblocktranslate %}
{% endif %}
{% endblock collapsible_box_title %}
{% block collapsible_box_content %}
{% include "release_notes/version.html" %}
<a href="{% url "release_notes" %}" class="btn">
<i icon-name="scroll"></i>
{% translate "Display all release notes" %}
</a>
{% endblock collapsible_box_content %}
27 changes: 27 additions & 0 deletions integreat_cms/cms/templates/release_notes/release_notes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "_base.html" %}
{% load i18n %}
{% load widget_tweaks %}
{% block content %}
<div>
<h1 class="heading !mb-3">
<i icon-name="scroll"></i> {% translate "Release notes" %}
</h1>
{% for year, versions in release_notes.items %}
{% for version, notes in versions.items %}
{% if version == "unreleased" %}
<h2 class="text-xl mb-2">
<span class="italic">{% translate "Unreleased" %}</span>
</h2>
{% else %}
<h2 class="text-2xl mb-2">
<a href="https://github.com/digitalfabrik/integreat-cms/releases/tag/{{ version }}"
class="hover:underline"
target="_blank"
rel="noopener noreferrer">{{ version }}</a>
</h2>
{% endif %}
{% include "release_notes/version.html" %}
{% endfor %}
{% endfor %}
</div>
{% endblock content %}
12 changes: 12 additions & 0 deletions integreat_cms/cms/templates/release_notes/version.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ul class="ml-6 mb-3 list-disc">
{% for issue, note in notes.items %}
<li>
<span class="inline-block w-20">[
<a href="https://github.com/digitalfabrik/integreat-cms/issues/{{ issue }}"
class="text-blue-500 hover:underline"
target="_blank"
rel="noopener noreferrer">#{{ issue }}</a>
]</span> {{ note }}
</li>
{% endfor %}
</ul>
11 changes: 11 additions & 0 deletions integreat_cms/cms/urls/protected.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
pois,
push_notifications,
regions,
release_notes,
roles,
settings,
statistics,
Expand Down Expand Up @@ -487,6 +488,11 @@
]
),
),
path(
"release-notes/",
release_notes.ReleaseNotesView.as_view(),
name="release_notes",
),
path(
"<region_slug>/",
include(
Expand Down Expand Up @@ -1355,6 +1361,11 @@
),
),
path("", include(user_settings_urlpatterns)),
path(
"release-notes/",
release_notes.ReleaseNotesView.as_view(),
name="release_notes",
),
]
),
),
Expand Down
5 changes: 4 additions & 1 deletion integreat_cms/cms/views/dashboard/admin_dashboard_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

from ...models import Feedback
from ..chat.chat_context_mixin import ChatContextMixin
from ..release_notes.release_notes_context_mixin import ReleaseNotesContextMixin

logger = logging.getLogger(__name__)


class AdminDashboardView(TemplateView, ChatContextMixin):
class AdminDashboardView(TemplateView, ChatContextMixin, ReleaseNotesContextMixin):
"""
View for the admin dashboard
"""
Expand All @@ -17,6 +18,8 @@ class AdminDashboardView(TemplateView, ChatContextMixin):
template_name = "dashboard/admin_dashboard.html"
#: The context dict passed to the template (see :class:`~django.views.generic.base.ContextMixin`)
extra_context = {"current_menu_item": "admin_dashboard"}
#: Whether only the latest release notes should be included
only_latest_release = True

def get_context_data(self, **kwargs):
r"""
Expand Down
1 change: 1 addition & 0 deletions integreat_cms/cms/views/release_notes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .release_notes_view import ReleaseNotesView
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import logging
from contextlib import ExitStack
from pathlib import Path

import yaml
from django.conf import settings
from django.utils.translation import get_language_from_request
from django.views.generic.base import ContextMixin
from natsort import natsorted

logger = logging.getLogger(__name__)


class ReleaseNotesContextMixin(ContextMixin):
"""
This mixin provides the release notes context (see :class:`~django.views.generic.base.ContextMixin`)
"""

#: Whether only the latest release notes should be included
only_latest_release = False

def __init__(self):
self.slice = 1 if self.only_latest_release else None

def get_context_data(self, **kwargs):
r"""
Extend context by release notes
:param \**kwargs: The supplied keyword arguments
:type \**kwargs: dict
:return: The context dictionary
:rtype: dict
"""
context = super().get_context_data(**kwargs)
context["release_notes"] = self.get_release_notes()
return context

def get_release_notes(self):
"""
Get all release notes
:return: The release note dict
:rtype: dict
"""
return {
year.name: self.get_versions(year)
for year in sorted(
Path(settings.RELEASE_NOTES_DIRS).iterdir(), reverse=True
)[: self.slice]
}

def get_versions(self, year):
"""
Get all versions of one year
:return: The version dict
:rtype: dict
"""
return {
version.name: self.get_entries(version)
for version in natsorted(year.iterdir(), reverse=True)[: self.slice]
}

def get_entries(self, version):
"""
Get all entries of one version
:return: The entry dict
:rtype: dict
"""
# Use exit stack to close file descriptors after list comprehension
with ExitStack() as stack:
return {
note.stem: yaml.safe_load(
stack.enter_context(open(note, encoding="UTF-8"))
)[get_language_from_request(self.request)]
for note in natsorted(version.iterdir())
}
12 changes: 12 additions & 0 deletions integreat_cms/cms/views/release_notes/release_notes_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.views.generic.base import TemplateView

from .release_notes_context_mixin import ReleaseNotesContextMixin


class ReleaseNotesView(TemplateView, ReleaseNotesContextMixin):
"""
View for retrieving the release notes
"""

#: The template to render (see :class:`~django.views.generic.base.TemplateResponseMixin`)
template_name = "release_notes/release_notes.html"
3 changes: 3 additions & 0 deletions integreat_cms/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
os.environ.get("INTEGREAT_CMS_DEFAULT_REQUEST_TIMEOUT", 10)
)

#: Where release notes are stored
RELEASE_NOTES_DIRS = os.path.join(BASE_DIR, "release_notes")


##############################################################
# Firebase Push Notifications (Firebase Cloud Messaging FCM) #
Expand Down
21 changes: 21 additions & 0 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6423,6 +6423,27 @@ msgstr "Noch keine Regionen vorhanden."
msgid "Open Dashboard"
msgstr "Dashboard öffnen"

#: cms/templates/release_notes/latest_release_widget.html
msgid "Changes that will be released soon"
msgstr "Änderungen, die demnächst veröffentlicht werden"

#: cms/templates/release_notes/latest_release_widget.html
#, python-format
msgid "What's new in version %(version)s?"
msgstr "Was gibt es Neues in Version %(version)s?"

#: cms/templates/release_notes/latest_release_widget.html
msgid "Display all release notes"
msgstr "Änderungsprotokoll öffnen"

#: cms/templates/release_notes/release_notes.html
msgid "Release notes"
msgstr "Änderungsprotokoll"

#: cms/templates/release_notes/release_notes.html
msgid "Unreleased"
msgstr "Unveröffentlicht"

#: cms/templates/roles/role_form.html
#, python-format
msgid "Edit role \"%(role_name)s\""
Expand Down
2 changes: 2 additions & 0 deletions integreat_cms/release_notes/current/unreleased/2131.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en: The release notes are now displayed in the CMS
de: Das Änderungsprotokoll wird jetzt im CMS angezeigt
31 changes: 17 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ dependencies = [
"ipython",
"jsonschema",
"lxml",
"natsort",
"Pillow",
"psycopg2-binary",
"pyotp",
"python-dateutil",
"python-magic",
"pyyaml",
"qrcode",
"requests",
"rules",
Expand Down Expand Up @@ -115,15 +117,15 @@ pinned = [
"cbor2==5.4.6",
"certifi==2022.12.7",
"cffi==1.15.1",
"charset-normalizer==3.0.1",
"charset-normalizer==3.1.0",
"click==8.1.3",
"cryptography==39.0.1",
"cryptography==39.0.2",
"cssselect2==0.7.0",
"decorator==5.1.1",
"deepl==1.13.0",
"deepl==1.14.0",
"Django==3.2.18",
"django-cacheops==6.1",
"django-cors-headers==3.13.0",
"django-cacheops==7.0",
"django-cors-headers==3.14.0",
"django-db-mutex==3.0.0",
"django_debug_toolbar==3.8.1",
"django-linkcheck==2.1.0",
Expand All @@ -140,26 +142,27 @@ pinned = [
"geopy==2.3.0",
"html5lib==1.1",
"idna==3.4",
"ipython==8.10.0",
"ipython==8.11.0",
"jedi==0.18.2",
"jsonschema==4.17.3",
"lxml==4.9.2",
"matplotlib-inline==0.1.6",
"multidict==6.0.4",
"natsort==8.3.1",
"oscrypto==1.3.0",
"parso==0.8.3",
"pexpect==4.8.0",
"pickleshare==0.7.5",
"Pillow==9.4.0",
"prompt-toolkit==3.0.36",
"prompt-toolkit==3.0.38",
"psycopg2-binary==2.9.5",
"ptyprocess==0.7.0",
"pure-eval==0.2.2",
"pycparser==2.21",
"pydantic==1.10.5",
"pydantic==1.10.6",
"Pygments==2.14.0",
"pyHanko==0.17.0",
"pyhanko-certvalidator==0.20.0",
"pyHanko==0.17.2",
"pyhanko-certvalidator==0.20.1",
"pyOpenSSL==23.0.0",
"pyotp==2.8.0",
"PyPDF3==1.0.6",
Expand All @@ -182,15 +185,15 @@ pinned = [
"stack-data==0.6.2",
"svglib==1.5.1",
"tinycss2==1.2.1",
"tqdm==4.64.1",
"tqdm==4.65.0",
"traitlets==5.9.0",
"typing_extensions==4.5.0",
"tzdata==2022.7",
"tzlocal==4.2",
"tzlocal==4.3",
"uritools==4.0.1",
"urllib3==1.26.14",
"urllib3==1.26.15",
"wcwidth==0.2.6",
"webauthn==1.7.2",
"webauthn==1.8.0",
"webencodings==0.5.1",
"xhtml2pdf==0.2.8",
"yarl==1.8.2",
Expand Down
2 changes: 2 additions & 0 deletions tests/cms/views/view_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
("new_user", STAFF_ROLES),
("offertemplates", STAFF_ROLES),
("poicategories", STAFF_ROLES),
("release_notes", STAFF_ROLES),
("regions", STAFF_ROLES),
("roles", [ROOT]),
("user_settings", STAFF_ROLES),
Expand Down Expand Up @@ -119,6 +120,7 @@
HIGH_PRIV_STAFF_ROLES + [MANAGEMENT],
{"username": "new_username", "email": "new@email.address", "role": 1},
),
("release_notes", ROLES),
("region_feedback", STAFF_ROLES + [MANAGEMENT]),
("region_users", STAFF_ROLES + [MANAGEMENT]),
("translation_coverage", STAFF_ROLES + [MANAGEMENT, EDITOR]),
Expand Down

0 comments on commit 5b48e1d

Please sign in to comment.