From c9a70ca02757e4585ab2dc4200db5382e20fae95 Mon Sep 17 00:00:00 2001 From: Thibaud Dauce Date: Tue, 20 Aug 2024 13:49:03 +0200 Subject: [PATCH] Fix wrong name for objects in pager --- udata/api_fields.py | 17 +++++++++-------- udata/core/dataservices/api.py | 6 +----- udata/tests/api/test_dataservices_api.py | 5 +---- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/udata/api_fields.py b/udata/api_fields.py index 18e269f3d..92eebc8f9 100644 --- a/udata/api_fields.py +++ b/udata/api_fields.py @@ -318,15 +318,16 @@ def apply_sort_filters_and_pagination(base_query): and getattr(cls, "__elasticsearch_search__", None) is not None ): # Do an Elasticsearch query - print(cls.__elasticsearch_search__(args.get("q"))) - print( - { - "data": cls.__elasticsearch_search__(args.get("q")), + results = cls.__elasticsearch_search__(args.get("q")) + if paginable: + return { + "objects": results, # restx pager rename `objects` into `data` + "total": len(results), + "page": 1, + "page_size": len(results), } - ) - return { - "data": cls.__elasticsearch_search__(args.get("q")), - } + else: + return results else: # Do a regular MongoDB query if sortables and args["sort"]: diff --git a/udata/core/dataservices/api.py b/udata/core/dataservices/api.py index 1c8d355eb..49a44b52b 100644 --- a/udata/core/dataservices/api.py +++ b/udata/core/dataservices/api.py @@ -25,11 +25,7 @@ def get(self): """List or search all dataservices""" query = Dataservice.objects.visible() - results = Dataservice.apply_sort_filters_and_pagination(query) - print(results) - - print("here") - return results + return Dataservice.apply_sort_filters_and_pagination(query) @api.secure @api.doc("create_dataservice", responses={400: "Validation error"}) diff --git a/udata/tests/api/test_dataservices_api.py b/udata/tests/api/test_dataservices_api.py index 89cded2f1..3be3e3cc1 100644 --- a/udata/tests/api/test_dataservices_api.py +++ b/udata/tests/api/test_dataservices_api.py @@ -1,9 +1,6 @@ -import random -import string import time from datetime import datetime -from elasticsearch_dsl import analyzer, token_filter, tokenizer from flask import url_for from udata.core.badges.models import Badge @@ -12,7 +9,7 @@ from udata.core.dataset.factories import DatasetFactory, LicenseFactory from udata.core.organization.constants import CERTIFIED, PUBLIC_SERVICE from udata.core.organization.factories import OrganizationFactory -from udata.core.organization.models import Member, Organization +from udata.core.organization.models import Member from udata.core.user.factories import UserFactory from udata.i18n import gettext as _