Remove old extras, include more RDFa markup for distributions/data resources
[ckanext-datagovau.git] / ckanext / datagovau / plugin.py
blob:a/ckanext/datagovau/plugin.py -> blob:b/ckanext/datagovau/plugin.py
--- a/ckanext/datagovau/plugin.py
+++ b/ckanext/datagovau/plugin.py
@@ -6,6 +6,9 @@
 import ckan.plugins.toolkit as tk
 import ckan.model as model
 from pylons import config
+
+from sqlalchemy import orm
+import ckan.model
 
 #parse the activity feed for last active non-system user
 def get_last_active_user(id):
@@ -26,8 +29,17 @@
 				lib.helpers.get_action('user_activity_list',{'id':user_dict['id']}) if x['data'].get('package')]
     return created_datasets_list + active_datasets_list
 
-def datastore_search(context, data_dict):
-        return {'success': True} # allow all
+def get_dga_stats():
+	connection = model.Session.connection()
+        res = connection.execute("SELECT 'organization', count(*) from \"group\" where type = 'organization' and state = 'active' 		union select 'package', count(*) from package where state='active' or state='draft' or state='draft-complete' 		union select 'resource', count(*) from resource where state='active' 		union select name||role, 0 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;")
+        return res
+
+
+def get_activity_counts():
+	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
+
 
 class DataGovAuPlugin(plugins.SingletonPlugin,
                                 tk.DefaultDatasetForm):
@@ -39,13 +51,6 @@
     plugins.implements(plugins.IConfigurer, inherit=False)
     plugins.implements(plugins.IDatasetForm, inherit=False)
     plugins.implements(plugins.ITemplateHelpers, inherit=False)
-    plugins.implements(plugins.IAuthFunctions)
-
-
-
-    def get_auth_functions(self):
-        return {'datastore_search': datastore_search}
-
 
     def update_config(self, config):
         # Add this plugin's templates dir to CKAN's extra_template_paths, so
@@ -59,7 +64,7 @@
         # config['licenses_group_url'] = 'http://%(ckan.site_url)/licenses.json'
 
     def get_helpers(self):
-        return {'get_last_active_user': get_last_active_user, 'get_user_datasets': get_user_datasets}
+        return {'get_last_active_user': get_last_active_user, 'get_user_datasets': get_user_datasets, 'get_dga_stats': get_dga_stats, 'get_activity_counts': get_activity_counts}
 
     def is_fallback(self):
         # Return True to register this plugin as the default handler for