forked from mirrors/bookwyrm
Updates image helpers on site
This commit is contained in:
parent
41dd915d7f
commit
3787a31c67
3 changed files with 23 additions and 15 deletions
|
@ -68,12 +68,27 @@ class SiteSettings(models.Model):
|
||||||
default_settings.save()
|
default_settings.save()
|
||||||
return default_settings
|
return default_settings
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logo_url(self):
|
||||||
|
"""helper to build the logo url"""
|
||||||
|
return self.get_url("logo", "images/logo.png")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logo_small_url(self):
|
def logo_small_url(self):
|
||||||
""" helper to build the lgoo url """
|
"""helper to build the logo url"""
|
||||||
if self.logo_small:
|
return self.get_url("logo_small", "images/logo-small.png")
|
||||||
return get_absolute_url(self.logo_small)
|
|
||||||
return urljoin(STATIC_FULL_URL, "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):
|
class SiteInvite(models.Model):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<html>
|
<html lang="en">
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<strong>Subject:</strong> {% include subject_path %}
|
<strong>Subject:</strong> {% include subject_path %}
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.utils import timezone
|
||||||
from django.views.decorators.http import require_GET
|
from django.views.decorators.http import require_GET
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
from bookwyrm.settings import DOMAIN, VERSION, MEDIA_FULL_URL, STATIC_FULL_URL
|
from bookwyrm.settings import DOMAIN, VERSION
|
||||||
|
|
||||||
|
|
||||||
@require_GET
|
@require_GET
|
||||||
|
@ -93,7 +93,7 @@ def instance_info(_):
|
||||||
status_count = models.Status.objects.filter(user__local=True, deleted=False).count()
|
status_count = models.Status.objects.filter(user__local=True, deleted=False).count()
|
||||||
|
|
||||||
site = models.SiteSettings.get()
|
site = models.SiteSettings.get()
|
||||||
logo = get_image_url(site.logo, "logo.png")
|
logo = site.logo_url
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{
|
{
|
||||||
"uri": DOMAIN,
|
"uri": DOMAIN,
|
||||||
|
@ -134,14 +134,7 @@ def host_meta(request):
|
||||||
def opensearch(request):
|
def opensearch(request):
|
||||||
"""Open Search xml spec"""
|
"""Open Search xml spec"""
|
||||||
site = models.SiteSettings.get()
|
site = models.SiteSettings.get()
|
||||||
image = get_image_url(site.favicon, "favicon.png")
|
image = site.favicon_url
|
||||||
return TemplateResponse(
|
return TemplateResponse(
|
||||||
request, "opensearch.xml", {"image": image, "DOMAIN": DOMAIN}
|
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}"
|
|
||||||
|
|
Loading…
Reference in a new issue