diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index a5d2df4e..5d91553e 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -68,12 +68,27 @@ class SiteSettings(models.Model): default_settings.save() return default_settings + @property + def logo_url(self): + """helper to build the logo url""" + return self.get_url("logo", "images/logo.png") + @property def logo_small_url(self): - """ helper to build the lgoo url """ - if self.logo_small: - return get_absolute_url(self.logo_small) - return urljoin(STATIC_FULL_URL, "images/logo-small.png") + """helper to build the logo url""" + return self.get_url("logo_small", "images/logo-small.png") + + @property + def favicon_url(self): + """helper to build the logo url""" + return self.get_url("favicon", "images/favicon.png") + + def get_url(self, field, default_path): + """get a media url or a default static path""" + uploaded = getattr(self, field, None) + if uploaded: + return get_absolute_url(uploaded) + return urljoin(STATIC_FULL_URL, default_path) class SiteInvite(models.Model): diff --git a/bookwyrm/templates/email/preview.html b/bookwyrm/templates/email/preview.html index 66d856c0..42f8707a 100644 --- a/bookwyrm/templates/email/preview.html +++ b/bookwyrm/templates/email/preview.html @@ -1,4 +1,4 @@ - +
Subject: {% include subject_path %} diff --git a/bookwyrm/views/wellknown.py b/bookwyrm/views/wellknown.py index a9b35b63..04aa88bf 100644 --- a/bookwyrm/views/wellknown.py +++ b/bookwyrm/views/wellknown.py @@ -9,7 +9,7 @@ from django.utils import timezone from django.views.decorators.http import require_GET from bookwyrm import models -from bookwyrm.settings import DOMAIN, VERSION, MEDIA_FULL_URL, STATIC_FULL_URL +from bookwyrm.settings import DOMAIN, VERSION @require_GET @@ -93,7 +93,7 @@ def instance_info(_): status_count = models.Status.objects.filter(user__local=True, deleted=False).count() site = models.SiteSettings.get() - logo = get_image_url(site.logo, "logo.png") + logo = site.logo_url return JsonResponse( { "uri": DOMAIN, @@ -134,14 +134,7 @@ def host_meta(request): def opensearch(request): """Open Search xml spec""" site = models.SiteSettings.get() - image = get_image_url(site.favicon, "favicon.png") + image = site.favicon_url return TemplateResponse( request, "opensearch.xml", {"image": image, "DOMAIN": DOMAIN} ) - - -def get_image_url(obj, fallback): - """helper for loading the full path to an image""" - if obj: - return f"{MEDIA_FULL_URL}{obj}" - return f"{STATIC_FULL_URL}images/{fallback}"