From: CKAN data.gov.au Date: Thu, 12 Sep 2013 07:34:13 +0000 Subject: Move last active user logic to helper function X-Git-Url: https://maxious.lambdacomplex.org/git/?p=ckanext-datagovau.git&a=commitdiff&h=ddcc2681391e4a46a9bb58d4dde613fe84bdb648 --- Move last active user logic to helper function --- --- a/ckanext/datagovau/plugin.py +++ b/ckanext/datagovau/plugin.py @@ -1,21 +1,20 @@ 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 - -# 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 +#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: - raise NotFound - - return model_dictize.user_dictize(user_obj,context) + return lib.helpers.get_action('user_show',{'id':user}) class ExampleIDatasetFormPlugin(plugins.SingletonPlugin, @@ -53,7 +52,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} 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 @@ -44,11 +44,11 @@ {{ pkg.get('Agency Program') }} {% endif %} - {% if pkg.get('DCTERMS.Source.URI') %} + {% if h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI') %} {{ _('Source') }} - {{ h.link_to(pkg.get('DCTERMS.Source.URI'), - pkg.get('DCTERMS.Source.URI'), rel='dct:source', target='_blank') }} + {{ h.link_to(h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI'), + h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI'), rel='dct:source', target='_blank') }} {% endif %} @@ -67,11 +67,11 @@ {{ pkg.spatial_coverage }} {% endif %} - {% if pkg.get('Geospatial Coverage') %} + {% if h.get_pkg_dict_extra(pkg,'Geospatial Coverage') %} Geospatial Coverage - {{ pkg.get('Geospatial Coverage') }} + {{ h.get_pkg_dict_extra(pkg,'Geospatial Coverage') }} {% endif %} {% if pkg.get('granularity') %} @@ -81,11 +81,11 @@ {{ pkg.granularity }} {% endif %} - {% if pkg.get('Granularity') %} + {% if h.get_pkg_dict_extra(pkg,'Granularity') %} Data Granularity - {{ pkg.get('Granularity') }} + {{ h.get_pkg_dict_extra(pkg,'Granularity') }} {% endif %} {% if pkg.get('jurisdiction') %} @@ -95,11 +95,11 @@ {{ pkg.jurisdiction }} {% endif %} - {% if pkg.get('AGLSTERMS.Jurisdiction') %} + {% if h.get_pkg_dict_extra(pkg,'AGLSTERMS.Jurisdiction') %} Government Jurisdiction - {{ pkg.get('AGLSTERMS.Jurisdiction') }} + {{ h.get_pkg_dict_extra(pkg,'AGLSTERMS.Jurisdiction') }} {% endif %} {% if pkg.get('temporal_coverage') %} @@ -109,11 +109,11 @@ {{ pkg.temporal_coverage }} {% endif %} - {% if pkg.get('Temporal Coverage') %} + {% if h.get_pkg_dict_extra(pkg,'Temporal Coverage') %} Temporal Coverage - {{ pkg.get('Temporal Coverage') }} + {{ h.get_pkg_dict_extra(pkg,'Temporal Coverage') }} {% endif %} {% if pkg.get('data_state') %} @@ -130,26 +130,33 @@ {{ pkg.update_freq }} {% endif %} - {% if pkg.get('Update Frequency') %} + {% if h.get_pkg_dict_extra(pkg,'Update Frequency') %} Update Frequency - {{ pkg.get('Update Frequency') }} + {{ h.get_pkg_dict_extra(pkg,'Update Frequency') }} {% 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,27 +79,25 @@ ${ 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"]} + - - ${c.pkg_dict.get('DCTERMS.Source.URI') } + ${h.get_pkg_dict_extra(c.pkg_dict,'DCTERMS.Source.URI') } ${c.pkg_dict.contact_point } ${ c.pkg_dict.spatial_coverage } - ${ c.pkg_dict.get('Geospatial Coverage') } + ${ h.get_pkg_dict_extra(c.pkg_dict,'Geospatial Coverage') } ${ c.pkg_dict.jurisdiction } - ${ c.pkg_dict.get('AGLSTERMS.Jurisdiction') } - ${ c.pkg_dict.temporal_coverage } - ${ c.pkg_dict.get('Temporal Coverage') } + ${ h.get_pkg_dict_extra(c.pkg_dict,'AGLSTERMS.Jurisdiction') } + ${ c.pkg_dict.get('temporal_coverage') } + ${ h.get_pkg_dict_extra(c.pkg_dict,'Temporal Coverage') } Data State @@ -103,17 +111,17 @@ ${ c.pkg_dict.get('update_freq') } - + Update Frequency - ${ c.pkg_dict.get('Update Frequency') } + ${ h.get_pkg_dict_extra(c.pkg_dict,'Update Frequency') } - + Agency Program - ${ c.pkg_dict.get('Agency Program') } + ${ h.get_pkg_dict_extra(c.pkg_dict,'Agency Program') } @@ -123,10 +131,10 @@ - + Data Granularity - ${ c.pkg_dict.get('Granularity') } + ${ h.get_pkg_dict_extra(c.pkg_dict,'Granularity') } --- a/ckanext/datagovau/templates/package/read_base.html +++ b/ckanext/datagovau/templates/package/read_base.html @@ -14,11 +14,11 @@ -{% if pkg.get('DCTERMS.Source.URI') %}{% endif %} +{% if h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI') %}{% endif %} - - - + + + --- a/ckanext/datagovau/templates/package/resource_read.html +++ b/ckanext/datagovau/templates/package/resource_read.html @@ -14,11 +14,11 @@ -{% if pkg.get('DCTERMS.Source.URI') %}{% endif %} +{% if h.get_pkg_dict_extra(pkg,'DCTERMS.Source.URI') %}{% endif %} - - - + + +