Skip to content

Commit

Permalink
feat(Forum): add get_absolute_url to forum model for social_share pur…
Browse files Browse the repository at this point in the history
…poses
  • Loading branch information
vincentporte committed Jul 18, 2023
1 parent 7a44b2d commit d3ac3a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib.auth.models import Group
from django.db import models
from django.urls import reverse
from django.utils.functional import cached_property
from machina.apps.forum.abstract_models import AbstractForum

Expand All @@ -28,6 +29,15 @@ class Forum(AbstractForum):

objects = ForumQuerySet().as_manager()

def get_absolute_url(self):
return reverse(
"forum_extension:forum",
kwargs={
"pk": self.pk,
"slug": self.slug,
},
)

def get_unanswered_topics(self):
return Topic.objects.unanswered().filter(forum__in=self.get_descendants(include_self=True))

Expand Down
7 changes: 7 additions & 0 deletions lacommunaute/forum/tests/tests_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ def test_kind(self):
Forum.kind.field.flatchoices,
[("PUBLIC_FORUM", "Espace public"), ("PRIVATE_FORUM", "Espace privé"), ("NEWS", "Actualités")],
)

def test_get_absolute_url(self):
forum = ForumFactory()
self.assertEqual(
forum.get_absolute_url(),
f"/forum/{forum.slug}-{forum.pk}/",
)

0 comments on commit d3ac3a0

Please sign in to comment.