--- a/ckanext/datagovau/plugin.py +++ b/ckanext/datagovau/plugin.py @@ -1,21 +1,30 @@ import logging import ckan.plugins as plugins +import ckan.lib as lib +import ckan.lib.dictization.model_dictize as model_dictize import ckan.plugins.toolkit as tk +import ckan.model as model +from pylons import config +#parse the activity feed for last active non-system user +def get_last_active_user(id): + system_user = lib.helpers.get_action('user_show',{'id': config.get('ckan.site_id', 'ckan_site_user')}) + user_list = [x for x in lib.helpers.get_action('package_activity_list',{'id':id}) if x['user_id'] != system_user['id']] + user = None + if len(user_list) > 0: + user = user_list[0].get('user_id', None) + if user is None: + return system_user + else: + return lib.helpers.get_action('user_show',{'id':user}) -# get_action will be deprecated soon, this is the replacement -def get_user(user): - user_name = unicode(user) - if user_name: - user_obj = model.User.get(id) - context['user_obj'] = user_obj - if user_obj is None: - raise NotFound - else: - raise NotFound - - return model_dictize.user_dictize(user_obj,context) +# get user created datasets and those they have edited +def get_user_datasets(user_dict): + created_datasets_list = user_dict['datasets'] + active_datasets_list = [x['data']['package'] for x in + lib.helpers.get_action('user_activity_list',{'id':user_dict['id']}) if x['data'].get('package')] + return created_datasets_list + active_datasets_list class ExampleIDatasetFormPlugin(plugins.SingletonPlugin, @@ -53,7 +62,7 @@ # config['licenses_group_url'] = 'http://%(ckan.site_url)/licenses.json' def get_helpers(self): - return {'getuser': get_user} + return {'get_last_active_user': get_last_active_user, 'get_user_datasets': get_user_datasets} def is_fallback(self): # Return True to register this plugin as the default handler for