Commit 2cc790a8 authored by David Read's avatar David Read
Browse files

Unpublished datasets excluded from the report - licence not relevant. Also...

Unpublished datasets excluded from the report - licence not relevant. Also linkified the licence text in the report.
parent 9b6f36d9
......@@ -3,6 +3,8 @@ import datetime
import logging
import os
from paste.deploy.converters import asbool
from ckan import model
from ckan.lib.helpers import OrderedDict
import ckan.plugins as p
......@@ -681,7 +683,6 @@ def licence_report(organization=None, include_sub_organizations=False):
Returns a dictionary detailing licences for datasets in the
organisation specified, and optionally sub organizations.
'''
import json
# Get packages
if organization:
top_org = model.Group.by_name(organization)
......@@ -709,11 +710,16 @@ def licence_report(organization=None, include_sub_organizations=False):
# Get their licences
packages_by_licence = collections.defaultdict(list)
rows = []
num_pkgs = 0
for pkg in pkgs:
if asbool(pkg.extras.get('unpublished')) is True:
# Ignore unpublished datasets
continue
licence_tuple = (pkg.license_id or '',
pkg.license.title if pkg.license else '',
pkg.extras.get('licence', ''))
packages_by_licence[licence_tuple].append((pkg.name, pkg.title))
num_pkgs += 1
for licence_tuple, dataset_tuples in sorted(packages_by_licence.items(),
key=lambda x: -len(x[1])):
......@@ -730,7 +736,7 @@ def licence_report(organization=None, include_sub_organizations=False):
rows.append(licence_dict)
return {
'num_datasets': len(pkgs),
'num_datasets': num_pkgs,
'num_licences': len(rows),
'table': rows,
}
......
......@@ -2,6 +2,7 @@
<li>Datasets: {{data['num_datasets']}}</li>
<li>Licences: {{data['num_licences']}}</li>
</ul>
<p>NB Unpublished datasets are excluded from this report</p>
<table class="table table-bordered table-condensed" id="report-table" style="width: 100%; table-layout: fixed;">
<thead>
......@@ -15,7 +16,7 @@
{% for row_dict in data['table'] %}
<tr>
<td>{{row_dict['license_title']}} {% if not row_dict['license_title'] and row_dict['licence'] %}(Custom){% endif %}</td>
<td>{{row_dict['licence']}}</td>
<td>{{h.linkify(row_dict['licence'])}}</td>
<td>
{% set names = row_dict['dataset_names'].split() %}
{% set titles = row_dict['dataset_titles'].split('|') %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment