From 78e1ec4957e7139d005d231b008fdef757cc6d16 Mon Sep 17 00:00:00 2001 From: MZhiyenbayev Date: Thu, 23 Feb 2023 21:59:28 +0600 Subject: [PATCH 1/3] [css][xs]: fix for main css error --- ckanext/datopian/templates/admin/config.html | 2 +- ckanext/datopian/templates/base.html | 5 ++--- ckanext/datopian/templates/macros/autoform.html | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ckanext/datopian/templates/admin/config.html b/ckanext/datopian/templates/admin/config.html index 2fb7290..48f929c 100644 --- a/ckanext/datopian/templates/admin/config.html +++ b/ckanext/datopian/templates/admin/config.html @@ -13,7 +13,7 @@ {{ form.input('ckan.site_title', id='field-ckan-site-title', label=_('Site Title'), value=data['ckan.site_title'], error=error, classes=['control-medium']) }} - {{ form.select('ckan.main_css', id='field-ckan-main-css', label=_('Style'), options=styles, selected=data['ckan.main_css'], error=error) }} + {{ form.select('ckan.theme', id='field-ckan-main-css', label=_('Style'), options=styles, selected=data['ckan.theme'], error=error) }} {{ form.input('ckan.site_description', id='field-ckan-site-description', label=_('Site Tag Line'), value=data['ckan.site_description'], error=error, classes=['control-medium']) }} diff --git a/ckanext/datopian/templates/base.html b/ckanext/datopian/templates/base.html index 82fe7ab..1235fe3 100644 --- a/ckanext/datopian/templates/base.html +++ b/ckanext/datopian/templates/base.html @@ -68,9 +68,8 @@ {%- block styles %} {# TODO: store just name of asset instead of path to it. #} - {% set main_css = h.get_rtl_css() if h.is_rtl_language() else g.main_css %} - {# strip '/base/' prefix and '.css' suffix #} - {% asset main_css[6:-4] %} + {% set theme = h.get_rtl_theme() if h.is_rtl_language() else g.theme %} + {% asset theme %} {% endblock %} diff --git a/ckanext/datopian/templates/macros/autoform.html b/ckanext/datopian/templates/macros/autoform.html index 7ffc4c5..c469b81 100644 --- a/ckanext/datopian/templates/macros/autoform.html +++ b/ckanext/datopian/templates/macros/autoform.html @@ -12,7 +12,7 @@ {% set form_info = [ {'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': ''}, - {'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, + {'name': 'ckan.theme', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, {'name': 'ckan.site_description', 'control': 'input', 'label': _('Site Tag Line'), 'placeholder': ''}, {'name': 'ckan.site_logo', 'control': 'input', 'label': _('Site Tag Logo'), 'placeholder': ''}, {'name': 'ckan.site_about', 'control': 'markdown', 'label': _('About'), 'placeholder': _('About page text')}, From c3046883fdee16e10bb3747a44a17c8c404c4997 Mon Sep 17 00:00:00 2001 From: steveoni Date: Wed, 22 Mar 2023 13:08:37 +0100 Subject: [PATCH 2/3] add total_download to package_searc and package_show if googleanaltyics is enabled --- ckanext/datopian/actions.py | 41 +++++++++++++++++++++++++++++++++++++ ckanext/datopian/plugin.py | 14 +++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 ckanext/datopian/actions.py diff --git a/ckanext/datopian/actions.py b/ckanext/datopian/actions.py new file mode 100644 index 0000000..eb72ca4 --- /dev/null +++ b/ckanext/datopian/actions.py @@ -0,0 +1,41 @@ +import json +import logging +import ckan.plugins.toolkit as tk +import ckan.plugins as p +import ckan.lib.dictization.model_dictize as model_dictize +import ckan.model as model + +ValidationError = tk.ValidationError +_get_or_bust = tk.get_or_bust + +log = logging.getLogger(__name__) + +@p.toolkit.chained_action +@tk.side_effect_free +def package_search(up_func, context, data_dict): + result = up_func(context, data_dict) + + # Add bilingual groups + for pkg in result['results']: + try: + pkg['total_downloads'] = tk.get_action('package_stats')(context, {'package_id': pkg['id']}) + + except: + log.error('package {id} download stats not available'.format(id=pkg['id'])) + pkg['total_downloads'] = 0 + + return result + +@p.toolkit.chained_action +@tk.side_effect_free +def package_show(up_func,context,data_dict): + result = up_func(context, data_dict) + + id = result.get('id') + try: + result['total_downloads'] = tk.get_action('package_stats')(context, {'package_id': id}) + except: + log.error(f'package {id} download stats not available') + result['total_downloads'] = 0 + + return \ No newline at end of file diff --git a/ckanext/datopian/plugin.py b/ckanext/datopian/plugin.py index 3734379..46be35b 100644 --- a/ckanext/datopian/plugin.py +++ b/ckanext/datopian/plugin.py @@ -1,6 +1,7 @@ import ckan.plugins as plugins import ckan.plugins.toolkit as toolkit from flask import Blueprint, render_template +from ckanext.datopian.actions import package_search, package_show def hello_plugin(): @@ -10,6 +11,7 @@ def hello_plugin(): class DatopianPlugin(plugins.SingletonPlugin): plugins.implements(plugins.IConfigurer) plugins.implements(plugins.IBlueprint) + plugins.implements(plugins.IActions) # IConfigurer @@ -29,3 +31,15 @@ def get_blueprint(self): # Add plugin url rules to Blueprint object blueprint.add_url_rule('/hello_plugin', '/hello_plugin', hello_plugin) return blueprint + + + # IActions + def get_actions(self): + if "googleanalytics" in toolkit.config.get("ckan.plugins", "").split(): + # if so, add the action to the list of actions + return { + 'package_search': package_search, + 'package_show': package_show + } + + return {} From 1a9d314d03758c0f4d64fbe940be8622a9a9221d Mon Sep 17 00:00:00 2001 From: Stephen Oni Date: Mon, 27 Mar 2023 10:10:34 +0000 Subject: [PATCH 3/3] [action][s]: add return value --- ckanext/datopian/actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/datopian/actions.py b/ckanext/datopian/actions.py index eb72ca4..156021e 100644 --- a/ckanext/datopian/actions.py +++ b/ckanext/datopian/actions.py @@ -38,4 +38,4 @@ def package_show(up_func,context,data_dict): log.error(f'package {id} download stats not available') result['total_downloads'] = 0 - return \ No newline at end of file + return result