Skip to content

Commit

Permalink
remove unusefull property on Forum model, related to ForumRating
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Oct 1, 2024
1 parent 5e1fdbd commit d2aa52d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 30 deletions.
6 changes: 0 additions & 6 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ def is_in_documentation_area(self):
def is_toplevel_discussion_area(self):
return self == Forum.objects.get_main_forum()

def get_session_rating(self, session_key):
return getattr(ForumRating.objects.filter(forum=self, session_id=session_key).first(), "rating", None)

def get_average_rating(self):
return ForumRating.objects.filter(forum=self).aggregate(models.Avg("rating"))["rating__avg"]


# TODO : to be removed after migration
class ForumRating(DatedModel):
Expand Down
19 changes: 1 addition & 18 deletions lacommunaute/forum/tests/tests_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.test import TestCase

from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory, ForumRatingFactory
from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory
from lacommunaute.forum.models import Forum
from lacommunaute.forum_conversation.factories import TopicFactory
from lacommunaute.users.factories import UserFactory
Expand Down Expand Up @@ -72,23 +72,6 @@ def test_is_toplevel_discussion_area(self):
self.assertFalse(forum.is_toplevel_discussion_area)
self.assertFalse(sub_forum.is_toplevel_discussion_area)

def test_get_session_rating(self):
forum = ForumFactory()
forum_rating = ForumRatingFactory(forum=forum)

self.assertIsNone(forum.get_session_rating("test"))
self.assertEqual(forum.get_session_rating(forum_rating.session_id), forum_rating.rating)

ForumRatingFactory(forum=forum, session_id=forum_rating.session_id, rating=forum_rating.rating + 1)
self.assertEqual(forum.get_session_rating(forum_rating.session_id), forum_rating.rating + 1)

def test_get_average_rating(self):
forum = ForumFactory()
ForumRatingFactory(forum=forum, rating=1)
ForumRatingFactory(forum=forum, rating=5)

self.assertEqual(forum.get_average_rating(), 3)


class TestForumQueryset:
def test_get_main_forum_wo_forum(self, db):
Expand Down
7 changes: 3 additions & 4 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def test_context(self):
self.assertEqual(response.context_data["filters"], Filters.choices)
self.assertEqual(response.context_data["loadmoretopic_url"], loadmoretopic_url)
self.assertEqual(response.context_data["forum"], self.forum)
self.assertIsNone(response.context_data["rating"])
self.assertEqual(response.context_data["active_filter_name"], Filters.ALL.label)
self.assertEqual(response.context_data["active_tags"], "")

Expand Down Expand Up @@ -196,7 +195,7 @@ def test_queries(self):

TopicFactory.create_batch(20, with_post=True)
self.client.force_login(self.user)
with self.assertNumQueries(23):
with self.assertNumQueries(22):
self.client.get(self.url)

def test_certified_post_display(self):
Expand Down Expand Up @@ -338,7 +337,7 @@ def test_filtered_queryset_on_tag(self):
tag = faker.word()
topic = TopicFactory(forum=self.forum, with_tags=[tag], with_post=True)

with self.assertNumQueries(20):
with self.assertNumQueries(19):
response = self.client.get(
reverse("forum_extension:forum", kwargs={"pk": self.forum.pk, "slug": self.forum.slug}), {"tags": tag}
)
Expand Down Expand Up @@ -652,7 +651,7 @@ def test_numqueries_on_tags(self, client, db, django_assert_num_queries):
20, parent=category_forum, with_public_perms=True, with_tags=[f"tag{i}" for i in range(3)]
)
# vincentporte TOBEFIXED : DUPLICATED QUERIES
with django_assert_num_queries(19):
with django_assert_num_queries(18):
client.get(category_forum.get_absolute_url())


Expand Down
2 changes: 0 additions & 2 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def get_context_data(self, **kwargs):
context["loadmoretopic_suffix"] = "topicsinforum"
context["form"] = PostForm(forum=forum, user=self.request.user)

context["rating"] = forum.get_session_rating(self.request.session.session_key)

context["filter_dropdown_endpoint"] = (
None
if self.request.GET.get("page")
Expand Down

0 comments on commit d2aa52d

Please sign in to comment.