diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index d7b3909..9554190 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -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: diff --git a/src/agenda_culturel/templates/agenda_culturel/page-event.html b/src/agenda_culturel/templates/agenda_culturel/page-event.html index 142defe..42f0276 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-event.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-event.html @@ -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 %} diff --git a/src/agenda_culturel/templatetags/event_extra.py b/src/agenda_culturel/templatetags/event_extra.py index 32bdee7..4dd5be9 100644 --- a/src/agenda_culturel/templatetags/event_extra.py +++ b/src/agenda_culturel/templatetags/event_extra.py @@ -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('TW') else: - return "" \ No newline at end of file + return "" + +@register.filter +def get_image_uri(event, request): + return event.get_image_url(request) \ No newline at end of file