add recent datasets
--- a/ckanext/dga_stats/controller.py
+++ b/ckanext/dga_stats/controller.py
@@ -18,6 +18,7 @@
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
@@ -140,6 +141,16 @@
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
@@ -46,6 +46,31 @@
<td>{{ month }}</td>
<td>{{ type }}</td>
<td class="metric">{{ count }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% else %}
+ <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>
@@ -282,6 +307,7 @@
<ul class="unstyled nav nav-simple">
<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"><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 %}