We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[back, front] refactor: Harmonize all API and Serializers (then:feat: Rate later list display information about the number of comparisons)
As a user I want to see how many times I have compared the videos when I look at my rate later list so that I can easily chose which videos to remove from my rate later list.

Display the information similarly as in the card used on the comparison page.

This probably will be best implemented by updating the backend endpoint to include the extra info

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `backend/tournesol/serializers/contributor_recommendations.py`
Content:
```
1 from drf_spectacular.utils import extend_schema_field, extend_schema_serializer
2 from rest_framework.serializers import SerializerMethodField
3 
4 from tournesol.models.ratings import ContributorRating
5 from tournesol.serializers.criteria_score import ContributorCriteriaScoreSerializer
6 from tournesol.serializers.poll import IndividualRatingSerializer, RecommendationSerializer
7 
8 
9 class IndividualRatingWithScoresSerializer(IndividualRatingSerializer):
10     criteria_scores = ContributorCriteriaScoreSerializer(many=True, read_only=True)
11 
12     class Meta:
13         model = ContributorRating
14         fields = IndividualRatingSerializer.Meta.fields + ["criteria_scores"]
15         read_only_fields = fields
16 
17 
18 @extend_schema_serializer(
19     exclude_fields=[
20         # legacy fields have been moved to "entity", "invidual_rating", "collective_rating", etc.
21         "uid",
22         "type",
23         "n_comparisons",
24         "n_contributors",
25         "metadata",
26         "total_score",
27         "tournesol_score",
28         "criteria_scores",
29         "unsafe",
30         "is_public",
31     ]
32 )
33 class ContributorRecommendationsSerializer(RecommendationSerializer):
34     """
35     An entity recommended by a user.
36     """
37 
38     is_public = SerializerMethodField()
39     criteria_scores = SerializerMethodField()
40     individual_rating = IndividualRatingWithScoresSerializer(
41         source="single_contributor_rating",
42         read_only=True,
43     )
44 
45     class Meta(RecommendationSerializer.Meta):
46         fields = RecommendationSerializer.Meta.fields + ["is_public", "individual_rating"]
47 
48     @extend_schema_field(ContributorCriteriaScoreSerializer(many=True))
49     def get_criteria_scores(self, obj):
50         return ContributorCriteriaScoreSerializer(
51             obj.single_contributor_rating.criteria_scores, many=True
52         ).data
53 
54     def get_is_public(self, obj) -> bool:
55         return obj.single_contributor_rating.is_public
56
```

Path: `backend/tournesol/serializers/poll.py`
Content:
```
1 from drf_spectacular.utils import extend_schema_serializer
2 from rest_framework import serializers
3 from rest_framework.serializers import IntegerField, ModelSerializer
4 
5 from tournesol.models import ContributorRating, CriteriaRank, Entity, EntityPollRating, Poll
6 from tournesol.models.entity_poll_rating import UNSAFE_REASONS
7 from tournesol.serializers.entity import EntityCriteriaScoreSerializer, RelatedEntitySerializer
8 from tournesol.serializers.entity_context import EntityContextSerializer
9 
10 
11 class PollCriteriaSerializer(ModelSerializer):
12     name = serializers.CharField(source="criteria.name")
13     label = serializers.CharField(source="criteria.get_label")
14 
15     class Meta:
16         model = CriteriaRank
17         fields = ["name", "label", "optional"]
18 
19 
20 class PollSerializer(ModelSerializer):
21     criterias = PollCriteriaSerializer(source="criteriarank_set", many=True)
22 
23     class Meta:
24         model = Poll
25         fields = ["name", "criterias", "entity_type", "active"]
26 
27 
28 class UnsafeStatusSerializer(ModelSerializer):
29     status = serializers.BooleanField(source="is_recommendation_unsafe")
30     reasons = serializers.ListField(
31         child=serializers.ChoiceField(choices=UNSAFE_REASONS),
32         source="unsafe_recommendation_reasons",
33     )
34 
35     class Meta:
36         model = EntityPollRating
37         fields = [
38             "status",
39             "reasons",
40         ]
41 
42 
43 class CollectiveRatingSerializer(ModelSerializer):
44     unsafe = UnsafeStatusSerializer(source="*", read_only=True)
45 
46     class Meta:
47         model = EntityPollRating
48         fields = [
49             "n_comparisons",
50             "n_contributors",
51             "tournesol_score",
52             "unsafe",
53         ]
54         read_only_fields = fields
55 
56 
57 class ExtendedCollectiveRatingSerializer(CollectiveRatingSerializer):
58     criteria_scores = EntityCriteriaScoreSerializer(source="entity.criteria_scores", many=True)
59 
60     class Meta:
61         model = CollectiveRatingSerializer.Meta.model
62         fields = CollectiveRatingSerializer.Meta.fields + ["criteria_scores"]
63         read_only_fields = fields
64 
65 
66 class IndividualRatingSerializer(ModelSerializer):
67     n_comparisons = IntegerField(read_only=True, default=0)
68 
69     class Meta:
70         model = ContributorRating
71         fields = [
72             "is_public",
73             "n_comparisons",
74         ]
75         read_only_fields = fields
76 
77 
78 class RecommendationMetadataSerializer(serializers.Serializer):
79     total_score = serializers.FloatField(read_only=True, allow_null=True)
80 
81 
82 @extend_schema_serializer(
83     exclude_fields=[
84         # legacy fields have been moved to "entity", "collective_rating", etc.
85         "uid",
86         "type",
87         "n_comparisons",
88         "n_contributors",
89         "metadata",
90         "total_score",
91         "tournesol_score",
92         "criteria_scores",
93         "unsafe",
94     ]
95 )
96 class RecommendationSerializer(ModelSerializer):
97     # pylint: disable=duplicate-code
98     n_comparisons = serializers.IntegerField(source="rating_n_ratings")
99     n_contributors = serializers.IntegerField(source="rating_n_contributors")
100     criteria_scores = EntityCriteriaScoreSerializer(many=True)
101     # TODO: the field total_score is the only field in this serializer that
102     # on the parameters of an api request. Should it be treated differently?
103     total_score = serializers.FloatField()
104     unsafe = UnsafeStatusSerializer(
105         source="single_poll_rating", allow_null=True, default=None, read_only=True
106     )
107 
108     entity = RelatedEntitySerializer(source="*", read_only=True)
109     collective_rating = ExtendedCollectiveRatingSerializer(
110         source="single_poll_rating",
111         read_only=True,
112         allow_null=True,
113     )
114     entity_contexts = EntityContextSerializer(
115         source="single_poll_entity_contexts",
116         read_only=True,
117         many=True
118     )
119     recommendation_metadata = RecommendationMetadataSerializer(source="*", read_only=True)
120 
121     class Meta:
122         model = Entity
123         fields = [
124             "uid",
125             "type",
126             "n_comparisons",
127             "n_contributors",
128             "metadata",
129             "total_score",
130             "tournesol_score",
131             "criteria_scores",
132             "unsafe",
133             "entity",
134             "collective_rating",
135             "entity_contexts",
136             "recommendation_metadata",
137         ]
138         read_only_fields = fields
139 
140 
141 class RecommendationsFilterSerializer(serializers.Serializer):
142     date_lte = serializers.DateTimeField(default=None)
143     date_gte = serializers.DateTimeField(default=None)
144     search = serializers.CharField(default=None, help_text="A search query to filter entities")
145     unsafe = serializers.BooleanField(
146         default=False,
147         help_text="If true, entities considered as unsafe recommendations because of a"
148         " low score or due to too few contributions will be included.",
149     )
150     exclude_compared_entities = serializers.BooleanField(
151         default=False,
152         help_text="If true and a user is authenticated, then entities compared by the"
153         " user will be removed from the response",
154     )
155
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/backend/tournesol/serializers/contributor_recommendations.py b/backend/tournesol/serializers/contributor_recommendations.py
--- a/backend/tournesol/serializers/contributor_recommendations.py
+++ b/backend/tournesol/serializers/contributor_recommendations.py
@@ -1,6 +1,3 @@
-from drf_spectacular.utils import extend_schema_field, extend_schema_serializer
-from rest_framework.serializers import SerializerMethodField
-
 from tournesol.models.ratings import ContributorRating
 from tournesol.serializers.criteria_score import ContributorCriteriaScoreSerializer
 from tournesol.serializers.poll import IndividualRatingSerializer, RecommendationSerializer
@@ -15,41 +12,14 @@
         read_only_fields = fields
 
 
-@extend_schema_serializer(
-    exclude_fields=[
-        # legacy fields have been moved to "entity", "invidual_rating", "collective_rating", etc.
-        "uid",
-        "type",
-        "n_comparisons",
-        "n_contributors",
-        "metadata",
-        "total_score",
-        "tournesol_score",
-        "criteria_scores",
-        "unsafe",
-        "is_public",
-    ]
-)
 class ContributorRecommendationsSerializer(RecommendationSerializer):
     """
     An entity recommended by a user.
     """
-
-    is_public = SerializerMethodField()
-    criteria_scores = SerializerMethodField()
     individual_rating = IndividualRatingWithScoresSerializer(
         source="single_contributor_rating",
         read_only=True,
     )
 
     class Meta(RecommendationSerializer.Meta):
-        fields = RecommendationSerializer.Meta.fields + ["is_public", "individual_rating"]
-
-    @extend_schema_field(ContributorCriteriaScoreSerializer(many=True))
-    def get_criteria_scores(self, obj):
-        return ContributorCriteriaScoreSerializer(
-            obj.single_contributor_rating.criteria_scores, many=True
-        ).data
-
-    def get_is_public(self, obj) -> bool:
-        return obj.single_contributor_rating.is_public
+        fields = RecommendationSerializer.Meta.fields + ["individual_rating"]
diff --git a/backend/tournesol/serializers/poll.py b/backend/tournesol/serializers/poll.py
--- a/backend/tournesol/serializers/poll.py
+++ b/backend/tournesol/serializers/poll.py
@@ -1,4 +1,3 @@
-from drf_spectacular.utils import extend_schema_serializer
 from rest_framework import serializers
 from rest_framework.serializers import IntegerField, ModelSerializer
 
@@ -79,32 +78,7 @@
     total_score = serializers.FloatField(read_only=True, allow_null=True)
 
 
-@extend_schema_serializer(
-    exclude_fields=[
-        # legacy fields have been moved to "entity", "collective_rating", etc.
-        "uid",
-        "type",
-        "n_comparisons",
-        "n_contributors",
-        "metadata",
-        "total_score",
-        "tournesol_score",
-        "criteria_scores",
-        "unsafe",
-    ]
-)
 class RecommendationSerializer(ModelSerializer):
-    # pylint: disable=duplicate-code
-    n_comparisons = serializers.IntegerField(source="rating_n_ratings")
-    n_contributors = serializers.IntegerField(source="rating_n_contributors")
-    criteria_scores = EntityCriteriaScoreSerializer(many=True)
-    # TODO: the field total_score is the only field in this serializer that
-    # on the parameters of an api request. Should it be treated differently?
-    total_score = serializers.FloatField()
-    unsafe = UnsafeStatusSerializer(
-        source="single_poll_rating", allow_null=True, default=None, read_only=True
-    )
-
     entity = RelatedEntitySerializer(source="*", read_only=True)
     collective_rating = ExtendedCollectiveRatingSerializer(
         source="single_poll_rating",
@@ -121,15 +95,6 @@
     class Meta:
         model = Entity
         fields = [
-            "uid",
-            "type",
-            "n_comparisons",
-            "n_contributors",
-            "metadata",
-            "total_score",
-            "tournesol_score",
-            "criteria_scores",
-            "unsafe",
             "entity",
             "collective_rating",
             "entity_contexts",

{"golden_diff": "diff --git a/backend/tournesol/serializers/contributor_recommendations.py b/backend/tournesol/serializers/contributor_recommendations.py\n--- a/backend/tournesol/serializers/contributor_recommendations.py\n+++ b/backend/tournesol/serializers/contributor_recommendations.py\n@@ -1,6 +1,3 @@\n-from drf_spectacular.utils import extend_schema_field, extend_schema_serializer\n-from rest_framework.serializers import SerializerMethodField\n-\n from tournesol.models.ratings import ContributorRating\n from tournesol.serializers.criteria_score import ContributorCriteriaScoreSerializer\n from tournesol.serializers.poll import IndividualRatingSerializer, RecommendationSerializer\n@@ -15,41 +12,14 @@\n         read_only_fields = fields\n \n \n-@extend_schema_serializer(\n-    exclude_fields=[\n-        # legacy fields have been moved to \"entity\", \"invidual_rating\", \"collective_rating\", etc.\n-        \"uid\",\n-        \"type\",\n-        \"n_comparisons\",\n-        \"n_contributors\",\n-        \"metadata\",\n-        \"total_score\",\n-        \"tournesol_score\",\n-        \"criteria_scores\",\n-        \"unsafe\",\n-        \"is_public\",\n-    ]\n-)\n class ContributorRecommendationsSerializer(RecommendationSerializer):\n     \"\"\"\n     An entity recommended by a user.\n     \"\"\"\n-\n-    is_public = SerializerMethodField()\n-    criteria_scores = SerializerMethodField()\n     individual_rating = IndividualRatingWithScoresSerializer(\n         source=\"single_contributor_rating\",\n         read_only=True,\n     )\n \n     class Meta(RecommendationSerializer.Meta):\n-        fields = RecommendationSerializer.Meta.fields + [\"is_public\", \"individual_rating\"]\n-\n-    @extend_schema_field(ContributorCriteriaScoreSerializer(many=True))\n-    def get_criteria_scores(self, obj):\n-        return ContributorCriteriaScoreSerializer(\n-            obj.single_contributor_rating.criteria_scores, many=True\n-        ).data\n-\n-    def get_is_public(self, obj) -> bool:\n-        return obj.single_contributor_rating.is_public\n+        fields = RecommendationSerializer.Meta.fields + [\"individual_rating\"]\ndiff --git a/backend/tournesol/serializers/poll.py b/backend/tournesol/serializers/poll.py\n--- a/backend/tournesol/serializers/poll.py\n+++ b/backend/tournesol/serializers/poll.py\n@@ -1,4 +1,3 @@\n-from drf_spectacular.utils import extend_schema_serializer\n from rest_framework import serializers\n from rest_framework.serializers import IntegerField, ModelSerializer\n \n@@ -79,32 +78,7 @@\n     total_score = serializers.FloatField(read_only=True, allow_null=True)\n \n \n-@extend_schema_serializer(\n-    exclude_fields=[\n-        # legacy fields have been moved to \"entity\", \"collective_rating\", etc.\n-        \"uid\",\n-        \"type\",\n-        \"n_comparisons\",\n-        \"n_contributors\",\n-        \"metadata\",\n-        \"total_score\",\n-        \"tournesol_score\",\n-        \"criteria_scores\",\n-        \"unsafe\",\n-    ]\n-)\n class RecommendationSerializer(ModelSerializer):\n-    # pylint: disable=duplicate-code\n-    n_comparisons = serializers.IntegerField(source=\"rating_n_ratings\")\n-    n_contributors = serializers.IntegerField(source=\"rating_n_contributors\")\n-    criteria_scores = EntityCriteriaScoreSerializer(many=True)\n-    # TODO: the field total_score is the only field in this serializer that\n-    # on the parameters of an api request. Should it be treated differently?\n-    total_score = serializers.FloatField()\n-    unsafe = UnsafeStatusSerializer(\n-        source=\"single_poll_rating\", allow_null=True, default=None, read_only=True\n-    )\n-\n     entity = RelatedEntitySerializer(source=\"*\", read_only=True)\n     collective_rating = ExtendedCollectiveRatingSerializer(\n         source=\"single_poll_rating\",\n@@ -121,15 +95,6 @@\n     class Meta:\n         model = Entity\n         fields = [\n-            \"uid\",\n-            \"type\",\n-            \"n_comparisons\",\n-            \"n_contributors\",\n-            \"metadata\",\n-            \"total_score\",\n-            \"tournesol_score\",\n-            \"criteria_scores\",\n-            \"unsafe\",\n             \"entity\",\n             \"collective_rating\",\n             \"entity_contexts\",\n", "issue": "[back, front] refactor: Harmonize all API and Serializers (then:feat: Rate later list display information about the number of comparisons)\nAs a user I want to see how many times I have compared the videos when I look at my rate later list so that I can easily chose which videos to remove from my rate later list.\r\n\r\nDisplay the information similarly as in the card used on the comparison page.\r\n\r\nThis probably will be best implemented by updating the backend endpoint to include the extra info\n", "before_files": [{"content": "from drf_spectacular.utils import extend_schema_field, extend_schema_serializer\nfrom rest_framework.serializers import SerializerMethodField\n\nfrom tournesol.models.ratings import ContributorRating\nfrom tournesol.serializers.criteria_score import ContributorCriteriaScoreSerializer\nfrom tournesol.serializers.poll import IndividualRatingSerializer, RecommendationSerializer\n\n\nclass IndividualRatingWithScoresSerializer(IndividualRatingSerializer):\n    criteria_scores = ContributorCriteriaScoreSerializer(many=True, read_only=True)\n\n    class Meta:\n        model = ContributorRating\n        fields = IndividualRatingSerializer.Meta.fields + [\"criteria_scores\"]\n        read_only_fields = fields\n\n\n@extend_schema_serializer(\n    exclude_fields=[\n        # legacy fields have been moved to \"entity\", \"invidual_rating\", \"collective_rating\", etc.\n        \"uid\",\n        \"type\",\n        \"n_comparisons\",\n        \"n_contributors\",\n        \"metadata\",\n        \"total_score\",\n        \"tournesol_score\",\n        \"criteria_scores\",\n        \"unsafe\",\n        \"is_public\",\n    ]\n)\nclass ContributorRecommendationsSerializer(RecommendationSerializer):\n    \"\"\"\n    An entity recommended by a user.\n    \"\"\"\n\n    is_public = SerializerMethodField()\n    criteria_scores = SerializerMethodField()\n    individual_rating = IndividualRatingWithScoresSerializer(\n        source=\"single_contributor_rating\",\n        read_only=True,\n    )\n\n    class Meta(RecommendationSerializer.Meta):\n        fields = RecommendationSerializer.Meta.fields + [\"is_public\", \"individual_rating\"]\n\n    @extend_schema_field(ContributorCriteriaScoreSerializer(many=True))\n    def get_criteria_scores(self, obj):\n        return ContributorCriteriaScoreSerializer(\n            obj.single_contributor_rating.criteria_scores, many=True\n        ).data\n\n    def get_is_public(self, obj) -> bool:\n        return obj.single_contributor_rating.is_public\n", "path": "backend/tournesol/serializers/contributor_recommendations.py"}, {"content": "from drf_spectacular.utils import extend_schema_serializer\nfrom rest_framework import serializers\nfrom rest_framework.serializers import IntegerField, ModelSerializer\n\nfrom tournesol.models import ContributorRating, CriteriaRank, Entity, EntityPollRating, Poll\nfrom tournesol.models.entity_poll_rating import UNSAFE_REASONS\nfrom tournesol.serializers.entity import EntityCriteriaScoreSerializer, RelatedEntitySerializer\nfrom tournesol.serializers.entity_context import EntityContextSerializer\n\n\nclass PollCriteriaSerializer(ModelSerializer):\n    name = serializers.CharField(source=\"criteria.name\")\n    label = serializers.CharField(source=\"criteria.get_label\")\n\n    class Meta:\n        model = CriteriaRank\n        fields = [\"name\", \"label\", \"optional\"]\n\n\nclass PollSerializer(ModelSerializer):\n    criterias = PollCriteriaSerializer(source=\"criteriarank_set\", many=True)\n\n    class Meta:\n        model = Poll\n        fields = [\"name\", \"criterias\", \"entity_type\", \"active\"]\n\n\nclass UnsafeStatusSerializer(ModelSerializer):\n    status = serializers.BooleanField(source=\"is_recommendation_unsafe\")\n    reasons = serializers.ListField(\n        child=serializers.ChoiceField(choices=UNSAFE_REASONS),\n        source=\"unsafe_recommendation_reasons\",\n    )\n\n    class Meta:\n        model = EntityPollRating\n        fields = [\n            \"status\",\n            \"reasons\",\n        ]\n\n\nclass CollectiveRatingSerializer(ModelSerializer):\n    unsafe = UnsafeStatusSerializer(source=\"*\", read_only=True)\n\n    class Meta:\n        model = EntityPollRating\n        fields = [\n            \"n_comparisons\",\n            \"n_contributors\",\n            \"tournesol_score\",\n            \"unsafe\",\n        ]\n        read_only_fields = fields\n\n\nclass ExtendedCollectiveRatingSerializer(CollectiveRatingSerializer):\n    criteria_scores = EntityCriteriaScoreSerializer(source=\"entity.criteria_scores\", many=True)\n\n    class Meta:\n        model = CollectiveRatingSerializer.Meta.model\n        fields = CollectiveRatingSerializer.Meta.fields + [\"criteria_scores\"]\n        read_only_fields = fields\n\n\nclass IndividualRatingSerializer(ModelSerializer):\n    n_comparisons = IntegerField(read_only=True, default=0)\n\n    class Meta:\n        model = ContributorRating\n        fields = [\n            \"is_public\",\n            \"n_comparisons\",\n        ]\n        read_only_fields = fields\n\n\nclass RecommendationMetadataSerializer(serializers.Serializer):\n    total_score = serializers.FloatField(read_only=True, allow_null=True)\n\n\n@extend_schema_serializer(\n    exclude_fields=[\n        # legacy fields have been moved to \"entity\", \"collective_rating\", etc.\n        \"uid\",\n        \"type\",\n        \"n_comparisons\",\n        \"n_contributors\",\n        \"metadata\",\n        \"total_score\",\n        \"tournesol_score\",\n        \"criteria_scores\",\n        \"unsafe\",\n    ]\n)\nclass RecommendationSerializer(ModelSerializer):\n    # pylint: disable=duplicate-code\n    n_comparisons = serializers.IntegerField(source=\"rating_n_ratings\")\n    n_contributors = serializers.IntegerField(source=\"rating_n_contributors\")\n    criteria_scores = EntityCriteriaScoreSerializer(many=True)\n    # TODO: the field total_score is the only field in this serializer that\n    # on the parameters of an api request. Should it be treated differently?\n    total_score = serializers.FloatField()\n    unsafe = UnsafeStatusSerializer(\n        source=\"single_poll_rating\", allow_null=True, default=None, read_only=True\n    )\n\n    entity = RelatedEntitySerializer(source=\"*\", read_only=True)\n    collective_rating = ExtendedCollectiveRatingSerializer(\n        source=\"single_poll_rating\",\n        read_only=True,\n        allow_null=True,\n    )\n    entity_contexts = EntityContextSerializer(\n        source=\"single_poll_entity_contexts\",\n        read_only=True,\n        many=True\n    )\n    recommendation_metadata = RecommendationMetadataSerializer(source=\"*\", read_only=True)\n\n    class Meta:\n        model = Entity\n        fields = [\n            \"uid\",\n            \"type\",\n            \"n_comparisons\",\n            \"n_contributors\",\n            \"metadata\",\n            \"total_score\",\n            \"tournesol_score\",\n            \"criteria_scores\",\n            \"unsafe\",\n            \"entity\",\n            \"collective_rating\",\n            \"entity_contexts\",\n            \"recommendation_metadata\",\n        ]\n        read_only_fields = fields\n\n\nclass RecommendationsFilterSerializer(serializers.Serializer):\n    date_lte = serializers.DateTimeField(default=None)\n    date_gte = serializers.DateTimeField(default=None)\n    search = serializers.CharField(default=None, help_text=\"A search query to filter entities\")\n    unsafe = serializers.BooleanField(\n        default=False,\n        help_text=\"If true, entities considered as unsafe recommendations because of a\"\n        \" low score or due to too few contributions will be included.\",\n    )\n    exclude_compared_entities = serializers.BooleanField(\n        default=False,\n        help_text=\"If true and a user is authenticated, then entities compared by the\"\n        \" user will be removed from the response\",\n    )\n", "path": "backend/tournesol/serializers/poll.py"}], "after_files": [{"content": "from tournesol.models.ratings import ContributorRating\nfrom tournesol.serializers.criteria_score import ContributorCriteriaScoreSerializer\nfrom tournesol.serializers.poll import IndividualRatingSerializer, RecommendationSerializer\n\n\nclass IndividualRatingWithScoresSerializer(IndividualRatingSerializer):\n    criteria_scores = ContributorCriteriaScoreSerializer(many=True, read_only=True)\n\n    class Meta:\n        model = ContributorRating\n        fields = IndividualRatingSerializer.Meta.fields + [\"criteria_scores\"]\n        read_only_fields = fields\n\n\nclass ContributorRecommendationsSerializer(RecommendationSerializer):\n    \"\"\"\n    An entity recommended by a user.\n    \"\"\"\n    individual_rating = IndividualRatingWithScoresSerializer(\n        source=\"single_contributor_rating\",\n        read_only=True,\n    )\n\n    class Meta(RecommendationSerializer.Meta):\n        fields = RecommendationSerializer.Meta.fields + [\"individual_rating\"]\n", "path": "backend/tournesol/serializers/contributor_recommendations.py"}, {"content": "from rest_framework import serializers\nfrom rest_framework.serializers import IntegerField, ModelSerializer\n\nfrom tournesol.models import ContributorRating, CriteriaRank, Entity, EntityPollRating, Poll\nfrom tournesol.models.entity_poll_rating import UNSAFE_REASONS\nfrom tournesol.serializers.entity import EntityCriteriaScoreSerializer, RelatedEntitySerializer\nfrom tournesol.serializers.entity_context import EntityContextSerializer\n\n\nclass PollCriteriaSerializer(ModelSerializer):\n    name = serializers.CharField(source=\"criteria.name\")\n    label = serializers.CharField(source=\"criteria.get_label\")\n\n    class Meta:\n        model = CriteriaRank\n        fields = [\"name\", \"label\", \"optional\"]\n\n\nclass PollSerializer(ModelSerializer):\n    criterias = PollCriteriaSerializer(source=\"criteriarank_set\", many=True)\n\n    class Meta:\n        model = Poll\n        fields = [\"name\", \"criterias\", \"entity_type\", \"active\"]\n\n\nclass UnsafeStatusSerializer(ModelSerializer):\n    status = serializers.BooleanField(source=\"is_recommendation_unsafe\")\n    reasons = serializers.ListField(\n        child=serializers.ChoiceField(choices=UNSAFE_REASONS),\n        source=\"unsafe_recommendation_reasons\",\n    )\n\n    class Meta:\n        model = EntityPollRating\n        fields = [\n            \"status\",\n            \"reasons\",\n        ]\n\n\nclass CollectiveRatingSerializer(ModelSerializer):\n    unsafe = UnsafeStatusSerializer(source=\"*\", read_only=True)\n\n    class Meta:\n        model = EntityPollRating\n        fields = [\n            \"n_comparisons\",\n            \"n_contributors\",\n            \"tournesol_score\",\n            \"unsafe\",\n        ]\n        read_only_fields = fields\n\n\nclass ExtendedCollectiveRatingSerializer(CollectiveRatingSerializer):\n    criteria_scores = EntityCriteriaScoreSerializer(source=\"entity.criteria_scores\", many=True)\n\n    class Meta:\n        model = CollectiveRatingSerializer.Meta.model\n        fields = CollectiveRatingSerializer.Meta.fields + [\"criteria_scores\"]\n        read_only_fields = fields\n\n\nclass IndividualRatingSerializer(ModelSerializer):\n    n_comparisons = IntegerField(read_only=True, default=0)\n\n    class Meta:\n        model = ContributorRating\n        fields = [\n            \"is_public\",\n            \"n_comparisons\",\n        ]\n        read_only_fields = fields\n\n\nclass RecommendationMetadataSerializer(serializers.Serializer):\n    total_score = serializers.FloatField(read_only=True, allow_null=True)\n\n\nclass RecommendationSerializer(ModelSerializer):\n    entity = RelatedEntitySerializer(source=\"*\", read_only=True)\n    collective_rating = ExtendedCollectiveRatingSerializer(\n        source=\"single_poll_rating\",\n        read_only=True,\n        allow_null=True,\n    )\n    entity_contexts = EntityContextSerializer(\n        source=\"single_poll_entity_contexts\",\n        read_only=True,\n        many=True\n    )\n    recommendation_metadata = RecommendationMetadataSerializer(source=\"*\", read_only=True)\n\n    class Meta:\n        model = Entity\n        fields = [\n            \"entity\",\n            \"collective_rating\",\n            \"entity_contexts\",\n            \"recommendation_metadata\",\n        ]\n        read_only_fields = fields\n\n\nclass RecommendationsFilterSerializer(serializers.Serializer):\n    date_lte = serializers.DateTimeField(default=None)\n    date_gte = serializers.DateTimeField(default=None)\n    search = serializers.CharField(default=None, help_text=\"A search query to filter entities\")\n    unsafe = serializers.BooleanField(\n        default=False,\n        help_text=\"If true, entities considered as unsafe recommendations because of a\"\n        \" low score or due to too few contributions will be included.\",\n    )\n    exclude_compared_entities = serializers.BooleanField(\n        default=False,\n        help_text=\"If true and a user is authenticated, then entities compared by the\"\n        \" user will be removed from the response\",\n    )\n", "path": "backend/tournesol/serializers/poll.py"}]}