add recent datasets
--- /dev/null
+++ b/.gitignore
@@ -1,1 +1,36 @@
+*.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
+
Binary files a/ckanext/__init__.pyc and /dev/null differ
Binary files a/ckanext/dga_stats/__init__.pyc and /dev/null differ
--- 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()
Binary files a/ckanext/dga_stats/controller.pyc and /dev/null differ
Binary files a/ckanext/dga_stats/plugin.pyc and /dev/null differ
--- 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):
@@ -205,6 +221,7 @@
# be 'for all time' else you get first revision in the time period.
package_revision = table('package_revision')
revision = table('revision')
+ package = table('package')
s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision)]).\
where(package.c.private == 'f').\
group_by(package_revision.c.id).order_by(func.min(revision.c.timestamp))
Binary files a/ckanext/dga_stats/stats.pyc and /dev/null differ
--- a/ckanext/dga_stats/templates/ckanext/stats/index.html
+++ b/ckanext/dga_stats/templates/ckanext/stats/index.html
@@ -54,7 +54,58 @@
<p class="empty">{{ _('No groups') }}</p>
{% endif %}
</section>
-
+ <section id="recent-datasets" class="module-content tab-content">
+ <h2>{{ _('Recent Datasets') }}</h2>
+ {% if c.recent_datasets %}
+ <table class="table table-chunky table-bordered table-striped">
+ <thead>
+ <tr>
+ <th>{{ _('Date') }}</th>
+ <th>{{ _('Dataset') }}</th>
+ <th>{{ _('New/Modified') }}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for date,package,newmodified in c.recent_datasets %}
+ <tr>
+ <td>{{ date }}</td>
+ <td>{{ h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name)) }}</td>
+ <td>{{ newmodified }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% else %}
+ <p class="empty">{{ _('No groups') }}</p>
+ {% endif %}
+ </section>
+{% if h.check_access('sysadmin') %}
+ <section id="user-access-list" class="module-content tab-content">
+ <h2>{{ _('User Access List') }}</h2>
+ {% if c.user_access_list %}
+ <table class="table table-chunky table-bordered table-striped">
+ <thead>
+ <tr>
+ <th>{{ _('Username') }}</th>
+ <th>{{ _('Sysadmin') }}</th>
+ <th class="metric">{{ _('Organisational Role') }}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for username,sysadmin,role in c.user_access_list %}
+ <tr>
+ <td>{{ username }}</td>
+ <td>{{ sysadmin }}</td>
+ <td>{{ role }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% else %}
+ <p class="empty">{{ _('No groups') }}</p>
+ {% endif %}
+ </section>
+{% endif %}
<section id="stats-total-datasets" class="module-content tab-content active">
<h2>{{ _('Total number of Datasets') }}</h2>
@@ -254,9 +305,13 @@
<h2 class="module-heading"><i class="icon-bar-chart icon-medium"></i> {{ _('Statistics Menu') }}</h2>
<nav data-module="stats-nav">
<ul class="unstyled nav nav-simple">
- <li class="nav-item"><a href="#summary" data-toggle="tab">{{ _('Summary') }}</a></li>
+ <li class="nav-item active"><a href="#summary" data-toggle="tab">{{ _('Summary') }}</a></li>
<li class="nav-item"><a href="#activity-counts" data-toggle="tab">{{ _('Site Activity Log') }}</a></li>
- <li class="nav-item active"><a href="#stats-total-datasets" data-toggle="tab">{{ _('Total Number of Datasets') }}</a></li>
+ <li class="nav-item"><a href="#recent-datasets" data-toggle="tab">{{ _('Recent Datasets') }}</a></li>
+{% if h.check_access('sysadmin') %}
+ <li class="nav-item"><a href="#user-access-list" data-toggle="tab">{{ _('User Access List') }}</a></li>
+{% endif %}
+ <li class="nav-item"><a href="#stats-total-datasets" data-toggle="tab">{{ _('Total Number of Datasets') }}</a></li>
<li class="nav-item"><a href="#stats-dataset-revisions" data-toggle="tab">{{ _('Dataset Revisions per Week') }}</a></li>
<!-- <li class="nav-item"><a href="#stats-top-rated" data-toggle="tab">{{ _('Top Rated Datasets') }}</a></li> -->
<li class="nav-item"><a href="#stats-most-edited" data-toggle="tab">{{ _('Most Edited Datasets') }}</a></li>