diff --git a/lacommunaute/forum_conversation/models.py b/lacommunaute/forum_conversation/models.py index a00249f60..82dac428e 100644 --- a/lacommunaute/forum_conversation/models.py +++ b/lacommunaute/forum_conversation/models.py @@ -59,8 +59,8 @@ class Topic(AbstractTopic): tags = TaggableManager() - def get_absolute_url(self): - return reverse( + def get_absolute_url(self, with_fqdn=False): + absolute_url = reverse( "forum_conversation:topic", kwargs={ "forum_pk": self.forum.pk, @@ -70,6 +70,12 @@ def get_absolute_url(self): }, ) + # for tasks context, when we don't have access to request + if with_fqdn: + return f"{settings.COMMU_PROTOCOL}://{settings.COMMU_FQDN}{absolute_url}" + + return absolute_url + @property def poster_email(self): return self.first_post.username or self.first_post.poster.email diff --git a/lacommunaute/forum_conversation/tests/tests_models.py b/lacommunaute/forum_conversation/tests/tests_models.py index a1422c682..fae4576a7 100644 --- a/lacommunaute/forum_conversation/tests/tests_models.py +++ b/lacommunaute/forum_conversation/tests/tests_models.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.core.exceptions import ValidationError from django.db import IntegrityError from django.test import TestCase @@ -98,6 +99,10 @@ def test_get_absolute_url(self): }, ), ) + self.assertEqual( + topic.get_absolute_url(with_fqdn=True), + f"{settings.COMMU_PROTOCOL}://{settings.COMMU_FQDN}{topic.get_absolute_url()}", + ) def test_poster_email(self): topic = TopicFactory(with_post=True)