From: Alex Sadleir Date: Mon, 16 Sep 2013 09:23:09 +0000 Subject: Show edited and created datasets on user profile/dashboard X-Git-Url: https://maxious.lambdacomplex.org/git/?p=ckanext-datagovau.git&a=commitdiff&h=c84d10ac6b729de3e838eeb734995bd49de8d4b8 --- Show edited and created datasets on user profile/dashboard --- --- a/ckanext/datagovau/plugin.py +++ b/ckanext/datagovau/plugin.py @@ -1,21 +1,29 @@ 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 +#parse the activity feed for last active non-system user +def get_last_active_user(id): + system_user = "de0ba262-83fe-45e2-adda-41bb9f0c86d8" + user_list = [x for x in lib.helpers.get_action('package_activity_list',{'id':id}) if x['user_id'] != system_user] + user = user_list[0]['user_id'] + if user is None: + return lib.helpers.get_action('user_show',{'id':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_id_list = [x['data']['package'] for x in + lib.helpers.get_action('user_activity_list',{'id':user_dict['id']}) if x['data'].get('package')] + active_datasets_list = active_datasets_id_list #if you need more detail, fetch each dataset here + print active_datasets_list + return created_datasets_list + active_datasets_list class ExampleIDatasetFormPlugin(plugins.SingletonPlugin, @@ -53,7 +61,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 --- a/ckanext/datagovau/templates/package/read.html +++ b/ckanext/datagovau/templates/package/read.html @@ -137,19 +137,26 @@ {% endif %} - {% if pkg.maintainer_email %} +{% set email =h.get_last_active_user(c.pkg_dict['id']).get('email','') %} {{ _('Maintainer') }} {{ - h.mail_to(email_address=pkg.maintainer_email, name=pkg.maintainer) }} + h.mail_to(email_address=(email or ' '), name=h.get_last_active_user(c.pkg_dict['id']).get("display_name",'')) }} - {% elif pkg.maintainer %} - {{ _('Maintainer') }} - {{ pkg.maintainer }} + Publisher/Agency + {{ c.pkg_dict['organization']['title']}} + - {% endif %} + + Type + Dataset + + + Language + English + --- a/ckanext/datagovau/templates/package/read.rdf +++ b/ckanext/datagovau/templates/package/read.rdf @@ -24,7 +24,17 @@ ${c.pkg_dict['metadata_created']} ${c.pkg_dict['metadata_modified']} en + + + ${c.pkg_dict['license_url']} + + + + ${c.pkg_dict['license_id']} + + + ${ tag_dict["name"] } @@ -69,16 +79,14 @@ ${ c.pkg_dict['organization']['title'] } - + - ${h.get_action("user_show",{"id":username})["display_name"]} - + ${h.get_last_active_user(c.pkg_dict['id'])["display_name"]} + - ${h.get_pkg_dict_extra(c.pkg_dict,'DCTERMS.Source.URI') } --- /dev/null +++ b/ckanext/datagovau/templates/user/dashboard_datasets.html @@ -1,1 +1,16 @@ +{% ckan_extends %} +{% block primary_content_inner %} +

{{ _('My Datasets') }}

+ {% if h.get_user_datasets(c.user_dict) %} + {% snippet 'snippets/package_list.html', packages=h.get_user_datasets(c.user_dict) %} + {% else %} +

+ You haven\'t created/edited any datasets. + {% if h.check_access('package_create') %} + {% link_for _('Create one now?'), controller='package', action='new' %} + {% endif %} +

+ {% endif %} +{% endblock %} + --- /dev/null +++ b/ckanext/datagovau/templates/user/read.html @@ -1,1 +1,29 @@ +{% ckan_extends %} + +{% block primary_content_inner %} +

+ {% block page_heading %}{{ _('Datasets') }}{% endblock %} +

+ {% block package_list %} + {% if h.get_user_datasets(c.user_dict) %} + {% snippet 'snippets/package_list.html', packages=h.get_user_datasets(c.user_dict) %} + {% else %} + + {% if c.is_myself %} +

+ {{ _('You haven\'t created any datasets.') }} + {% if h.check_access('package_create') %} + {% link_for _('Create one now?'), controller='package', action='new' %} + {% endif %} +

+ {% else %} +

+ {{ _('User hasn\'t created any datasets.') }} +

+ {% endif %} + {% endif %} + {% endblock %} +{% endblock %} + +