Skip to content

Commit

Permalink
Make recently_changed_packages_activity_stream a helper
Browse files Browse the repository at this point in the history
recently_changed_packages_activity_stream was an @Property of the
HomeController, but it wasn't working, accessing the property just
returned a property object e.g. <property object at 0x7f7210087e68> not
the HTML string as desired.

I think this is because the @Property was declared inside a method, and
properties only work at class-level.

The @Property cannot simply be moved to class level because it uses
`context`, a param of the index() function it was defined in.

Instead move recently_changed_packages_activity_stream into helpers.py,
where any template (not just the front page) can access it like this:

    {{ h.recently_changed_packages_activity_stream() }}

dashboard_activity_stream is already done the same way (but other
activity streams are not).

This means any existing home/index.html templates that were accessing
recently_changed_packages_activity_stream as an attribute of the
template context itself, will no longer work. However, apparently they
weren't working anyway.
  • Loading branch information
Sean Hammond authored and tobes committed Dec 11, 2012
1 parent f67a1c7 commit 1daea39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 0 additions & 5 deletions ckan/controllers/home.py
Expand Up @@ -104,11 +104,6 @@ def index(self):
if msg:
h.flash_notice(msg, allow_html=True)

@property
def recently_changed_packages_activity_stream():
return ckan.logic.action.get.recently_changed_packages_activity_list_html(context, {})
c.recently_changed_packages_activity_stream = recently_changed_packages_activity_stream

# START OF DIRTYNESS
def get_group(id):
def _get_group_type(id):
Expand Down
8 changes: 8 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -1190,6 +1190,13 @@ def dashboard_activity_stream(user_id):
{'id': user_id})


def recently_changed_packages_activity_stream():
import ckan.logic as logic
context = {'model': model, 'session': model.Session, 'user': c.user}
return logic.get_action('recently_changed_packages_activity_list_html')(
context, {})


def escape_js(str_to_escape):
'''Escapes special characters from a JS string.
Expand Down Expand Up @@ -1381,6 +1388,7 @@ def resource_preview(resource, pkg_id):
'add_url_param',
'groups_available',
'dashboard_activity_stream',
'recently_changed_packages_activity_stream',
'escape_js',
'get_pkg_dict_extra',
'get_request_param',
Expand Down

0 comments on commit 1daea39

Please sign in to comment.