-
-
Notifications
You must be signed in to change notification settings - Fork 48
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 entity contexts to unconnected entities API #1873
Merged
GresilleSiffle
merged 5 commits into
main
from
1852-add_ent_contexts_to_unconnected_entities
Jan 29, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8da1a2a
[back] feat: add entity contexts to unconnected entities API
GresilleSiffle 32148cd
[back] fix: add missing file
GresilleSiffle 3e00a31
[back] refactor: comparisons API now uses ent contexts from PollScope…
GresilleSiffle 591be54
Merge branch 'main' into 1852-add_ent_contexts_to_unconnected_entities
GresilleSiffle c9ccc2c
[back] tests: fix the broken tests of unconnected entities
GresilleSiffle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from rest_framework import serializers | ||
|
||
from tournesol.serializers.entity import EntityNoExtraFieldSerializer | ||
from tournesol.serializers.entity_context import EntityContextSerializer | ||
|
||
|
||
class UnconnectedEntitySerializer(serializers.Serializer): | ||
entity = EntityNoExtraFieldSerializer(source="*") | ||
entity_contexts = EntityContextSerializer(read_only=True, many=True, default=[]) | ||
|
||
def to_representation(self, instance): | ||
ret = super().to_representation(instance) | ||
|
||
poll = self.context["poll"] | ||
ent_contexts = self.context.get("entity_contexts") | ||
|
||
if ent_contexts is not None: | ||
ret["entity_contexts"] = EntityContextSerializer( | ||
poll.get_entity_contexts(ret["entity"]["metadata"], ent_contexts), many=True | ||
).data | ||
|
||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the cases where
poll
orent_contexts
would be None ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ExportComparisonsView
class uses theComparisonSerializer
to write the comparisons of the logged user in a .csv file. In this case the serializer context doesn't contain any entity context.If we consider that a comparison should not be represented without its related entity contexts, then we may want to remove this condition
and ent_contexts is not None
. In this case we should also consider adding the entity contexts in the public dataset.Because they are here to "bias" the comparisons I think it could be a good idea to include those entity contexts in the public dataset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue to address this question #1902