From 9132c054f26ee2327582b000d41fa3b680731f0c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 17 Feb 2022 16:23:15 -0800 Subject: [PATCH 1/2] Adds notice to admin about available updates --- bookwyrm/settings.py | 5 +++++ .../templates/settings/dashboard/dashboard.html | 14 +++++++++++++- bookwyrm/views/admin/dashboard.py | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 520b424e..01528b81 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -11,6 +11,11 @@ env.read_env() DOMAIN = env("DOMAIN") VERSION = "0.3.0" +RELEASE_API = env( + "RELEASE_API", + "https://api.github.com/repos/bookwyrm-social/bookwyrm/releases/latest" +) + PAGE_LENGTH = env("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") diff --git a/bookwyrm/templates/settings/dashboard/dashboard.html b/bookwyrm/templates/settings/dashboard/dashboard.html index 65c666a6..45c4d22f 100644 --- a/bookwyrm/templates/settings/dashboard/dashboard.html +++ b/bookwyrm/templates/settings/dashboard/dashboard.html @@ -48,6 +48,7 @@ {% endif %} + {% if pending_domains %}
@@ -59,9 +60,10 @@
{% endif %} + {% if not site.allow_registration and site.allow_invite_requests and invite_requests %}
- + {% blocktrans trimmed count counter=invite_requests with display_count=invite_requests|intcomma %} {{ display_count }} invite request {% plural %} @@ -70,6 +72,16 @@
{% endif %} + + {% if current_version %} +
+ + {% blocktrans trimmed with current=current_version available=available_version %} + An update is available! You're running v{{ current }} and the latest release is {{ available }}. + {% endblocktrans %} + +
+ {% endif %}
diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index 6c6ab009..9476e3ff 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -1,6 +1,7 @@ """ instance overview """ from datetime import timedelta from dateutil.parser import parse +from packaging import version from django.contrib.auth.decorators import login_required, permission_required from django.db.models import Q @@ -9,7 +10,9 @@ from django.utils import timezone from django.utils.decorators import method_decorator from django.views import View -from bookwyrm import models +from bookwyrm import models, settings +from bookwyrm.connectors.abstract_connector import get_data +from bookwyrm.connectors.connector_manager import ConnectorException # pylint: disable= no-self-use @@ -107,6 +110,17 @@ class Dashboard(View): "register_stats": register_chart.get_chart(start, end, interval), "works_stats": works_chart.get_chart(start, end, interval), } + + # check version + try: + release = get_data(settings.RELEASE_API, timeout=3) + available_version = release.get("tag_name", None) + if available_version and version.parse(available_version) > version.parse(settings.VERSION): + data["current_version"] = settings.VERSION + data["available_version"] = available_version + except ConnectorException: + pass + return TemplateResponse(request, "settings/dashboard/dashboard.html", data) From 3869f0cc1a3d844172979f043179ed786d9fa71c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 17 Feb 2022 16:28:55 -0800 Subject: [PATCH 2/2] Python formatting --- bookwyrm/settings.py | 2 +- bookwyrm/views/admin/dashboard.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 01528b81..7bbdef66 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -13,7 +13,7 @@ VERSION = "0.3.0" RELEASE_API = env( "RELEASE_API", - "https://api.github.com/repos/bookwyrm-social/bookwyrm/releases/latest" + "https://api.github.com/repos/bookwyrm-social/bookwyrm/releases/latest", ) PAGE_LENGTH = env("PAGE_LENGTH", 15) diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index 9476e3ff..92fb0185 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -115,7 +115,9 @@ class Dashboard(View): try: release = get_data(settings.RELEASE_API, timeout=3) available_version = release.get("tag_name", None) - if available_version and version.parse(available_version) > version.parse(settings.VERSION): + if available_version and version.parse(available_version) > version.parse( + settings.VERSION + ): data["current_version"] = settings.VERSION data["available_version"] = available_version except ConnectorException: