Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[back] feat: add the EntityContext model #1844

Merged
merged 34 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
df563e7
[back] rework: EntityContext now replaces poll.moderation
GresilleSiffle Nov 16, 2023
6eacb59
[back] fix: entity_has_unsafe_context was returning an undefined var
GresilleSiffle Nov 16, 2023
d0c1691
[back] fix: the `FAQEntryAdmin.has_answer` was always returning True
GresilleSiffle Nov 16, 2023
4e0a013
[back] chore: add the admin UI for model `EntityContext`
GresilleSiffle Nov 16, 2023
20557fd
[back][front] fix: EntityContext origin not being properly saved
GresilleSiffle Nov 16, 2023
6aa2a2a
[back] chore: display the EntityContext's origin in the admin
GresilleSiffle Nov 16, 2023
257d368
[back] refactor: remove source_url and source_label, we...
GresilleSiffle Nov 20, 2023
986d302
[back] fix: add missing migration file
GresilleSiffle Nov 20, 2023
a466afe
[back] feat: add the entity contexs to RecommendationSerializer seria…
GresilleSiffle Nov 20, 2023
c1e1168
[back][front] feat: make the FE aware of the new entity_contexts field
GresilleSiffle Nov 20, 2023
68e2b17
Merge branch 'main' into back-add_entity_context
GresilleSiffle Nov 22, 2023
6209098
[back] fix: RecommendationSerializer now properly return entity contexts
GresilleSiffle Nov 22, 2023
09f4126
[front] feat: analysis page now displays entity contexts from asso
GresilleSiffle Nov 22, 2023
22f5eb9
[front] fix: refresh the entity context when the UI lang changes
GresilleSiffle Nov 23, 2023
e58f5e7
[front] style: add a divider between contexts
GresilleSiffle Nov 23, 2023
cfed7c9
Merge branch 'main' into back-add_entity_context
GresilleSiffle Nov 23, 2023
3294722
[back] tests: add tests for EntityPollRating.unsafe_recommendation_re…
GresilleSiffle Nov 23, 2023
12795c2
[back] docs: document the EntityContext model
GresilleSiffle Nov 23, 2023
1adb380
[back] refactor: merge all mig file into one
GresilleSiffle Nov 23, 2023
af15bc2
[front] refactor: remove unused translations
GresilleSiffle Nov 23, 2023
7ec87fd
[front] style: display a border when a context is unsafe
GresilleSiffle Nov 23, 2023
7d2a27f
[back] tests: add tests for the model `Poll`
GresilleSiffle Nov 23, 2023
70a7cf8
[back] tests: use != context name in test_unsafe_recommendation_reaso…
GresilleSiffle Nov 23, 2023
651a169
[back] tests: test the method `get_entity_contexts`
GresilleSiffle Nov 27, 2023
d80602d
lint
GresilleSiffle Nov 27, 2023
9d5789c
[back] tests: add new tests for the recommendations API
GresilleSiffle Nov 27, 2023
260fc14
[back] tests: add more tests to the recommendations API
GresilleSiffle Nov 27, 2023
29dba1e
[back] refactor: re-order the fields of EntityContext in the admin form
GresilleSiffle Nov 27, 2023
6ec16ad
[back] tests: clear cache between requests
GresilleSiffle Nov 27, 2023
a51b647
[back] perf: retrieve all context texts in a single query
GresilleSiffle Nov 29, 2023
962af5b
[back] tests: also test that the context is translated
GresilleSiffle Nov 29, 2023
313c9bf
[back] refactor: create single_poll_entity_contexts property
GresilleSiffle Nov 30, 2023
b54c959
[back] refactor: make single_poll_entity_contexts raise exception in …
GresilleSiffle Nov 30, 2023
f90f02d
[back] fix: wrong attribute name in EntityContextAdmin
GresilleSiffle Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions backend/backoffice/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,9 @@ def get_queryset(self, request):

@admin.display(description="has answer?", boolean=True)
def has_answer(self, obj) -> bool:
try:
obj.answers
except FAQEntry.answers.RelatedObjectDoesNotExist: # pylint: disable=no-member
return False
else:
if obj.answers.exists():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this method was always returning True.

return True
return False
GresilleSiffle marked this conversation as resolved.
Show resolved Hide resolved

@admin.action(description=_("Enable the selected entries."))
def enable_entries(self, request, queryset):
Expand Down
28 changes: 14 additions & 14 deletions backend/core/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-10 14:05+0000\n"
"POT-Creation-Date: 2023-11-16 14:45+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -38,22 +38,22 @@ msgstr "Oui"
msgid "No"
msgstr "Non"

#: backoffice/admin.py:134
#: backoffice/admin.py:131
msgid "Enable the selected entries."
msgstr "Activer les entrées sélectionnées."

#: backoffice/admin.py:140
#: backoffice/admin.py:137
#, python-format
msgid "%d entry was successfully marked as enabled."
msgid_plural "%d entries were successfully marked as enabled."
msgstr[0] "%d entrée a été activée avec succès."
msgstr[1] "%d entrées ont été activées avec succès."

#: backoffice/admin.py:148
#: backoffice/admin.py:145
msgid "Disable the selected entries."
msgstr "Désactiver les entrées sélectionnées."

#: backoffice/admin.py:154
#: backoffice/admin.py:151
#, python-format
msgid "%d entry was successfully marked as disabled."
msgid_plural "%d entries were successfully marked as disabled."
Expand Down Expand Up @@ -84,23 +84,23 @@ msgstr "Tournesol - confiance"
msgid "Tournesol - preferences"
msgstr "Tournesol - préférences"

#: core/models/user.py:33
#: core/models/user.py:31
msgid "email address"
msgstr "adresse e-mail"

#: core/models/user.py:53
#: core/models/user.py:51
msgid "The user' preferences."
msgstr "Les préférences de l'utilisateur."

#: core/models/user.py:126
#: core/models/user.py:124
#, python-format
msgid ""
"A user with an email starting with '%(email)s' already exists in this domain."
msgstr ""
"Un utilisateur avec un e-mail commençant par '%(email)s' existe déjà dans ce "
"domaine."

#: core/models/user.py:165 core/serializers/user.py:20
#: core/models/user.py:163 core/serializers/user.py:20
msgid "A user with this email address already exists."
msgstr "Un utilisateur avec cet e-mail existe déjà."

Expand All @@ -113,24 +113,24 @@ msgstr "'%(name)s' est un nom d'utilisateur reservé"
msgid "'@' is not allowed in username"
msgstr "Un nom d'utilisateur ne peut pas contenir '@'"

#: core/serializers/user_settings.py:53
#: core/serializers/user_settings.py:55
msgid "The main criterion cannot be in the list."
msgstr "Le critère principal ne peut pas être présent."

#: core/serializers/user_settings.py:56
#: core/serializers/user_settings.py:58
msgid "The list cannot contain duplicates."
msgstr "La liste ne peut pas contenir des doublons."

#: core/serializers/user_settings.py:61
#: core/serializers/user_settings.py:63
#, python-format
msgid "Unknown criterion: %(criterion)s."
msgstr "Critère inconnu: %(criterion)s."

#: core/serializers/user_settings.py:68
#: core/serializers/user_settings.py:70
msgid "This parameter cannot be lower than 1."
msgstr "Ce paramètre ne peut pas être inférieur à 1."

#: core/serializers/user_settings.py:98
#: core/serializers/user_settings.py:108
#, python-format
msgid "Unknown language code: %(lang)s."
msgstr "Code de langue inconnu : %(lang)s."
Expand Down
49 changes: 49 additions & 0 deletions backend/tournesol/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.utils.translation import gettext_lazy as _
from sql_util.utils import SubqueryCount

from tournesol.models.entity_context import EntityContext, EntityContextLocale

from .entities.video import YOUTUBE_PUBLISHED_AT_FORMAT
from .models import (
Comparison,
Expand Down Expand Up @@ -365,3 +367,50 @@ def get_proof_of_vote_file(self, obj):
@admin.register(Criteria)
class CriteriaAdmin(admin.ModelAdmin):
inlines = (CriteriaLocalesInline,)


class HasTextListFilter(admin.SimpleListFilter):
title = _("has text?")
parameter_name = "has_text"

def lookups(self, request, model_admin):
return (
(1, _("Yes")),
(0, _("No")),
)

def queryset(self, request, queryset):
if self.value() == "1":
return queryset.filter(
texts__isnull=False,
)
if self.value() == "0":
return queryset.filter(
texts__isnull=True,
)
return queryset


class EntityContextLocaleInline(admin.StackedInline):
model = EntityContextLocale
extra = 0


@admin.register(EntityContext)
class EntityContextAdmin(admin.ModelAdmin):
search_fields = ("name",)
list_display = ("name", "poll", "origin", "created_at", "has_answer", "unsafe", "enabled")
list_filter = ("poll", "origin", HasTextListFilter, "unsafe", "enabled")
ordering = ("-created_at",)
inlines = (EntityContextLocaleInline,)

def get_queryset(self, request):
qst = super().get_queryset(request)
qst = qst.prefetch_related("texts").select_related("poll")
return qst

@admin.display(description="has text?", boolean=True)
def has_answer(self, obj) -> bool:
if obj.texts.exists():
return True
return False
GresilleSiffle marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 15 additions & 3 deletions backend/tournesol/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-03 13:07+0000\n"
"POT-Creation-Date: 2023-11-16 14:45+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -18,12 +18,24 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: tournesol/admin.py:89
#: tournesol/admin.py:91
#, python-format
msgid "Successfully refreshed the metadata of %(count)s entities."
msgstr "Les métadonnées de %(count)s entités ont été mises à jour."

#: tournesol/serializers/rate_later.py:31
#: tournesol/admin.py:373
msgid "has text?"
msgstr "contient du texte?"

#: tournesol/admin.py:378
msgid "Yes"
msgstr "Oui"

#: tournesol/admin.py:379
msgid "No"
msgstr "Non"

#: tournesol/serializers/rate_later.py:53
msgid "The entity is already in the rate-later list of this poll."
msgstr "L'entité est déjà dans la liste à comparer plus tard de ce scrutin."

Expand Down
Loading
Loading