Skip to content

Commit

Permalink
Merge pull request #6110 from OCHA-DAP/dev-hdx-9232
Browse files Browse the repository at this point in the history
HDX-9232 wrong resource to be previewed on dataset page and on contri…
  • Loading branch information
danmihaila authored Oct 10, 2023
2 parents 4b552d8 + 4d2c756 commit 2eecb65
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,24 @@ def hdx_convert_values_to_boolean_for_dataset_preview(key, data, errors, context
convert values to boolean and also sets the dataset_preview to false for the other resources
'''

value = data.get(key)
if value in (True, False, 'True', 'False'):
new_value = value = data.get(key)

if value in (True, False):
pass
elif value in ('True','true'):
new_value = True
elif value in ('False', 'false'):
new_value = False
elif value in ('1', 1):
# set others on False
new_value = True
elif value in ('0', 0):
new_value = False
else:
# value not in ('1',1,'0',0, True, False, 'True', 'False'):
new_value = None

if new_value:
i = 0
while True:
temp_key_name = ('resources', i, 'name')
Expand All @@ -257,13 +270,7 @@ def hdx_convert_values_to_boolean_for_dataset_preview(key, data, errors, context
break
data[temp_key_preview] = False
i += 1
data[key] = True

elif value in ('0', 0):
data[key] = False
else:
# value not in ('1',1,'0',0, True, False, 'True', 'False'):
data[key] = None
data[key] = new_value
return data[key]


Expand Down
6 changes: 5 additions & 1 deletion ckanext-hdx_package/ckanext/hdx_package/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ def show_package_schema(self):
schema = super(HDXPackagePlugin, self).show_package_schema()

self._remove_package_fields_from_schema(schema)

schema['resources'].update(
{
'format': [
Expand Down Expand Up @@ -360,8 +359,13 @@ def show_package_schema(self):
tk.get_validator('ignore_missing'),
tk.get_validator('boolean_validator')
],
'dataset_preview_enabled': [
tk.get_validator('ignore_missing'),
tk.get_validator('boolean_validator'),
],
}
)

schema.update({
# Notes == description. Makes description required
'notes': [vd.not_empty_ignore_ws],
Expand Down
2 changes: 1 addition & 1 deletion ckanext-hdx_package/ckanext/hdx_package/views/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def read(id):
dataset_preview_disabled_list = []
if _dataset_preview == vd._DATASET_PREVIEW_RESOURCE_ID:
for r in view_enabled_resources:
if r.get('dataset_preview_enabled'):
if r.get('dataset_preview_enabled') is True:
dataset_preview_enabled_list.append(r)
else:
dataset_preview_disabled_list.append(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,19 +427,17 @@
var selectOptions = $('#field_dataset_preview_value').prop('options');
selectOptions[0] = new Option('Default (first resource with preview)', 'first_resource');
var i = 'first_resource';
$.each(newOptions, function(index, value) {
var resName = value.get('name') ? value.get('name') : 'Resource '+(index+1);
if (value.get('dataset_preview_enabled') === true){
selectOptions[selectOptions.length] = new Option(resName, index+'', true, true);
i = index+'';
}
else {
selectOptions[selectOptions.length] = new Option(resName, index+'');
}
});
$.each(newOptions, function (index, value) {
var resName = value.get('name') ? value.get('name') : 'Resource ' + (index + 1);
if (value.get('dataset_preview_enabled') === true) {
selectOptions[selectOptions.length] = new Option(resName, index + '', true, true);
i = index + '';
} else {
selectOptions[selectOptions.length] = new Option(resName, index + '');
}
});
$("#field_dataset_preview_value").val(i).trigger('change');


},
'generateResourcePostData': function() {
var resourceModelList = this.resourceModelList.models;
Expand Down

0 comments on commit 2eecb65

Please sign in to comment.