Merge pull request #1950 from bookwyrm-social/release-notice

Adds notice to admin about available updates
This commit is contained in:
Mouse Reeve 2022-02-17 16:37:22 -08:00 committed by GitHub
commit 98cad7c51a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 2 deletions

View file

@ -11,6 +11,11 @@ env.read_env()
DOMAIN = env("DOMAIN") DOMAIN = env("DOMAIN")
VERSION = "0.3.0" 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) PAGE_LENGTH = env("PAGE_LENGTH", 15)
DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")

View file

@ -48,6 +48,7 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
{% if pending_domains %} {% if pending_domains %}
<div class="column"> <div class="column">
<a href="{% url 'settings-link-domain' %}" class="notification is-primary is-block"> <a href="{% url 'settings-link-domain' %}" class="notification is-primary is-block">
@ -59,9 +60,10 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
{% if not site.allow_registration and site.allow_invite_requests and invite_requests %} {% if not site.allow_registration and site.allow_invite_requests and invite_requests %}
<div class="column"> <div class="column">
<a href="{% url 'settings-invite-requests' %}" class="notification is-block is-success is-light"> <a href="{% url 'settings-invite-requests' %}" class="notification is-block is-success">
{% blocktrans trimmed count counter=invite_requests with display_count=invite_requests|intcomma %} {% blocktrans trimmed count counter=invite_requests with display_count=invite_requests|intcomma %}
{{ display_count }} invite request {{ display_count }} invite request
{% plural %} {% plural %}
@ -70,6 +72,16 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
{% if current_version %}
<div class="column">
<a href="https://docs.joinbookwyrm.com/updating-your-instance.html" class="notification is-block is-warning" target="_blank">
{% 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 %}
</a>
</div>
{% endif %}
</div> </div>
<div class="block content"> <div class="block content">

View file

@ -1,6 +1,7 @@
""" instance overview """ """ instance overview """
from datetime import timedelta from datetime import timedelta
from dateutil.parser import parse from dateutil.parser import parse
from packaging import version
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import Q from django.db.models import Q
@ -9,7 +10,9 @@ from django.utils import timezone
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View 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 # pylint: disable= no-self-use
@ -107,6 +110,19 @@ class Dashboard(View):
"register_stats": register_chart.get_chart(start, end, interval), "register_stats": register_chart.get_chart(start, end, interval),
"works_stats": works_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) return TemplateResponse(request, "settings/dashboard/dashboard.html", data)