fixes
--- a/ckanext/dga_stats/stats.py
+++ b/ckanext/dga_stats/stats.py
@@ -57,8 +57,8 @@
s = select([member.c.group_id, func.count(member.c.table_id)]).\
group_by(member.c.group_id).\
where(and_(member.c.group_id!=None, member.c.table_name=='package')).\
- order_by(func.count(member.c.table_id).desc()).\
- limit(limit)
+ order_by(func.count(member.c.table_id).desc())
+ #limit(limit)
res_ids = model.Session.execute(s).fetchall()
res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), val) for group_id, val in res_ids]
@@ -68,10 +68,11 @@
def by_org(cls, limit=10):
group = table('group')
package = table('package')
- s = select([group.c.id, package.c.private, func.count(package.c.private)]).\
+ s = select([group.c.id, package.c.private, func.count('*')], group_by=[group.c.id, package.c.private]).\
+ where(group.c.is_organization == True).\
group_by(group.c.id, package.c.private).\
- order_by(group.c.id).\
- limit(limit)
+ order_by(group.c.name)
+ #limit(limit)
res_ids = model.Session.execute(s).fetchall()
res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), private, val) for group_id, private, val in res_ids]
@@ -108,10 +109,9 @@
package_role = table('package_role')
user_object_role = table('user_object_role')
package = table('package')
-# join(package, package_role.c.package_id == package.c.id).\
-# where(package.c.private == 'f').\
- s = select([user_object_role.c.user_id, func.count(user_object_role.c.role)], from_obj=[user_object_role.join(package_role)]).\
+ s = select([user_object_role.c.user_id, func.count(user_object_role.c.role)], from_obj=[user_object_role.join(package_role).join(package, package_role.c.package_id == package.c.id)]).\
where(user_object_role.c.role==model.authz.Role.ADMIN).\
+ where(package.c.private == 'f').\
where(user_object_role.c.user_id!=None).\
group_by(user_object_role.c.user_id).\
order_by(func.count(user_object_role.c.role).desc()).\
@@ -222,7 +222,7 @@
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)]).\
+ s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision).join(package)]).\
where(package.c.private == 'f').\
group_by(package_revision.c.id).order_by(func.min(revision.c.timestamp))
res = model.Session.execute(s).fetchall() # [(id, datetime), ...]
--- a/ckanext/dga_stats/templates/ckanext/stats/index.html
+++ b/ckanext/dga_stats/templates/ckanext/stats/index.html
@@ -29,6 +29,7 @@
<p class="empty">{{ _('No groups') }}</p>
{% endif %}
</section>
+{% if h.check_access('sysadmin') %}
<section id="activity-counts" class="module-content tab-content">
<h2>{{ _('Site Activity Log') }}</h2>
{% if c.activity_counts %}
@@ -79,7 +80,6 @@
<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 %}
@@ -227,7 +227,7 @@
<p class="empty">{{ _('No groups') }}</p>
{% endif %}
</section>
-
+<!--
<section id="stats-top-tags" class="module-content tab-content">
<h2>{{ _('Top Tags') }}</h2>
<table class="table table-chunky table-bordered table-striped">
@@ -247,7 +247,7 @@
</tbody>
</table>
</section>
-
+-->
<section id="stats-most-owned" class="module-content tab-content">
<h2>{{ _('Users Owning Most Datasets') }}</h2>
<table class="table table-chunky table-bordered table-striped">
@@ -267,7 +267,7 @@
</tbody>
</table>
</section>
- <section id="stats-by-org" class="module-content tab-content">
+<!-- <section id="stats-by-org" class="module-content tab-content">
<h2>{{ _('Datasets by Organization') }}</h2>
{% if c.by_org %}
<table class="table table-chunky table-bordered table-striped">
@@ -296,7 +296,7 @@
<p class="empty">{{ _('No groups') }}</p>
{% endif %}
</section>
-
+-->
</article>
{% endblock %}
@@ -306,18 +306,18 @@
<nav data-module="stats-nav">
<ul class="unstyled nav nav-simple">
<li class="nav-item active"><a href="#summary" data-toggle="tab">{{ _('Summary') }}</a></li>
+{% if h.check_access('sysadmin') %}
<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 %}
<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>
- <li class="nav-item"><a href="#stats-top-tags" data-toggle="tab">{{ _('Top Tags') }}</a></li>
+<!-- <li class="nav-item"><a href="#stats-top-tags" data-toggle="tab">{{ _('Top Tags') }}</a></li> -->
<li class="nav-item"><a href="#stats-most-owned" data-toggle="tab">{{ _('Users Owning Most Datasets') }}</a></li>
- <li class="nav-item"><a href="#stats-by-org" data-toggle="tab">{{ _('Datasets by Organization') }}</a></li>
+<!-- <li class="nav-item"><a href="#stats-by-org" data-toggle="tab">{{ _('Datasets by Organization') }}</a></li> -->
</ul>
</nav>
</section>