From f34b26336eef57ecf9e99a80efbeb03f643e2581 Mon Sep 17 00:00:00 2001 From: revelis-vincenzo Date: Fri, 6 Sep 2024 13:57:37 +0200 Subject: [PATCH] fix: cdswebsites pages objects requests params --- ...ds_websites_pages_external_oggetti_portale_widget.html | 8 ++++---- .../cds_websites_pages_oggetti_portale_widget.html | 4 ++-- crud/cds_websites_pages/views.py | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crud/cds_websites_pages/templates/widgets/cds_websites_pages_external_oggetti_portale_widget.html b/crud/cds_websites_pages/templates/widgets/cds_websites_pages_external_oggetti_portale_widget.html index 1b2f45db..edd2734c 100644 --- a/crud/cds_websites_pages/templates/widgets/cds_websites_pages_external_oggetti_portale_widget.html +++ b/crud/cds_websites_pages/templates/widgets/cds_websites_pages_external_oggetti_portale_widget.html @@ -136,10 +136,10 @@

[[ const objectClass = this.objectClass; var searchUrl = ''; if(this.searchField === 'ID') { - searchUrl = `${this.url}${this.query}/?object_class=${objectClass}`; + searchUrl = `${this.url}${this.query}/?object_class=${objectClass}&format=json`; } else if(this.searchField === 'Name') { - searchUrl = `${this.url}?search=${this.query}&object_class=${objectClass}`; + searchUrl = `${this.url}?search=${this.query}&object_class=${objectClass}&format=json`; } this.fetchData(searchUrl); }, @@ -181,7 +181,7 @@

[[ }, fetchInitialData() { const objectClass = this.objectClass; - const initialUrl = `${this.url}${this.initialValue}/?object_class=${objectClass}`; + const initialUrl = `${this.url}${this.initialValue}/?object_class=${objectClass}&format=json`; this.isLoadingSearch = true; axios.get(initialUrl) .then(response => { @@ -199,7 +199,7 @@

[[ if (!this.selectedOption) return; const objectClass = this.selectedOption.object_class; if (objectClass === "Publication") { - const previewUrl = `${this.url}${this.selectedOption.id}/?object_class=${objectClass}`; + const previewUrl = `${this.url}${this.selectedOption.id}/?object_class=${objectClass}&format=json`; this.isLoadingPreview = true; $('#preview-modal').modal('show'); axios.get(previewUrl) diff --git a/crud/cds_websites_pages/templates/widgets/cds_websites_pages_oggetti_portale_widget.html b/crud/cds_websites_pages/templates/widgets/cds_websites_pages_oggetti_portale_widget.html index 8d524a17..062ec51e 100644 --- a/crud/cds_websites_pages/templates/widgets/cds_websites_pages_oggetti_portale_widget.html +++ b/crud/cds_websites_pages/templates/widgets/cds_websites_pages_oggetti_portale_widget.html @@ -59,7 +59,7 @@ clearTimeout(this.api_debounce_timeout); } this.api_debounce_timeout = setTimeout(() => { - this.search(this.url + '?search=' + newQuery); + this.search(`${this.url}?search=${newQuery}&format=json`); }, 500); // 500 milliseconds } } @@ -106,7 +106,7 @@ fetchInitialData() { this.is_loading = true axios - .get(this.url + `${this.initial_value}`) + .get(this.url + `${this.initial_value}/?format=json`) .then(response => { this.selectOption(response.data, true); }) diff --git a/crud/cds_websites_pages/views.py b/crud/cds_websites_pages/views.py index ade12605..c238ff79 100644 --- a/crud/cds_websites_pages/views.py +++ b/crud/cds_websites_pages/views.py @@ -842,7 +842,7 @@ def list(self, request): url = UNICMS_OBJECT_API[object_class] headers = { 'Authorization': f'Token {UNICMS_AUTH_TOKEN}' } - params = {'search': search} + params = { 'search': search, 'format': 'json' } try: response_obj = {} response = requests.get(url, params=params, headers=headers) @@ -885,9 +885,10 @@ def retrieve(self, request, pk=None): url = f"{UNICMS_OBJECT_API[object_class]}{pk}/" headers = { 'Authorization': f'Token {UNICMS_AUTH_TOKEN}' } + params = { 'format': 'json' } try: - response = requests.get(url, headers=headers) + response = requests.get(url, headers=headers, params=params) response.raise_for_status() response_json = response.json() response_json["object_class"] = object_class