Skip to content

Commit

Permalink
#118 reports improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
etj committed Sep 24, 2020
1 parent c693f5d commit 16c605a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
31 changes: 31 additions & 0 deletions ckanext/faoclh/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FAOCLHGUIPlugin(plugins.SingletonPlugin,
plugins.implements(plugins.ITranslation)
plugins.implements(plugins.ITemplateHelpers)
plugins.implements(plugins.IRoutes)
plugins.implements(plugins.IAuthFunctions)

# IPackageController
def before_search(self, search_params):
Expand Down Expand Up @@ -263,6 +264,36 @@ def register_reports(self):
log.info('registering reports')
return all_reports()

# ------------- IAuthFunctions --------------- #
def get_auth_functions(self):
out = {}
for k in ('report_list', 'report_show',
'report_data_get', 'report_key_get',
'report_refresh',):
out[k] = check_if_super

# monkeypatch report plugin to avoid auth functions conflict
# in authz
from ckanext.report.plugin import ReportPlugin
def fake_get_auth_functions(s):
return {}

ReportPlugin.get_auth_functions = fake_get_auth_functions

return out

def check_if_super(context, data_dict=None):
out = {'success': False,
'msg': ''}
user = context.get('auth_user_obj')
if not user:
out['msg'] = 'User must be logged in'
return out
if not (user.state == 'active' and user.sysadmin):
out['msg'] = 'Only superuser can use reports'
return out
out['success'] = True
return out

def fao_voc(voc_name):
try:
Expand Down
9 changes: 9 additions & 0 deletions ckanext/faoclh/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ <h1>
<span class="badge">{{ new_activities }}</span>
</a>
</li>

{% if c.userobj.sysadmin %}
<li>
<a href="{{ h.url_for('reports') }}" title="{{ _('Reports') }}">
<i class="fa fa-tasks" aria-hidden="true"></i>
</a>
</li>
{% endif %}

<li>
<a href="{{ h.url_for('user.edit', id=c.userobj.name) }}" title="{{ _('Edit settings') }}">
<i class="fa fa-cog" aria-hidden="true"></i>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/faoclh/templates/report/broken_links_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<tr>
{% set dataset_title = h.gsreport_get_pkg_title(row['dataset_id'], h.lang()) %}
<td><a href="{{ row.dataset_url }}">{{ dataset_title or row.dataset_title }}</a></td>
<td>{{ row.resource_name|truncate(50) }}</td>
<td>{{ row.resource_name or '' |truncate(50) }}</td>
<td>{{ row.resource_format }}</td>
<td><a href="{{ row.res_url or row.resource_url }}">{{ row.res_url or row.resource_url}}</a></td>
<td>{{ _(row.error) }}</td>
Expand Down
69 changes: 69 additions & 0 deletions ckanext/faoclh/templates/report/view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "page.html" %}

{% block title %}{{ report.title }} - {{ _('Reports') }} - {{ super() }}{% endblock %}

{% block breadcrumb_content %}
{{ h.build_nav('reports', _('Reports')) }}
{{ h.build_nav('report-org' if '/organization' in request.environ.get('PATH_INFO', '') else 'report', report.title, report_name=report_name) }}
{% endblock%}

{% block primary_content_inner %}
<h1>{{ report.title }}</h1>
<p>{{ report.description }}</p>
<p>
{{ _('Generated') }}: {{ h.report__render_datetime(report_date, '%d/%m/%Y %H:%M') }}
</p>

{% if options %}
<h3>{{ _('Options') }}</h3>
<form action="">
{% for key, value in options.items() %}
{% if key in options_html %}
{{ options_html[key]|safe }}
{% else %}
{{ key }}: {{ value }}
<input type="hidden" name="{{ key }}" value="{{ value }}"/>
{% endif %}
<br/>
{% endfor %}
</form>
{% endif %}

{% if are_some_results %}
<div class="pull-right">
{{ _('Download') }}:
<a class="btn btn-primary" href="{{ h.report__relative_url_for(format='csv') }}">CSV</a>
<a class="btn btn-primary" href="{{ h.report__relative_url_for(format='json') }}">JSON</a>
</div>
{% endif %}
<h3>{{ _('Results') }}</h3>
{% if not are_some_results %}
<p>{{ _('No results found.') }}</p>
{% else %}
<div class="pull-left">
{% snippet report_template, table=data['table'], data=data, report_name=report_name, options=options %}
</div>
{% endif %}
</div>
{% endblock%}

{% block scripts %}
{{ super() }}
<!--! Tablesorter allows table sorting by clicking on each column -->
<script type="text/javascript" src="/scripts/vendor/jquery.tablesorter.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function()
{
$("#report-table").tablesorter({
dateFormat: "uk",
});
$(".js-auto-submit").change(function () {
$(this).closest("form").submit();
});
}
);
// ]]>
</script>
{% endblock%}

0 comments on commit 16c605a

Please sign in to comment.