-
Notifications
You must be signed in to change notification settings - Fork 6
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
project-search: add identifer to search field #6247
Open
vellip
wants to merge
1
commit into
dev
Choose a base branch
from
pv-2025-03-add-identifier-to-search
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -65,6 +65,7 @@ class ProjectSerializer( | |
type = serializers.SerializerMethodField() | ||
url = serializers.SerializerMethodField() | ||
topics = serializers.SerializerMethodField() | ||
identifier = serializers.SerializerMethodField() | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.now = kwargs.pop("now") | ||
|
@@ -84,6 +85,7 @@ class Meta: | |
"description", | ||
"district", | ||
"future_phase", | ||
"identifier", | ||
"organisation", | ||
"participation", | ||
"participation_active", | ||
|
@@ -248,6 +250,11 @@ def get_point_label(self, instance): | |
def get_cost(self, instance): | ||
return "" | ||
|
||
def get_identifier(self, instance): | ||
if hasattr(instance, "externalproject"): | ||
if hasattr(instance.externalproject, "bplan"): | ||
return instance.externalproject.bplan.identifier | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, just check for can you add the field in the bplan tests as well? |
||
|
||
class ActiveProjectSerializer(ProjectSerializer): | ||
def seconds_in_units(self, seconds): | ||
|
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.
this should be
project.indentifier
, since bplan is externalproject and externaprojects are projects. And I see you pass bplans directly in your tests, which makes sense.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.
@m4ra I tried this before and again today but it didn't work. Since
ExternalProject
andProjects
are not abstract models but just further inherited, they don't have thatidentifier
field on themselves, I can only access that through theBplan
model. And to get that I have to follow the OneToOne relation that is being created when a model inherits another model, which I do in the code here and inserializers.py
.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.
If I try to just return
project.identifier
I get nothing back. And doingtype(instance)
also shows that it's aProject
not aBplan
, doingvars(instance)
also shows noidentifier
.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.
Indeed, for this to work we need to query
projects = Project.objects.select_related("externalproject__bplan").all()
. This would decrease the amount of queries. And then we can squash the three checks into one withif hasattr(p, 'externalproject') and hasattr(p.externalproject, 'bplan'):
Need to find where we query the projects.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.
Maybe I am missing something, but since
get_search_profiles_for_project
does not query the project, it would mean whoever is usingget_search_profiles_for_project
would have to always query with theselect_related
, otherwise it would lead to bugs. I imagine it's any easy thing to oversee and don't know if we should change that.I could query the project again, something like
but I suppose that feels weird as well. In the serializer it might be easier because we can just override
get_queryset
in all the views where it's used, but still I am not sure if this works that well? What do you think?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 new field method
identifier
in the project serializers, it is introducing more lookups when we call it from other views, e.g the list of projects. That's why we are getting a test failure related to caching. So yes It is not related to theget_serch_profiles_for_project
. Can you add theexternalproject__bplan
here? I just tested it locally and the caching test is passing.ps. I realized am commenting on the wrong place, it should be in the serializers o_O