From: Alex Sadleir Date: Tue, 22 Oct 2013 11:30:14 +0000 Subject: add recent datasets X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-dga-stats.git&a=commitdiff&h=dbc82f6a6ecc236b588bd6c15b5ebb7bf2f56b2a --- add recent datasets --- --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,36 @@ -*.pyc +*.py[cod] +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + --- a/ckanext/dga_stats/controller.py +++ b/ckanext/dga_stats/controller.py @@ -17,6 +17,8 @@ c.summary_stats = stats.summary_stats() c.activity_counts = stats.activity_counts() c.by_org = stats.by_org() + c.user_access_list = stats.user_access_list() + c.recent_datasets = stats.recent_datasets() c.new_packages_by_week = rev_stats.get_by_week('new_packages') c.deleted_packages_by_week = rev_stats.get_by_week('deleted_packages') c.num_packages_by_week = rev_stats.get_num_packages_by_week() --- a/ckanext/dga_stats/stats.py +++ b/ckanext/dga_stats/stats.py @@ -2,6 +2,7 @@ from pylons import config from sqlalchemy import Table, select, func, and_ +from sqlalchemy.sql.expression import text import ckan.plugins as p import ckan.model as model @@ -122,7 +123,6 @@ @classmethod def summary_stats(cls): connection = model.Session.connection() -# select name,role from user_object_role inner join \"user\" on user_object_role.user_id = \"user\".id where name not in ('logged_in','visitor') group by name,role" res = connection.execute("SELECT 'Total Organisations', count(*) from \"group\" where type = 'organization' and state = 'active' union \ select 'Total Datasets', count(*) from package where state='active' or state='draft' or state='draft-complete' union \ @@ -135,6 +135,22 @@ connection = model.Session.connection() res = connection.execute("select to_char(timestamp, 'YYYY-MM') as month,activity_type, count(*) from activity group by month, activity_type order by month;").fetchall(); return res + + @classmethod + def user_access_list(cls): + connection = model.Session.connection() + res = connection.execute("select name,sysadmin,role from user_object_role right outer join \"user\" on user_object_role.user_id = \"user\".id where name not in ('logged_in','visitor') group by name,sysadmin,role order by sysadmin desc, role asc;").fetchall(); + return res + + @classmethod + def recent_datasets(cls): + activity = table('activity') + package = table('package') + s = select([func.max(activity.c.timestamp),package.c.id, activity.c.activity_type], from_obj=[activity.join(package,activity.c.object_id == package.c.id)]).where(package.c.private == 'f').\ + where(activity.c.timestamp > func.now() - text("interval '60 day'")).group_by(package.c.id,activity.c.activity_type).order_by(func.max(activity.c.timestamp)) + result = model.Session.execute(s).fetchall() + return [(datetime2date(timestamp), model.Session.query(model.Package).get(unicode(package_id)), activity_type) for timestamp,package_id,activity_type in result] + class RevisionStats(object): --- a/ckanext/dga_stats/templates/ckanext/stats/index.html +++ b/ckanext/dga_stats/templates/ckanext/stats/index.html @@ -54,7 +54,58 @@

{{ _('No groups') }}

{% endif %} - +
+

{{ _('Recent Datasets') }}

+ {% if c.recent_datasets %} + + + + + + + + + + {% for date,package,newmodified in c.recent_datasets %} + + + + + + {% endfor %} + +
{{ _('Date') }}{{ _('Dataset') }}{{ _('New/Modified') }}
{{ date }}{{ h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name)) }}{{ newmodified }}
+ {% else %} +

{{ _('No groups') }}

+ {% endif %} +
+{% if h.check_access('sysadmin') %} +
+

{{ _('User Access List') }}

+ {% if c.user_access_list %} + + + + + + + + + + {% for username,sysadmin,role in c.user_access_list %} + + + + + + {% endfor %} + +
{{ _('Username') }}{{ _('Sysadmin') }}{{ _('Organisational Role') }}
{{ username }}{{ sysadmin }}{{ role }}
+ {% else %} +

{{ _('No groups') }}

+ {% endif %} +
+{% endif %}

{{ _('Total number of Datasets') }}

@@ -254,9 +305,13 @@

{{ _('Statistics Menu') }}