diff --git a/lacommunaute/forum/factories.py b/lacommunaute/forum/factories.py
index 72acfc3bc..a0705584d 100644
--- a/lacommunaute/forum/factories.py
+++ b/lacommunaute/forum/factories.py
@@ -54,3 +54,9 @@ class ForumRatingFactory(factory.django.DjangoModelFactory):
class Meta:
model = ForumRating
+
+ @factory.post_generation
+ def set_created(self, create, extracted, **kwargs):
+ if extracted:
+ self.created = extracted
+ self.save()
diff --git a/lacommunaute/forum/models.py b/lacommunaute/forum/models.py
index 518302313..d13c21f5c 100644
--- a/lacommunaute/forum/models.py
+++ b/lacommunaute/forum/models.py
@@ -77,6 +77,9 @@ def is_newsfeed(self):
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"]
+
class ForumRating(DatedModel):
session_id = models.CharField(max_length=40)
diff --git a/lacommunaute/forum/tests/tests_model.py b/lacommunaute/forum/tests/tests_model.py
index 8e6d8a8a0..fe0fb7f4e 100644
--- a/lacommunaute/forum/tests/tests_model.py
+++ b/lacommunaute/forum/tests/tests_model.py
@@ -117,3 +117,10 @@ def test_get_session_rating(self):
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)
diff --git a/lacommunaute/stats/factories.py b/lacommunaute/stats/factories.py
index b4221b5c1..2beb7fed7 100644
--- a/lacommunaute/stats/factories.py
+++ b/lacommunaute/stats/factories.py
@@ -36,3 +36,6 @@ class ForumStatFactory(factory.django.DjangoModelFactory):
class Meta:
model = ForumStat
+
+ class Params:
+ for_snapshot = factory.Trait(period="week", date=datetime.date(2024, 5, 20))
diff --git a/lacommunaute/stats/tests/__snapshots__/tests_views.ambr b/lacommunaute/stats/tests/__snapshots__/tests_views.ambr
index 21d0150f3..81384b099 100644
--- a/lacommunaute/stats/tests/__snapshots__/tests_views.ambr
+++ b/lacommunaute/stats/tests/__snapshots__/tests_views.ambr
@@ -11,6 +11,102 @@
'''
# ---
+# name: TestForumStatWeekArchiveView.test_header_and_breadcrumb[breadcrumb]
+ '''
+
+ '''
+# ---
+# name: TestForumStatWeekArchiveView.test_header_and_breadcrumb[title-01]
+ '''
+
+
+
+
+
+ Partenariat Academie France Travail x La communauté de l'inclusion
+
+ Statistiques de la semaine du 20 mai 2024 au 26 mai 2024
+
+
+
+
+
+ '''
+# ---
+# name: TestForumStatWeekArchiveView.test_most_rated_forums[most_rated_forums]
+ '''
+
+
+
+
Les 1 fiches pratiques les plus notées sur la période
+
+
+
+ Fiche Pratique |
+ Nombres de notations de la semaine |
+ Notation moyenne totale |
+
+
+
+
+
+ Forum A |
+ 2 |
+ 3,00 |
+
+
+
+
+
+
+
+ '''
+# ---
+# name: TestForumStatWeekArchiveView.test_most_viewed_forums[most_viewed_forums]
+ '''
+
+
+
+
Les 2 fiches pratiques les plus lues sur la période
+
+
+
+ Fiche Pratique |
+ Visiteurs uniques |
+ Visiteurs uniques entrants |
+ Temps de lecture total |
+
+
+
+
+
+ Forum B |
+ 17 |
+ 5 |
+ 1978 secondes |
+
+
+
+ Forum A |
+ 10 |
+ 8 |
+ 1000 secondes |
+
+
+
+
+
+
+
+ '''
+# ---
# name: TestMonthlyVisitorsView.test_navigation[breadcrumb]
'''