From bb897ad68c77cc3df2fd693605f3e30810e70152 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Mon, 11 Sep 2023 12:19:59 +0200 Subject: [PATCH] =?UTF-8?q?feat(forum=5Fconversation):=C2=A0update=20topic?= =?UTF-8?q?.get=5Fabsolute=5Furl=20to=20get=20url=20with=20fqdn=20&=20prot?= =?UTF-8?q?ocol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/forum_conversation/models.py | 10 ++++++++-- lacommunaute/forum_conversation/tests/tests_models.py | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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)