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

Add default class sort on reuses and dataservices #3170

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Add default class sort on reuses and dataservices [#3170](https://github.com/opendatateam/udata/pull/3170)

## 9.2.3 (2024-10-14)

Expand Down
1 change: 1 addition & 0 deletions udata/api_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def make_lambda(method):
location="args",
choices=choices,
help="The field (and direction) on which sorting apply",
default=kwargs.get("default_sort"),
)

searchable = kwargs.pop("searchable", False)
Expand Down
2 changes: 1 addition & 1 deletion udata/core/dataservices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class HarvestMetadata(db.EmbeddedDocument):
archived_at = field(db.DateTimeField())


@generate_fields(searchable=True)
@generate_fields(searchable=True, default_sort="-created_at")
class Dataservice(WithMetrics, Owned, db.Document):
meta = {
"indexes": [
Expand Down
5 changes: 1 addition & 4 deletions udata/core/reuse/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from udata.core.badges.fields import badge_fields
from udata.core.dataset.api_fields import dataset_ref_fields
from udata.core.followers.api import FollowAPI
from udata.core.reuse.constants import REUSE_TOPICS, REUSE_TYPES
from udata.core.reuse.constants import REUSE_TOPICS, REUSE_TYPES, SUGGEST_SORTING
from udata.core.storages.api import (
image_parser,
parse_uploaded_image,
Expand All @@ -30,9 +30,6 @@
from .models import Reuse
from .permissions import ReuseEditPermission

DEFAULT_SORTING = "-created_at"
SUGGEST_SORTING = "-metrics.followers"


class ReuseApiParser(ModelApiParser):
sorts = {
Expand Down
3 changes: 3 additions & 0 deletions udata/core/reuse/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@

TITLE_SIZE_LIMIT = 350
DESCRIPTION_SIZE_LIMIT = 100000

DEFAULT_SORTING = "-created_at"
SUGGEST_SORTING = "-metrics.followers"
3 changes: 2 additions & 1 deletion udata/core/reuse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from udata.uris import endpoint_for
from udata.utils import hash_url

from .constants import IMAGE_MAX_SIZE, IMAGE_SIZES, REUSE_TOPICS, REUSE_TYPES
from .constants import DEFAULT_SORTING, IMAGE_MAX_SIZE, IMAGE_SIZES, REUSE_TOPICS, REUSE_TYPES

__all__ = ("Reuse",)

Expand All @@ -35,6 +35,7 @@ def check_url_does_not_exists(url):

@generate_fields(
searchable=True,
default_sort=DEFAULT_SORTING,
additionalSorts=[
{"key": "datasets", "value": "metrics.datasets"},
{"key": "followers", "value": "metrics.followers"},
Expand Down
3 changes: 2 additions & 1 deletion udata/core/reuse/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime

from udata.core.reuse.api import DEFAULT_SORTING, ReuseApiParser
from udata.core.reuse.api import ReuseApiParser
from udata.core.reuse.constants import DEFAULT_SORTING
from udata.models import Organization, Reuse, User
from udata.search import (
BoolFilter,
Expand Down