Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom script snippet to footer #87

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ckanext/opendata_theme/base/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ def package_tracking_summary(package):
tracking_summary = result.get('tracking_summary')
except Exception:
logger.debug("[opendata_theme] Error getting dataset tracking_summary")
return {}
return {
'total': 0,
'recent': 0
}
return tracking_summary


Expand Down
13 changes: 13 additions & 0 deletions ckanext/opendata_theme/opengov_custom_footer/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 @@ -48,6 +49,7 @@ 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 @@ -59,6 +61,17 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
{% endblock %}
</div>
</div>
{% set script_snippet = h.opendata_theme_get_footer_script_snippet() %}
{% if script_snippet %}
{{ script_snippet }}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
{% endblock %}
</div>
</div>
{% set script_snippet = h.opendata_theme_get_footer_script_snippet() %}
{% if script_snippet %}
{{ script_snippet }}
{% endif %}
{% endblock %}