L'image a une url absolue

This commit is contained in:
Jean-Marie Favreau 2024-11-29 12:43:20 +01:00
parent 1256adcb8a
commit bf773686f9
3 changed files with 11 additions and 4 deletions

View File

@ -923,10 +923,13 @@ class Event(models.Model):
else:
return recurrences[0]
def get_image_url(self):
def get_image_url(self, request=None):
if self.local_image and hasattr(self.local_image, "url"):
try:
return self.local_image.url
if request:
return request.build_absolute_uri(self.local_image.url)
else:
return self.local_image.url
except:
pass
if self.image:

View File

@ -6,7 +6,7 @@
{% block title %}{% block og_title %}{{ event.title }}{% endblock %}{% endblock %}
{% block og_image %}{% if event.has_image_url %}{{ event.get_image_url }}{% else %}{{ block.super }}{% endif %}{% endblock %}
{% block og_image %}{% if event.has_image_url %}{{ event|get_image_uri:request }}{% else %}{{ block.super }}{% endif %}{% endblock %}
{% block og_description %}{% if event.description %}{{ event.description |truncatewords:20|linebreaks }}{% else %}{{ block.super }}{% endif %}{% endblock %}
{% block entete_header %}

View File

@ -179,4 +179,8 @@ def tw_badge(event):
if event.tags and len([t for t in event.tags if t.startswith("TW:")]) > 0:
return mark_safe('<span class="badge tw-badge">TW</span>')
else:
return ""
return ""
@register.filter
def get_image_uri(event, request):
return event.get_image_url(request)