Skip to content

Commit

Permalink
Add indicators resource view template
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarans committed Apr 8, 2020
1 parent 582e759 commit 3c92703
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/hdx/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,19 +1571,29 @@ def generate_resource_view(self, resource=0, path=None, bites_disabled=None, ind
if bites_disabled is not None or indicators is not None:
hxl_preview_config = resourceview['hxl_preview_config']
if indicators is not None:
if indicators[0] is not None:
len_indicators = len(indicators)
if len_indicators == 0:
return None
if bites_disabled is None:
bites_disabled = [True, True, True]
if indicators[0]:
hxl_preview_config = hxl_preview_config.replace('INDICATOR_CODE_1', indicators[0]['code'])
hxl_preview_config = hxl_preview_config.replace('INDICATOR_TITLE_1', indicators[0]['title'])
hxl_preview_config = hxl_preview_config.replace('INDICATOR_UNIT_1', indicators[0]['unit'])
if indicators[1] is not None:
bites_disabled[0] = False
if len_indicators > 1 and indicators[1]:
hxl_preview_config = hxl_preview_config.replace('INDICATOR_CODE_2', indicators[1]['code'])
hxl_preview_config = hxl_preview_config.replace('INDICATOR_TITLE_2', indicators[1]['title'])
hxl_preview_config = hxl_preview_config.replace('INDICATOR_UNIT_2', indicators[1]['unit'])
if indicators[2] is not None:
bites_disabled[1] = False
if len_indicators > 2 and indicators[2]:
hxl_preview_config = hxl_preview_config.replace('INDICATOR_CODE_3', indicators[2]['code'])
hxl_preview_config = hxl_preview_config.replace('INDICATOR_TITLE_3', indicators[2]['title'])
hxl_preview_config = hxl_preview_config.replace('INDICATOR_UNIT_3', indicators[2]['unit'])
if bites_disabled is not None:
bites_disabled[2] = False
if bites_disabled == [True, True, True]:
return None
if bites_disabled:
hxl_preview_config = json.loads(hxl_preview_config)
bites = hxl_preview_config['bites']
for i, disable in reversed(list(enumerate(bites_disabled))):
Expand Down
2 changes: 1 addition & 1 deletion src/hdx/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.6
4.3.7
4 changes: 4 additions & 0 deletions tests/hdx/data/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,8 @@ def test_generate_resource_view(self, configuration, post_update, static_resourc
assert hxl_preview_config['bites'][2]['ingredient']['filters']['filterWith'][0]['#indicator+code'] == '3'
assert hxl_preview_config['bites'][2]['uiProperties']['title'] == 'My3'
assert hxl_preview_config['bites'][2]['computedProperties']['dataTitle'] == 'threes'
assert dataset.generate_resource_view(indicators=[]) is None
assert dataset.generate_resource_view(indicators=[None, None, None]) is None
assert dataset.generate_resource_view(resource='123', path=static_resource_view_yaml) is None
del dataset.get_resources()[0]['id']
resourceview = dataset.generate_resource_view(path=static_resource_view_yaml)
Expand All @@ -1383,6 +1385,8 @@ def test_generate_resource_view(self, configuration, post_update, static_resourc
dataset['id'] = 'TEST1'
dataset.update_in_hdx()
assert dataset.preview_resourceview is None
with pytest.raises(FileNotFoundError):
dataset.generate_resource_view()

def test_get_hdx_url(self, configuration, hdx_config_yaml, project_config_yaml):
dataset = Dataset()
Expand Down

0 comments on commit 3c92703

Please sign in to comment.