Skip to content

Commit

Permalink
refactor: Make logic in 'get_query_params_from_metadata' simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Jan 9, 2025
1 parent d3842c4 commit 950e320
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 3 additions & 1 deletion onadata/libs/tests/utils/test_export_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def test_get_query_params_from_metadata_fn(self):
{
"title": "start",
"fields": "",
"simple_style": None,
"geo_field": "qn09",
},
get_query_params_from_metadata(metadata),
Expand All @@ -307,9 +308,10 @@ def test_get_query_params_from_metadata_fn(self):
}
self.assertEqual(
{
"title": "start",
"fields": "one,two",
"geo_field": "qn09",
"simple_style": None,
"title": "start",
},
get_query_params_from_metadata(metadata),
)
Expand Down
14 changes: 4 additions & 10 deletions onadata/libs/utils/export_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,17 +649,11 @@ def get_query_params_from_metadata(metadata):
return None

extra_data = metadata.extra_data
keys_mapping = {
"data_geo_field": "geo_field",
"data_simple_style": "simple_style",
"data_title": "title",
"data_fields": "fields",
}

return {
mapped_key: extra_data[original_key]
for original_key, mapped_key in keys_mapping.items()
if original_key in extra_data
"geo_field": extra_data.get("data_geo_field"),
"simple_style": extra_data.get("data_simple_style"),
"title": extra_data.get("data_title"),
"fields": extra_data.get("data_fields"),
}


Expand Down

0 comments on commit 950e320

Please sign in to comment.