From 629c0b0f6c09ecc1e3e36222e3f719552e18dfb4 Mon Sep 17 00:00:00 2001 From: Ian leggett <> Date: Thu, 24 Oct 2024 16:26:49 +0100 Subject: [PATCH] fix: add template filter to correctly format the table name --- .../apps/datasets/templatetags/datasets_tags.py | 5 +++++ .../datasets/details/sourceset_dataset.html | 4 ++-- .../tests/datasets/test_datasets_tags.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 dataworkspace/dataworkspace/tests/datasets/test_datasets_tags.py diff --git a/dataworkspace/dataworkspace/apps/datasets/templatetags/datasets_tags.py b/dataworkspace/dataworkspace/apps/datasets/templatetags/datasets_tags.py index 4b744c3297..096defcf76 100644 --- a/dataworkspace/dataworkspace/apps/datasets/templatetags/datasets_tags.py +++ b/dataworkspace/dataworkspace/apps/datasets/templatetags/datasets_tags.py @@ -182,3 +182,8 @@ def saved_grid_config(user, source): @register.filter def timedelta_to_minutes(td): return round(td.total_seconds() / 60, 2) + + +@register.filter +def format_table_name(table_name): + return table_name.capitalize().replace("_", " ") diff --git a/dataworkspace/dataworkspace/templates/datasets/details/sourceset_dataset.html b/dataworkspace/dataworkspace/templates/datasets/details/sourceset_dataset.html index 90ef604b07..0c66768ffe 100644 --- a/dataworkspace/dataworkspace/templates/datasets/details/sourceset_dataset.html +++ b/dataworkspace/dataworkspace/templates/datasets/details/sourceset_dataset.html @@ -117,11 +117,11 @@

Data tables

{% if has_access %} {% if source_table.data_grid_enabled %} - {{ source_table.name }} + {{ source_table.name|format_table_name }}moo {% endif %} {% else %} - {{ source_table.name }} + {{ source_table.name|format_table_name }} {% endif %} {% endif %} diff --git a/dataworkspace/dataworkspace/tests/datasets/test_datasets_tags.py b/dataworkspace/dataworkspace/tests/datasets/test_datasets_tags.py new file mode 100644 index 0000000000..3cafc4c43a --- /dev/null +++ b/dataworkspace/dataworkspace/tests/datasets/test_datasets_tags.py @@ -0,0 +1,16 @@ +from dataworkspace.apps.datasets.templatetags.datasets_tags import format_table_name + + +class TestFormatTableName: + def test_should_correctly_format_table_name(self): + test_cases = [ + 'This_Is_A_Table_Name', + 'this_is_a_table_name', + 'THIS_IS_A_TABLE_NAME', + 'tHIS_iS_a_tABLE_nAME', + 'This_is_a_table_name', + + ] + + for test in test_cases: + assert format_table_name(test) == 'This is a table name'