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
@@ -137,19 +137,26 @@
</tr>
{% endif %}
- {% if pkg.maintainer_email %}
+{% set email =h.get_last_active_user(c.pkg_dict['id']).get('email','') %}
<tr>
<th scope="row" class="dataset-label">{{ _('Maintainer') }}</th>
<td class="dataset-details" property="dc:contributor">{{
- 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",'')) }}
</td>
</tr>
- {% elif pkg.maintainer %}
<tr>
- <th scope="row" class="dataset-label">{{ _('Maintainer') }}</th>
- <td class="dataset-details" property="dc:contributor">{{ pkg.maintainer }}</td>
+ <th scope="row" class="dataset-label">Publisher/Agency</th>
+ <td class="dataset-details" property="dc:publisher">{{ c.pkg_dict['organization']['title']}}
+ </td>
</tr>
- {% endif %}
+ <tr>
+ <th scope="row" class="dataset-label">Type</th>
+ <td class="dataset-details" property="dc:type">Dataset</td>
+ </tr>
+ <tr>
+ <th scope="row" class="dataset-label">Language</th>
+ <td class="dataset-details" property="dc:language">English</td>
+ </tr>
</tbody>
</table>
--- a/ckanext/datagovau/templates/package/read.rdf
+++ b/ckanext/datagovau/templates/package/read.rdf
@@ -24,7 +24,17 @@
<dct:issued>${c.pkg_dict['metadata_created']}</dct:issued>
<dct:modified>${c.pkg_dict['metadata_modified']}</dct:modified>
<dct:language>en</dct:language>
+
+<py:choose>
+ <py:when test="c.pkg_dict.get('license_url',None)">
<dct:license>${c.pkg_dict['license_url']}</dct:license>
+ <dct:rights rdf:resource="${c.pkg_dict['license_url']}"/>
+ </py:when>
+ <py:otherwise>
+ <dct:license>${c.pkg_dict['license_id']}</dct:license>
+ <dct:rights rdf:resource="${c.pkg_dict['license_id']}"/>
+ </py:otherwise>
+</py:choose>
<py:for each="tag_dict in c.pkg_dict.get('tags',[])">
<dcat:keyword>${ tag_dict["name"] }</dcat:keyword>
</py:for>
@@ -69,16 +79,14 @@
<foaf:name>${ c.pkg_dict['organization']['title'] }</foaf:name>
</rdf:Description>
</dct:creator>
- <dct:contributor
- py:with="username = h.get_action('package_activity_list',{'id':c.pkg_dict['id']})[0]['user_id']">
+ <dct:contributor>
<rdf:Description>
- <foaf:name>${h.get_action("user_show",{"id":username})["display_name"]}</foaf:name>
- <foaf:mbox py:if="h.get_action('user_show',{'id':username}).get('email', None)"
- rdf:resource="mailto:${h.get_action('user_show',{'id':username})['email']}"/>
+ <foaf:name>${h.get_last_active_user(c.pkg_dict['id'])["display_name"]}</foaf:name>
+ <foaf:mbox py:if="h.get_last_active_user(c.pkg_dict['id']).get('email', None)"
+ rdf:resource="mailto:${h.get_last_active_user(c.pkg_dict['id'])['email']}"/>
</rdf:Description>
</dct:contributor>
- <dct:rights py:if="c.pkg_dict.get('license_url', None)" rdf:resource="${c.pkg_dict['license_url']}"/>
<foaf:homepage py:if="h.get_pkg_dict_extra(c.pkg_dict,'DCTERMS.Source.URI')">${h.get_pkg_dict_extra(c.pkg_dict,'DCTERMS.Source.URI') }
</foaf:homepage>