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

Fix main css #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions ckanext/datopian/actions.py
Original file line number Diff line number Diff line change
@@ -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 result
14 changes: 14 additions & 0 deletions ckanext/datopian/plugin.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -10,6 +11,7 @@ def hello_plugin():
class DatopianPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IBlueprint)
plugins.implements(plugins.IActions)

# IConfigurer

Expand All @@ -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 {}
2 changes: 1 addition & 1 deletion ckanext/datopian/templates/admin/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -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']) }}

Expand Down
5 changes: 2 additions & 3 deletions ckanext/datopian/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datopian/templates/macros/autoform.html
Original file line number Diff line number Diff line change
Expand Up @@ -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')},
Expand Down