Skip to content

Commit

Permalink
Move footer_script_snippet helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
jguo144 committed Dec 5, 2024
1 parent b5bc582 commit 95a644e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
16 changes: 16 additions & 0 deletions ckanext/opendata_theme/base/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
from ckanext.opendata_theme.base.compatibility_controller import BaseCompatibilityController
from ckanext.opendata_theme.opengov_custom_homepage.constants import CUSTOM_NAMING

if toolkit.check_ckan_version(min_version='2.9.0'):
from ckan.lib.helpers import literal
else:
from webhelpers.html import literal


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -300,3 +305,14 @@ def get_default_extent():
[-66.9513812,24.7433195],[-66.9513812,49.3457868], \
[-124.7844079,49.3457868],[-124.7844079,24.7433195]]] }'
)


def get_footer_script_snippet():
pattern = r'<script\b[^>]*>(.*?)<\/script>'
script_snippet = toolkit.config.get('ckanext.opendata_theme.script_snippet', '')
if not script_snippet:
return False
match = re.match(pattern, script_snippet, re.IGNORECASE)
if not bool(match):
return False
return literal(script_snippet)
13 changes: 0 additions & 13 deletions ckanext/opendata_theme/opengov_custom_footer/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
import re

import ckanext.opendata_theme.base.helpers as helper
from ckanext.opendata_theme.opengov_custom_footer.controller import CustomFooterController
Expand Down Expand Up @@ -49,7 +48,6 @@ def get_validators(self):
def get_helpers(self):
return {
'opendata_theme_get_footer_data': get_footer_data,
'opendata_theme_get_footer_script_snippet': get_footer_script_snippet,
'version': helper.version_builder,
}

Expand All @@ -61,17 +59,6 @@ def get_footer_data(section):
return ''


def get_footer_script_snippet():
pattern = r'<script\b[^>]*>(.*?)<\/script>'
script_snippet = toolkit.config.get('ckanext.opendata_theme.script_snippet', '')
if not script_snippet:
return False
match = re.match(pattern, script_snippet, re.IGNORECASE)
if not bool(match):
return False
return literal(script_snippet)


def custom_footer_validator(value):
layout_type = value.get('layout_type')
if layout_type not in ['default', 'custom']:
Expand Down
1 change: 1 addition & 0 deletions ckanext/opendata_theme/opengov_custom_theme/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def get_helpers(self):
'opendata_theme_group_alias': helper.get_group_alias,
'opendata_theme_organization_alias': helper.get_organization_alias,
'opendata_theme_get_default_extent': helper.get_default_extent,
'opendata_theme_get_footer_script_snippet': helper.get_footer_script_snippet,
'opendata_theme_is_data_dict_active': helper.is_data_dict_active,
'version': helper.version_builder,
'opendata_theme_segment_writekey': helper.get_segment_writekey,
Expand Down

0 comments on commit 95a644e

Please sign in to comment.