From 5665bd75ea06cb360c7ff2192bdb525b6bef1802 Mon Sep 17 00:00:00 2001 From: Fuhu Xia Date: Wed, 29 Nov 2023 16:22:45 -0500 Subject: [PATCH 1/6] label dataset ngda and style it --- .../fanstatic_library/styles/datagovtheme.css | 74 ++++++++++++++++++- ckanext/datagovtheme/helpers.py | 9 +++ ckanext/datagovtheme/plugin.py | 1 + .../datagovtheme/public/css/datagovtheme.css | 2 - .../templates/snippets/package_item.html | 6 ++ 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css b/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css index d689171c..2c734600 100644 --- a/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css +++ b/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css @@ -656,7 +656,7 @@ a { } .label { display: inline; - padding: 0.2em 0.6em 0.3em; + padding: 0.2em 0.6em 0.2em; font-size: 75%; font-weight: 700; line-height: 1; @@ -736,6 +736,8 @@ a.label:focus { .module-narrow #dataset-map-container { height: 200px; + border-bottom: 1px solid #ddd; + border-top: 1px solid #ddd; } .module-content #dataset-map-container { height: 250px; @@ -2120,9 +2122,75 @@ p.module-content { float: left; } -.topic-aapi a i:before { - content: '\e600'; +/* BEGIN of styling NGDA lable using button arrows for bootstrap 3 */ +body .tagged-ngda { + background-color: #3498db; + border-color: #3498db; } +.btn-arrow-right { + padding-top: 1px; + padding-bottom:2px; + line-height: 1; + margin-right: 8px; + cursor: auto; +} +.btn-arrow-right, +.btn-arrow-left { + position: relative; + padding-left: 16px; + padding-right: 8px; +} +.btn-arrow-right:before, +.btn-arrow-right:after, +.btn-arrow-left:before, +.btn-arrow-left:after { /* make two squares (before and after), looking similar to the button */ + content:""; + position: absolute; + top: 2px; /* move it down because of rounded corners */ + width: 13px; /* same as height */ + height: 13px; /* button_outer_height / sqrt(2) */ + background: inherit; /* use parent background */ + border: inherit; /* use parent border */ + border-left-color: transparent; /* hide left border */ + border-bottom-color: transparent; /* hide bottom border */ + border-radius: 0px 4px 0px 0px; /* round arrow corner, the shorthand property doesn't accept "inherit" so it is set to 4px */ + -webkit-border-radius: 0px 4px 0px 0px; + -moz-border-radius: 0px 4px 0px 0px; +} +.btn-arrow-right:before, +.btn-arrow-right:after { + transform: rotate(45deg); /* rotate right arrow squares 45 deg to point right */ + -webkit-transform: rotate(45deg); + -moz-transform: rotate(45deg); + -o-transform: rotate(45deg); + -ms-transform: rotate(45deg); +} +.btn-arrow-left:before, +.btn-arrow-left:after { + transform: rotate(225deg); /* rotate left arrow squares 225 deg to point left */ + -webkit-transform: rotate(225deg); + -moz-transform: rotate(225deg); + -o-transform: rotate(225deg); + -ms-transform: rotate(225deg); +} +.btn-arrow-right:before, +.btn-arrow-left:before { /* align the "before" square to the left */ + left: -6px; +} +.btn-arrow-right:after, +.btn-arrow-left:after { /* align the "after" square to the right */ + right: -6px; +} +.btn-arrow-right:after, +.btn-arrow-left:before { /* bring arrow pointers to front */ + z-index: 1; +} +.btn-arrow-right:before, +.btn-arrow-left:after { /* hide arrow tails background */ + background-color: #f6f6f6; +} +/* END of styling NGDA lable using button arrows for bootstrap 3 */ + .dataset-collection { margin-right: 5px; diff --git a/ckanext/datagovtheme/helpers.py b/ckanext/datagovtheme/helpers.py index e655bb47..c0cd518e 100644 --- a/ckanext/datagovtheme/helpers.py +++ b/ckanext/datagovtheme/helpers.py @@ -647,6 +647,15 @@ def get_bureau_info(bureau_code): } +# returns true if the package contains a tag with the name 'ngda +def is_tagged_ngda(pkg_dict): + if 'tags' in pkg_dict: + for tag in pkg_dict['tags']: + if tag['name'].lower() == 'ngda': + return True + return False + + # TODO can we drop this dependency on ckanext-harvest? Can this be moved to ckanext-harvest? geodatagov? def get_pkg_dict_extra(pkg_dict, key, default=None): '''Override the CKAN core helper to add rolled up extras diff --git a/ckanext/datagovtheme/plugin.py b/ckanext/datagovtheme/plugin.py index a2219de5..c48f659d 100644 --- a/ckanext/datagovtheme/plugin.py +++ b/ckanext/datagovtheme/plugin.py @@ -88,6 +88,7 @@ def get_helpers(self): 'datagovtheme_api_doc_url': datagovtheme_helpers.api_doc_url, 'datagovtheme_get_reference_date': datagovtheme_helpers.get_reference_date, 'datagovtheme_get_responsible_party': datagovtheme_helpers.get_responsible_party, + 'is_tagged_ngda': datagovtheme_helpers.is_tagged_ngda, 'render_datetime_datagov': datagovtheme_helpers.render_datetime_datagov, 'get_harvest_object_formats': datagovtheme_helpers.get_harvest_object_formats, 'get_bureau_info': datagovtheme_helpers.get_bureau_info, diff --git a/ckanext/datagovtheme/public/css/datagovtheme.css b/ckanext/datagovtheme/public/css/datagovtheme.css index edf170ac..0130cf12 100644 --- a/ckanext/datagovtheme/public/css/datagovtheme.css +++ b/ckanext/datagovtheme/public/css/datagovtheme.css @@ -1790,8 +1790,6 @@ p.module-content{padding-left: 18px !important;} float: left; } -.topic-aapi a i:before{content:"\e600";} - .dataset-collection { margin-right: 5px; } diff --git a/ckanext/datagovtheme/templates/snippets/package_item.html b/ckanext/datagovtheme/templates/snippets/package_item.html index 04ab79e5..37091ce1 100755 --- a/ckanext/datagovtheme/templates/snippets/package_item.html +++ b/ckanext/datagovtheme/templates/snippets/package_item.html @@ -43,6 +43,12 @@

{% endif %} + {% if h.is_tagged_ngda(package) %} + + {{ _('NGDA') }} + + {% endif %} + {% if h.get_pkg_dict_extra(package, 'collection_metadata', '') %} From 8f4711a0637f5c1c1aa16063f736eed10f035cf5 Mon Sep 17 00:00:00 2001 From: Fuhu Xia Date: Thu, 30 Nov 2023 10:29:01 -0500 Subject: [PATCH 2/6] smaller --- .../fanstatic_library/styles/datagovtheme.css | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css b/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css index 2c734600..ffc5d987 100644 --- a/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css +++ b/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css @@ -2126,6 +2126,8 @@ p.module-content { body .tagged-ngda { background-color: #3498db; border-color: #3498db; + color: white; + font-size: 0.75em; } .btn-arrow-right { padding-top: 1px; @@ -2147,8 +2149,8 @@ body .tagged-ngda { content:""; position: absolute; top: 2px; /* move it down because of rounded corners */ - width: 13px; /* same as height */ - height: 13px; /* button_outer_height / sqrt(2) */ + width: 11px; /* same as height */ + height: 11px; /* button_outer_height / sqrt(2) */ background: inherit; /* use parent background */ border: inherit; /* use parent border */ border-left-color: transparent; /* hide left border */ @@ -2175,11 +2177,11 @@ body .tagged-ngda { } .btn-arrow-right:before, .btn-arrow-left:before { /* align the "before" square to the left */ - left: -6px; + left: -5px; } .btn-arrow-right:after, .btn-arrow-left:after { /* align the "after" square to the right */ - right: -6px; + right: -5px; } .btn-arrow-right:after, .btn-arrow-left:before { /* bring arrow pointers to front */ From 0332b02cdb1f73c1985db01aed2e628ac9a3dba1 Mon Sep 17 00:00:00 2001 From: Fuhu Xia Date: Thu, 30 Nov 2023 15:06:22 -0500 Subject: [PATCH 3/6] left arrow --- .../fanstatic_library/styles/datagovtheme.css | 19 ++++++++++++------- .../templates/snippets/package_item.html | 13 +++++++------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css b/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css index ffc5d987..3e9dc8dd 100644 --- a/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css +++ b/ckanext/datagovtheme/fanstatic_library/styles/datagovtheme.css @@ -2127,20 +2127,25 @@ body .tagged-ngda { background-color: #3498db; border-color: #3498db; color: white; - font-size: 0.75em; } .btn-arrow-right { - padding-top: 1px; - padding-bottom:2px; - line-height: 1; + padding-left: 14px; + padding-right: 8px; margin-right: 8px; - cursor: auto; +} +.btn-arrow-left { + padding-left: 8px; + padding-right: 14px; + margin-left: 8px; } .btn-arrow-right, .btn-arrow-left { position: relative; - padding-left: 16px; - padding-right: 8px; + font-size: 0.75em; + padding-top: 1px; + padding-bottom:2px; + line-height: 1; + cursor: auto; } .btn-arrow-right:before, .btn-arrow-right:after, diff --git a/ckanext/datagovtheme/templates/snippets/package_item.html b/ckanext/datagovtheme/templates/snippets/package_item.html index 37091ce1..df07c199 100755 --- a/ckanext/datagovtheme/templates/snippets/package_item.html +++ b/ckanext/datagovtheme/templates/snippets/package_item.html @@ -43,12 +43,6 @@

{% endif %} - {% if h.is_tagged_ngda(package) %} - - {{ _('NGDA') }} - - {% endif %} - {% if h.get_pkg_dict_extra(package, 'collection_metadata', '') %} @@ -62,6 +56,13 @@

{% elif package.get('state', '').startswith('deleted') %} {{ _('Deleted') }} {% endif %} + + {% if h.is_tagged_ngda(package) %} + + {{ _('NGDA') }} + + {% endif %} + {{ h.popular('recent views', package.tracking_summary.recent, min=10) if package.tracking_summary }}

From d00cc4371b338a1b0bf70d6f3ee54dee68e2345c Mon Sep 17 00:00:00 2001 From: Fuhu Xia Date: Thu, 30 Nov 2023 16:06:33 -0500 Subject: [PATCH 4/6] add test and bump version --- ckanext/datagovtheme/tests/test_helpers.py | 15 +++++++++++++++ setup.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ckanext/datagovtheme/tests/test_helpers.py b/ckanext/datagovtheme/tests/test_helpers.py index 5b56bd7b..474aafa5 100644 --- a/ckanext/datagovtheme/tests/test_helpers.py +++ b/ckanext/datagovtheme/tests/test_helpers.py @@ -6,6 +6,8 @@ import pytest from ckanext.datagovtheme import helpers +import ckan.tests.factories as factories + ################ @@ -117,3 +119,16 @@ def test_get_bureau_info_none(): bureau_info = helpers.get_bureau_info(None) assert bureau_info is None + + +def test_is_tagged_ngda(): + """Assert that package with ngda tag returns true.""" + dataset_ngda = factories.Dataset( + name="dataset-ngda", title="Dataset NGDA", tags=[{"name": "nGda"}] + ) + dataset_non_ngda = factories.Dataset( + name="dataset-non-ngda", title="Dataset Non NGDA", tags=[{"name": "non-ngda"}] + ) + + assert helpers.is_tagged_ngda(dataset_ngda) is True + assert helpers.is_tagged_ngda(dataset_non_ngda) is False \ No newline at end of file diff --git a/setup.py b/setup.py index 1eaad8c8..58fcfe99 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="ckanext-datagovtheme", - version="0.2.7", + version="0.2.8", description="CKAN Extension to manage data.gov theme", long_description=long_description, classifiers=[ From 677680db5f40730f735da60f6f207d808fcdbd76 Mon Sep 17 00:00:00 2001 From: Fuhu Xia Date: Thu, 30 Nov 2023 16:10:59 -0500 Subject: [PATCH 5/6] lint --- ckanext/datagovtheme/tests/test_helpers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ckanext/datagovtheme/tests/test_helpers.py b/ckanext/datagovtheme/tests/test_helpers.py index 474aafa5..19296f75 100644 --- a/ckanext/datagovtheme/tests/test_helpers.py +++ b/ckanext/datagovtheme/tests/test_helpers.py @@ -9,12 +9,10 @@ import ckan.tests.factories as factories - ################ # get_login_url ################ - @pytest.mark.ckan_config('ckanext.saml2auth.enable_ckan_internal_login', 'false') def test_saml2_login_url(): """ test saml2 URL on Catalog-next """ @@ -32,7 +30,6 @@ def test_login_url(): # api_doc_url ############## - @mock.patch('ckanext.datagovtheme.helpers.h') def test_api_doc_url(mock_ckan_lib_helpers): mock_ckan_lib_helpers.lang.return_value = 'en' @@ -46,7 +43,6 @@ def test_api_doc_url(mock_ckan_lib_helpers): # get_bureau_info ################## - def assert_url(actual_url, expected_bureau_code): # In CKAN 2.9, the url_for is returning a path ending in / which does not # happen in 2.8. Include an optional ending / in the path, use URL encoded @@ -121,14 +117,18 @@ def test_get_bureau_info_none(): assert bureau_info is None +################## +# ngda +################## + def test_is_tagged_ngda(): """Assert that package with ngda tag returns true.""" dataset_ngda = factories.Dataset( - name="dataset-ngda", title="Dataset NGDA", tags=[{"name": "nGda"}] - ) + name="dataset-ngda", title="Dataset NGDA", tags=[{"name": "nGda"}] + ) dataset_non_ngda = factories.Dataset( name="dataset-non-ngda", title="Dataset Non NGDA", tags=[{"name": "non-ngda"}] ) assert helpers.is_tagged_ngda(dataset_ngda) is True - assert helpers.is_tagged_ngda(dataset_non_ngda) is False \ No newline at end of file + assert helpers.is_tagged_ngda(dataset_non_ngda) is False From 4a11a2cbb17ac4aecf8c3e70abf34dcc746555a7 Mon Sep 17 00:00:00 2001 From: Fuhu Xia Date: Thu, 30 Nov 2023 16:15:59 -0500 Subject: [PATCH 6/6] lint --- ckanext/datagovtheme/tests/test_helpers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ckanext/datagovtheme/tests/test_helpers.py b/ckanext/datagovtheme/tests/test_helpers.py index 19296f75..9d1649e2 100644 --- a/ckanext/datagovtheme/tests/test_helpers.py +++ b/ckanext/datagovtheme/tests/test_helpers.py @@ -13,6 +13,7 @@ # get_login_url ################ + @pytest.mark.ckan_config('ckanext.saml2auth.enable_ckan_internal_login', 'false') def test_saml2_login_url(): """ test saml2 URL on Catalog-next """ @@ -30,6 +31,7 @@ def test_login_url(): # api_doc_url ############## + @mock.patch('ckanext.datagovtheme.helpers.h') def test_api_doc_url(mock_ckan_lib_helpers): mock_ckan_lib_helpers.lang.return_value = 'en' @@ -43,6 +45,7 @@ def test_api_doc_url(mock_ckan_lib_helpers): # get_bureau_info ################## + def assert_url(actual_url, expected_bureau_code): # In CKAN 2.9, the url_for is returning a path ending in / which does not # happen in 2.8. Include an optional ending / in the path, use URL encoded @@ -121,6 +124,7 @@ def test_get_bureau_info_none(): # ngda ################## + def test_is_tagged_ngda(): """Assert that package with ngda tag returns true.""" dataset_ngda = factories.Dataset(