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()
|
||||
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):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<div>
|
||||
<strong>Subject:</strong> {% include subject_path %}
|
||||
|
|
|
@ -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}"
|
||||
|
|
Loading…
Reference in a new issue