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

Filter by org badge #3155

Merged
merged 19 commits into from
Nov 4, 2024
Merged

Filter by org badge #3155

merged 19 commits into from
Nov 4, 2024

Conversation

magopian
Copy link
Contributor

@magopian magopian commented Sep 25, 2024

Fixes #1431

Filter by org badge in

  • datasets api GET
  • datasets api search
  • reuses api GET
  • reuses api search
  • dataservices api GET
  • dataservices api search (no search in apiv2 for dataservices, yet?)
  • organizations api GET
  • organizations search

@maudetes
Copy link
Contributor

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.
It would probably allow for unit increments instead of maybe a big PR?

@magopian
Copy link
Contributor Author

Yes, good idea, and at the same time... I think i'd like to keep all this in the same PR.
So, the reasoning is this: we currently have objects using the old system, and some using the new system.

  • datasets: old
  • reuses: new
  • dataservices: new
  • organizations: old

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.
And then it would mean that I'd have to wait for the reuses implementation to be finalized before starting the dataservices implementation to avoid the extra work needed to maintain a PR based on another unmerged PR (eg the dataservices PR based on the reuses PR).

What do you think?

@magopian magopian marked this pull request as ready for review September 30, 2024 15:51
@magopian
Copy link
Contributor Author

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 organization_badge filter which isn't supported/implemented yet will just ignore it, or return a failure?

Copy link
Contributor

@bolinocroustibat bolinocroustibat left a 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
Copy link
Contributor

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 😆

Copy link
Contributor Author

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" 😬

Copy link
Contributor

@maudetes maudetes left a 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?

udata/core/dataset/api.py Outdated Show resolved Hide resolved
@@ -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):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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/api_fields.py Show resolved Hide resolved
udata/core/dataset/search.py Outdated Show resolved Hide resolved
udata/core/dataset/search.py Outdated Show resolved Hide resolved
{"key": "datasets", "value": "metrics.datasets"},
{"key": "followers", "value": "metrics.followers"},
{"key": "views", "value": "metrics.views"},
],
related_filters=[
Copy link
Contributor

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 :)

Copy link
Contributor

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 :-)

udata/core/reuse/api.py Outdated Show resolved Hide resolved
udata/api_fields.py Outdated Show resolved Hide resolved
@magopian
Copy link
Contributor Author

magopian commented Oct 2, 2024

The existing duplicate logic for the search makes me sad and makes your work more tedious

Agreed. Should we tackle that in a future PR?

What happened with the badge organization constants being a mix of capitalize case and kebab case?

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?

@maudetes
Copy link
Contributor

maudetes commented Oct 3, 2024

The existing duplicate logic for the search makes me sad and makes your work more tedious

Agreed. Should we tackle that in a future PR?

Yes! Ticket created : datagouv/data.gouv.fr#1514

What happened with the badge organization constants being a mix of capitalize case and kebab case?

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?

Let's do this in an upcoming PR, ticket created: datagouv/data.gouv.fr#1515
But I think we should do that next to implement the front with the correct filter wording directly.

And use inheritance instead of a `get_badge_mixin` helper in the
inheritance declaration of the model.
@magopian
Copy link
Contributor Author

@maudetes is that what you were thinking about?

Copy link
Contributor

@maudetes maudetes left a 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

udata/core/reuse/models.py Outdated Show resolved Hide resolved
Copy link
Contributor

@maudetes maudetes left a comment

Choose a reason for hiding this comment

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

👌

@magopian magopian merged commit 1f966a6 into master Nov 4, 2024
1 check passed
magopian added a commit that referenced this pull request Nov 12, 2024
This is based on PR #3155

Add docstrings, comments and tests for the "new system" from
@ThibaudDauce.

---------

Co-authored-by: Thibaud Dauce <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rajouter un filtre type d'organisation à la recherche de données
4 participants