Skip to content

Commit

Permalink
fix: cdswebsites pages objects requests params
Browse files Browse the repository at this point in the history
  • Loading branch information
revelis-vincenzo committed Sep 6, 2024
1 parent 306e728 commit f34b263
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ <h4 v-if="preview.subheading" class="pt-1 pb-4" style="font-weight: lighter">[[
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);
},
Expand Down Expand Up @@ -181,7 +181,7 @@ <h4 v-if="preview.subheading" class="pt-1 pb-4" style="font-weight: lighter">[[
},
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 => {
Expand All @@ -199,7 +199,7 @@ <h4 v-if="preview.subheading" class="pt-1 pb-4" style="font-weight: lighter">[[
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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);
})
Expand Down
5 changes: 3 additions & 2 deletions crud/cds_websites_pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f34b263

Please sign in to comment.