-
Notifications
You must be signed in to change notification settings - Fork 87
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
Filter by org badge #3155
Filter by org badge #3155
Conversation
As a suggestion, I would recommend to add it on datasets first in this PR as a first iteration and the others in another go. |
Yes, good idea, and at the same time... I think i'd like to keep all this in the same PR.
And those won't use exactly the same code, as their API, and more specifically, their parser aren't the same between the old and the new system. Implementing at least one for each (dataset is already done in this PR, and reuse is nearly done), allows us to see what can be common between the two (maybe nothing). And once we have one for each, implementing for the other two (organization and dataservice) should be very straightforward. The other option would be to implement for the old system (eg datasets) in a different PR than for the new system (eg reuses), but modifications (following a review) might have implications in the other. What do you think? |
I believe this is now ready for review, with the one (big) caveat that this doesn't implement anything for the udata search service side of the feature, which will be done in a separate PR. I'm not sure if this PR can be landed (after review and fixes obviously) before the change are done in udata-search-service? Haven't checked yet if passing an |
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'm not sure I can grasp the full features of the PR, but LGTM! Great job!
from udata.core.dataservices.factories import DataserviceFactory | ||
from udata.core.dataservices.models import Dataservice | ||
from udata.core.dataset.factories import DatasetFactory, LicenseFactory | ||
from udata.core.organization.factories import OrganizationFactory | ||
from udata.core.organization.models import Member | ||
from udata.core.user.factories import UserFactory | ||
from udata.i18n import gettext as _ | ||
from udata.tests.helpers import assert200, assert_redirects | ||
from udata.tests.helpers import assert200, assert400, assert_redirects |
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.
Very slightly bothered by the non-pythonic naming of those functions with no underscore, but that's just me 😆
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.
yeah, it's a mix between pythonic and "unittest-ic" 😬
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 think it works smoothly, well done! 👏
I have only minor questions/remarks!
Notes:
- The existing duplicate logic for the search makes me sad and makes your work more tedious
- What happened with the badge organization constants being a mix of capitalize case and kebab case?
@@ -82,6 +82,9 @@ def hidden(self): | |||
def get_by_id_or_slug(self, id_or_slug): | |||
return self(slug=id_or_slug).first() or self(id=id_or_slug).first() | |||
|
|||
def with_badge(self, kind): |
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.
Since the QuerySet is quite straightforward, do we need to create this helper?
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.
sooooo we don't really need it, but it's very convenient for the generate_fields.related_fields
declaration here.
I can find a way around it if you feel we should, let me know.
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.
Yes, I think I then saw the usage is related_fields
and thought "yes ok, seems fair"! Let's keep it!
udata/core/reuse/models.py
Outdated
{"key": "datasets", "value": "metrics.datasets"}, | ||
{"key": "followers", "value": "metrics.followers"}, | ||
{"key": "views", "value": "metrics.views"}, | ||
], | ||
related_filters=[ |
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 would be curious about @ThibaudDauce opinion on this part :)
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.
Hum, I would try to make it work with only:
additional_filters=[
'organization.badge',
]
but not sure it's possible :-) If you want to pair program on this @magopian we could look into it :-)
Agreed. Should we tackle that in a future PR?
ah, I'm REALLY curious about that too, was pondering if it made sense to change it to something coherent. Should I give it a go in this PR? Or maybe in a future refactor/cleanup? |
Yes! Ticket created : datagouv/data.gouv.fr#1514
Let's do this in an upcoming PR, ticket created: datagouv/data.gouv.fr#1515 |
1ebc4eb
to
c87b5e2
Compare
c87b5e2
to
4cef617
Compare
And use inheritance instead of a `get_badge_mixin` helper in the inheritance declaration of the model.
c2f0d58
to
362acf2
Compare
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.
Thank you for all the work on this org badge! 💪
I find the result quite clean, well done!
I've created a PR on the search-service side: opendatateam/udata-search-service#49
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 is based on PR #3155 Add docstrings, comments and tests for the "new system" from @ThibaudDauce. --------- Co-authored-by: Thibaud Dauce <[email protected]>
Fixes #1431
Filter by org badge in
dataservices api search(no search in apiv2 for dataservices, yet?)