Skip to content

Commit

Permalink
Add package extras activities
Browse files Browse the repository at this point in the history
Adds activity stream events of the form:

USER added/updated/deleted the extra "EXTRA" to/in/from the dataset DATASET
  • Loading branch information
Sean Hammond committed Feb 2, 2012
1 parent f3a4c77 commit 21ecae9
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -939,10 +939,26 @@ def render_removed_tag_activity(context, activity, detail):
return render('activity_streams/removed_tag.html',
extra_vars = {'activity': activity, 'detail': detail})

def render_new_package_extra_activity(context, activity, detail):
return render('activity_streams/new_package_extra.html',
extra_vars = {'activity': activity, 'detail': detail})

def render_changed_package_extra_activity(context, activity, detail):
return render('activity_streams/changed_package_extra.html',
extra_vars = {'activity': activity, 'detail': detail})

def render_deleted_package_extra_activity(context, activity, detail):
return render('activity_streams/deleted_package_extra.html',
extra_vars = {'activity': activity, 'detail': detail})

def render_changed_package_activity(context, activity):
details = activity_detail_list(context=context,
data_dict={'id': activity['id']})

if len(details) == 1:
# If an activity has only one activity detail we try to find an
# activity detail renderer to use instead of rendering the normal
# 'changed package' template.
detail = details[0]
activity_detail_renderers = {
'Resource': {
Expand All @@ -954,14 +970,19 @@ def render_changed_package_activity(context, activity):
'added': render_added_tag_activity,
'removed': render_removed_tag_activity,
},
'PackageExtra': {
'new': render_new_package_extra_activity,
'changed': render_changed_package_extra_activity,
'deleted': render_deleted_package_extra_activity
},
}
object_type = detail['object_type']
if activity_detail_renderers.has_key(object_type):
activity_type = detail['activity_type']
if activity_detail_renderers[object_type].has_key(activity_type):
renderer = activity_detail_renderers[object_type][activity_type]
return renderer(context, activity, detail)

return render('activity_streams/changed_package.html',
extra_vars = {'activity': activity})

Expand Down Expand Up @@ -1005,7 +1026,8 @@ def _activity_list_to_html(context, activity_stream):
if not activity_renderers.has_key(activity_type):
raise NotImplementedError, ("No activity renderer for activity "
"type '%s'" % str(activity_type))
html.append(activity_renderers[activity_type](context, activity))
activity_html = activity_renderers[activity_type](context, activity)
html.append(activity_html)
return literal('\n'.join(html))

def user_activity_list_html(context, data_dict):
Expand Down
17 changes: 17 additions & 0 deletions ckan/model/package_extra.py
Expand Up @@ -28,6 +28,23 @@ class PackageExtra(vdm.sqlalchemy.RevisionedObjectMixin,
def related_packages(self):
return [self.package]

def activity_stream_detail(self, activity_id, activity_type):
import ckan.model as model
import ckan.model.activity as activity
import ckan.lib.dictization

# Handle 'deleted' extras.
# When the user marks an extra as deleted this comes through here as a
# 'changed' extra. We detect this and change it to a 'deleted'
# activity.
if activity_type == 'changed' and self.state == u'deleted':
activity_type = 'deleted'

data_dict = ckan.lib.dictization.table_dictize(self,
context={'model': model})
return activity.ActivityDetail(activity_id, self.id, u"PackageExtra",
activity_type, {'package_extra': data_dict})

mapper(PackageExtra, package_extra_table, properties={
'package': orm.relation(Package,
backref=orm.backref('_extras',
Expand Down
21 changes: 21 additions & 0 deletions ckan/templates/activity_streams/changed_package_extra.html
@@ -0,0 +1,21 @@
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">changed</span>
the extra "${detail.data.package_extra.key}"
in the dataset ${package_summary(activity.data.package)}<br/>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
<div style="color:#999;">
${h.markdown_extract(activity.data.package.notes)}
</div>
</div>
</html>
21 changes: 21 additions & 0 deletions ckan/templates/activity_streams/deleted_package_extra.html
@@ -0,0 +1,21 @@
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">deleted</span>
the extra "${detail.data.package_extra.key}"
from the dataset ${package_summary(activity.data.package)}<br/>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
<div style="color:#999;">
${h.markdown_extract(activity.data.package.notes)}
</div>
</div>
</html>
21 changes: 21 additions & 0 deletions ckan/templates/activity_streams/new_package_extra.html
@@ -0,0 +1,21 @@
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">added</span>
the extra "${detail.data.package_extra.key}"
to the dataset ${package_summary(activity.data.package)}<br/>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
<div style="color:#999;">
${h.markdown_extract(activity.data.package.notes)}
</div>
</div>
</html>

0 comments on commit 21ecae9

Please sign in to comment.