Skip to content

Commit

Permalink
[#1633] Add activity streams to dataset pages.
Browse files Browse the repository at this point in the history
They don't look particularly nice yet and there's no test for it yet,
but it works.

Add package_activity_list() and package_activity_list_html() logic
functions.

Package read controller calls package_activity_list_html() logic
function and adds the activity stream HTML to the template context.
Package read template retrieves the HTML and outputs it into the page.
  • Loading branch information
Sean Hammond committed Jan 13, 2012
1 parent 4764350 commit 2176131
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
10 changes: 9 additions & 1 deletion ckan/controllers/package.py
Expand Up @@ -29,6 +29,7 @@
import ckan.authz
import ckan.rating
import ckan.misc
import ckan.logic.action.get

log = logging.getLogger('ckan.controllers')

Expand Down Expand Up @@ -215,7 +216,14 @@ def read(self, id):

# used by disqus plugin
c.current_package_id = c.pkg.id


# Add the package's activity stream (already rendered to HTML) to the
# template context for the package/read.html template to retrieve
# later.
c.package_activity_stream = \
ckan.logic.action.get.package_activity_list_html(context,
{'id': c.current_package_id})

if config.get('rdf_packages'):
accept_header = request.headers.get('Accept', '*/*')
for content_type, exts in negotiate(autoneg_cfg, accept_header):
Expand Down
37 changes: 29 additions & 8 deletions ckan/logic/action/get.py
Expand Up @@ -864,6 +864,14 @@ def user_activity_list(context, data_dict):
model.activity.Activity).filter_by(user_id=user_id).all()
return activity_list_dictize(activity_objects, context)

def package_activity_list(context, data_dict):
'''Return a package's public activity stream as a list of dicts.'''
model = context['model']
package_id = data_dict['id']
activity_objects = model.Session.query(
model.activity.Activity).filter_by(object_id=package_id).all()
return activity_list_dictize(activity_objects, context)

def activity_detail_list(context, data_dict):
'''Return an activity's list of activity detail items, as a list of dicts.
Expand Down Expand Up @@ -934,14 +942,7 @@ def render_changed_group_activity(context, activity):
'changed group' : render_changed_group_activity,
}

def user_activity_list_html(context, data_dict):
'''Return an HTML rendering of a user's public activity stream.
The activity stream is rendered as a snippet of HTML meant to be included
in an HTML page.
'''
activity_stream = user_activity_list(context, data_dict)
def _activity_list_to_html(context, activity_stream):
html = []
for activity in reversed(activity_stream):
activity_type = activity['activity_type']
Expand All @@ -950,3 +951,23 @@ def user_activity_list_html(context, data_dict):
"type '%s'" % str(activity_type))
html.append(activity_renderers[activity_type](context, activity))
return literal('\n'.join(html))

def user_activity_list_html(context, data_dict):
'''Return an HTML rendering of a user's public activity stream.
The activity stream is rendered as a snippet of HTML meant to be included
in an HTML page.
'''
activity_stream = user_activity_list(context, data_dict)
return _activity_list_to_html(context, activity_stream)

def package_activity_list_html(context, data_dict):
'''Return an HTML rendering of a package's public activity stream.
The activity stream is rendered as a snippet of HTML meant to be included
in an HTML page.
'''
activity_stream = package_activity_list(context, data_dict)
return _activity_list_to_html(context, activity_stream)
5 changes: 5 additions & 0 deletions ckan/templates/package/read.html
Expand Up @@ -69,6 +69,11 @@ <h3>Related Datasets</h3>
</ul>
</li>

<li class="sidebar-section">
<h3>Activity</h3>
${c.package_activity_stream}
</li>

<!-- <py:if test="not(c.pkg.isopen() and c.pkg.resources)"> -->
<!-- <h3 i18n:msg="">This dataset is Not Open</h3> -->
<!-- <p>Either because it is not openly licensed or is missing -->
Expand Down

0 comments on commit 2176131

Please sign in to comment.