Skip to content

Commit

Permalink
[#1633] Add activity streams to group pages
Browse files Browse the repository at this point in the history
Still needs a unit test and to look nicer
  • Loading branch information
Sean Hammond committed Jan 13, 2012
1 parent 2176131 commit e84a302
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ckan/controllers/group.py
Expand Up @@ -16,6 +16,7 @@
from ckan.logic import tuplize_dict, clean_dict, parse_params
from ckan.lib.dictization.model_dictize import package_dictize
import ckan.forms
import ckan.logic.action.get

class GroupController(BaseController):

Expand Down Expand Up @@ -110,6 +111,12 @@ def read(self, id):
for pkg_rev in c.page.items:
result.append(package_dictize(pkg_rev, context))
c.page.items = result

# Add the group's activity stream (already rendered to HTML) to the
# template context for the group/read.html template to retrieve later.
c.group_activity_stream = \
ckan.logic.action.get.group_activity_list_html(context,
{'id': c.group_dict['id']})

return render('group/read.html')

Expand Down
18 changes: 18 additions & 0 deletions ckan/logic/action/get.py
Expand Up @@ -872,6 +872,14 @@ def package_activity_list(context, data_dict):
model.activity.Activity).filter_by(object_id=package_id).all()
return activity_list_dictize(activity_objects, context)

def group_activity_list(context, data_dict):
'''Return a group's public activity stream as a list of dicts.'''
model = context['model']
group_id = data_dict['id']
activity_objects = model.Session.query(
model.activity.Activity).filter_by(object_id=group_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 @@ -971,3 +979,13 @@ def package_activity_list_html(context, data_dict):
'''
activity_stream = package_activity_list(context, data_dict)
return _activity_list_to_html(context, activity_stream)

def group_activity_list_html(context, data_dict):
'''Return an HTML rendering of a group's public activity stream.
The activity stream is rendered as a snippet of HTML meant to be included
in an HTML page.
'''
activity_stream = group_activity_list(context, data_dict)
return _activity_list_to_html(context, activity_stream)
4 changes: 4 additions & 0 deletions ckan/templates/group/read.html
Expand Up @@ -18,6 +18,10 @@ <h3>Administrators</h3>
</ul>
</li>
</py:if>
<li>
<h3>Activity</h3>
${c.group_activity_stream}
</li>
</ul>
</li>
</py:match>
Expand Down

0 comments on commit e84a302

Please sign in to comment.