Skip to content

Commit

Permalink
feat(forum_conversation): update topic.get_absolute_url to get url wi…
Browse files Browse the repository at this point in the history
…th fqdn & protocol
  • Loading branch information
vincentporte committed Sep 11, 2023
1 parent 3ff3fc9 commit bb897ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lacommunaute/forum_conversation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lacommunaute/forum_conversation/tests/tests_models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bb897ad

Please sign in to comment.