From cf9b1980cd4afd49d3a7eea965042cd0cde1795e Mon Sep 17 00:00:00 2001 From: Tyler Kennedy Date: Wed, 19 Apr 2017 13:55:40 -0400 Subject: [PATCH] Activities are now just templates. Removes all _html 'helpers'. --- ckan/controllers/group.py | 25 +- ckan/controllers/package.py | 18 +- ckan/controllers/user.py | 38 ++- ckan/lib/activity_streams.py | 256 ------------------ ckan/lib/helpers.py | 10 +- ckan/logic/action/get.py | 121 +-------- ckan/templates/base.html | 2 +- ckan/templates/group/activity_stream.html | 10 +- .../organization/activity_stream.html | 10 +- ckan/templates/package/activity.html | 10 +- .../snippets/activities/added_tag.html | 14 + .../snippets/activities/changed_group.html | 13 + .../activities/changed_organization.html | 13 + .../snippets/activities/changed_package.html | 15 + .../snippets/activities/changed_resource.html | 14 + .../snippets/activities/changed_user.html | 12 + .../snippets/activities/deleted_group.html | 13 + .../activities/deleted_organization.html | 13 + .../snippets/activities/deleted_package.html | 13 + .../snippets/activities/deleted_resource.html | 14 + .../snippets/activities/follow_dataset.html | 13 + .../snippets/activities/follow_group.html | 13 + .../snippets/activities/follow_user.html | 13 + .../snippets/activities/new_group.html | 13 + .../snippets/activities/new_organization.html | 13 + .../snippets/activities/new_package.html | 15 + .../snippets/activities/new_resource.html | 14 + .../snippets/activities/new_user.html | 12 + .../snippets/activities/removed_tag.html | 14 + ckan/templates/snippets/activity_item.html | 10 - ckan/templates/snippets/activity_stream.html | 51 ++++ ckan/templates/user/activity_stream.html | 4 +- ckan/templates/user/dashboard.html | 4 +- 33 files changed, 386 insertions(+), 437 deletions(-) delete mode 100644 ckan/lib/activity_streams.py create mode 100644 ckan/templates/snippets/activities/added_tag.html create mode 100644 ckan/templates/snippets/activities/changed_group.html create mode 100644 ckan/templates/snippets/activities/changed_organization.html create mode 100644 ckan/templates/snippets/activities/changed_package.html create mode 100644 ckan/templates/snippets/activities/changed_resource.html create mode 100644 ckan/templates/snippets/activities/changed_user.html create mode 100644 ckan/templates/snippets/activities/deleted_group.html create mode 100644 ckan/templates/snippets/activities/deleted_organization.html create mode 100644 ckan/templates/snippets/activities/deleted_package.html create mode 100644 ckan/templates/snippets/activities/deleted_resource.html create mode 100644 ckan/templates/snippets/activities/follow_dataset.html create mode 100644 ckan/templates/snippets/activities/follow_group.html create mode 100644 ckan/templates/snippets/activities/follow_user.html create mode 100644 ckan/templates/snippets/activities/new_group.html create mode 100644 ckan/templates/snippets/activities/new_organization.html create mode 100644 ckan/templates/snippets/activities/new_package.html create mode 100644 ckan/templates/snippets/activities/new_resource.html create mode 100644 ckan/templates/snippets/activities/new_user.html create mode 100644 ckan/templates/snippets/activities/removed_tag.html delete mode 100644 ckan/templates/snippets/activity_item.html create mode 100644 ckan/templates/snippets/activity_stream.html diff --git a/ckan/controllers/group.py b/ckan/controllers/group.py index e711fea8561..776ee49a608 100644 --- a/ckan/controllers/group.py +++ b/ckan/controllers/group.py @@ -817,18 +817,19 @@ def activity(self, id, offset=0): except (NotFound, NotAuthorized): abort(404, _('Group not found')) - try: - # 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 = self._action('group_activity_list_html')( - context, {'id': c.group_dict['id'], 'offset': offset}) - - except ValidationError as error: - base.abort(400) - - return render(self._activity_template(group_type), - extra_vars={'group_type': group_type}) + return render( + self._activity_template(group_type), + extra_vars={ + 'group_type': group_type, + 'activity_stream': get_action('organization_activity_list')( + context, + { + 'id': c.group_dict['id'], + 'offset': offset + } + ) + } + ) def follow(self, id): '''Start following this group.''' diff --git a/ckan/controllers/package.py b/ckan/controllers/package.py index d57dee05e00..68d370c3056 100644 --- a/ckan/controllers/package.py +++ b/ckan/controllers/package.py @@ -1277,18 +1277,24 @@ def activity(self, id): data_dict = {'id': id} try: c.pkg_dict = get_action('package_show')(context, data_dict) - c.pkg = context['package'] - c.package_activity_stream = get_action( - 'package_activity_list_html')( - context, {'id': c.pkg_dict['id']}) dataset_type = c.pkg_dict['type'] or 'dataset' except NotFound: abort(404, _('Dataset not found')) except NotAuthorized: abort(403, _('Unauthorized to read dataset %s') % id) - return render('package/activity.html', - {'dataset_type': dataset_type}) + return render( + 'package/activity.html', + extra_vars={ + 'dataset_type': dataset_type, + 'activity_stream': get_action('package_activity_list')( + context, + { + 'id': id + } + ) + } + ) def resource_embedded_dataviewer(self, id, resource_id, width=500, height=500): diff --git a/ckan/controllers/user.py b/ckan/controllers/user.py index 4c622caf243..d5d0a0fcf2d 100644 --- a/ckan/controllers/user.py +++ b/ckan/controllers/user.py @@ -595,13 +595,18 @@ def activity(self, id, offset=0): self._setup_template_variables(context, data_dict) - try: - c.user_activity_stream = get_action('user_activity_list_html')( - context, {'id': c.user_dict['id'], 'offset': offset}) - except ValidationError: - base.abort(400) - - return render('user/activity_stream.html') + return render( + 'user/activity_stream.html', + extra_vars={ + 'activity_stream': get_action('user_activity_list')( + context, + { + 'id': id, + 'offset': offset + } + ) + } + ) def _get_dashboard_context(self, filter_type=None, filter_id=None, q=None): '''Return a dict needed by the dashboard view to determine context.''' @@ -668,10 +673,19 @@ def dashboard(self, id=None, offset=0): filter_id = request.params.get('name', u'') c.followee_list = get_action('followee_list')( - context, {'id': c.userobj.id, 'q': q}) + context, + { + 'id': c.userobj.id, + 'q': q + } + ) + c.dashboard_activity_stream_context = self._get_dashboard_context( - filter_type, filter_id, q) - c.dashboard_activity_stream = h.dashboard_activity_stream( + filter_type, + filter_id, + q + ) + dashboard_activity_stream = h.dashboard_activity_stream( c.userobj.id, filter_type, filter_id, offset ) @@ -679,7 +693,9 @@ def dashboard(self, id=None, offset=0): # dashboard page. get_action('dashboard_mark_activities_old')(context, {}) - return render('user/dashboard.html') + return render('user/dashboard.html', extra_vars={ + 'activity_stream': dashboard_activity_stream + }) def dashboard_datasets(self): context = {'for_view': True, 'user': c.user, diff --git a/ckan/lib/activity_streams.py b/ckan/lib/activity_streams.py deleted file mode 100644 index 481e7a696c7..00000000000 --- a/ckan/lib/activity_streams.py +++ /dev/null @@ -1,256 +0,0 @@ -# encoding: utf-8 - -import re - -from webhelpers.html import literal - -import ckan.lib.helpers as h -import ckan.lib.base as base -import ckan.logic as logic - -from ckan.common import _ - -# get_snippet_*() functions replace placeholders like {user}, {dataset}, etc. -# in activity strings with HTML representations of particular users, datasets, -# etc. - -def get_snippet_actor(activity, detail): - return literal('''%s''' - % (h.linked_user(activity['user_id'], 0, 30)) - ) - -def get_snippet_user(activity, detail): - return literal('''%s''' - % (h.linked_user(activity['object_id'], 0, 20)) - ) - -def get_snippet_dataset(activity, detail): - data = activity['data'] - pkg_dict = data.get('package') or data.get('dataset') - link = h.dataset_link(pkg_dict) if pkg_dict else '' - return literal('''%s''' - % (link) - ) - -def get_snippet_tag(activity, detail): - return h.tag_link(detail['data']['tag']) - -def get_snippet_group(activity, detail): - link = h.group_link(activity['data']['group']) - return literal('''%s''' - % (link) - ) - -def get_snippet_organization(activity, detail): - return h.organization_link(activity['data']['group']) - -def get_snippet_extra(activity, detail): - return '"%s"' % detail['data']['package_extra']['key'] - -def get_snippet_resource(activity, detail): - return h.resource_link(detail['data']['resource'], - activity['data']['package']['id']) - -# activity_stream_string_*() functions return translatable string -# representations of activity types, the strings contain placeholders like -# {user}, {dataset} etc. to be replaced with snippets from the get_snippet_*() -# functions above. - -def activity_stream_string_added_tag(context, activity): - return _("{actor} added the tag {tag} to the dataset {dataset}") - -def activity_stream_string_changed_group(context, activity): - return _("{actor} updated the group {group}") - -def activity_stream_string_changed_organization(context, activity): - return _("{actor} updated the organization {organization}") - -def activity_stream_string_changed_package(context, activity): - return _("{actor} updated the dataset {dataset}") - -def activity_stream_string_changed_package_extra(context, activity): - return _("{actor} changed the extra {extra} of the dataset {dataset}") - -def activity_stream_string_changed_resource(context, activity): - return _("{actor} updated the resource {resource} in the dataset {dataset}") - -def activity_stream_string_changed_user(context, activity): - return _("{actor} updated their profile") - -def activity_stream_string_deleted_group(context, activity): - return _("{actor} deleted the group {group}") - -def activity_stream_string_deleted_organization(context, activity): - return _("{actor} deleted the organization {organization}") - -def activity_stream_string_deleted_package(context, activity): - return _("{actor} deleted the dataset {dataset}") - -def activity_stream_string_deleted_package_extra(context, activity): - return _("{actor} deleted the extra {extra} from the dataset {dataset}") - -def activity_stream_string_deleted_resource(context, activity): - return _("{actor} deleted the resource {resource} from the dataset " - "{dataset}") - -def activity_stream_string_new_group(context, activity): - return _("{actor} created the group {group}") - -def activity_stream_string_new_organization(context, activity): - return _("{actor} created the organization {organization}") - -def activity_stream_string_new_package(context, activity): - return _("{actor} created the dataset {dataset}") - -def activity_stream_string_new_package_extra(context, activity): - return _("{actor} added the extra {extra} to the dataset {dataset}") - -def activity_stream_string_new_resource(context, activity): - return _("{actor} added the resource {resource} to the dataset {dataset}") - -def activity_stream_string_new_user(context, activity): - return _("{actor} signed up") - -def activity_stream_string_removed_tag(context, activity): - return _("{actor} removed the tag {tag} from the dataset {dataset}") - -def activity_stream_string_follow_dataset(context, activity): - return _("{actor} started following {dataset}") - -def activity_stream_string_follow_user(context, activity): - return _("{actor} started following {user}") - -def activity_stream_string_follow_group(context, activity): - return _("{actor} started following {group}") - -# A dictionary mapping activity snippets to functions that expand the snippets. -activity_snippet_functions = { - 'actor': get_snippet_actor, - 'user': get_snippet_user, - 'dataset': get_snippet_dataset, - 'tag': get_snippet_tag, - 'group': get_snippet_group, - 'organization': get_snippet_organization, - 'extra': get_snippet_extra, - 'resource': get_snippet_resource, -} - -# A dictionary mapping activity types to functions that return translatable -# string descriptions of the activity types. -activity_stream_string_functions = { - 'added tag': activity_stream_string_added_tag, - 'changed group': activity_stream_string_changed_group, - 'changed organization': activity_stream_string_changed_organization, - 'changed package': activity_stream_string_changed_package, - 'changed package_extra': activity_stream_string_changed_package_extra, - 'changed resource': activity_stream_string_changed_resource, - 'changed user': activity_stream_string_changed_user, - 'deleted group': activity_stream_string_deleted_group, - 'deleted organization': activity_stream_string_deleted_organization, - 'deleted package': activity_stream_string_deleted_package, - 'deleted package_extra': activity_stream_string_deleted_package_extra, - 'deleted resource': activity_stream_string_deleted_resource, - 'new group': activity_stream_string_new_group, - 'new organization': activity_stream_string_new_organization, - 'new package': activity_stream_string_new_package, - 'new package_extra': activity_stream_string_new_package_extra, - 'new resource': activity_stream_string_new_resource, - 'new user': activity_stream_string_new_user, - 'removed tag': activity_stream_string_removed_tag, - 'follow dataset': activity_stream_string_follow_dataset, - 'follow user': activity_stream_string_follow_user, - 'follow group': activity_stream_string_follow_group, -} - -# A dictionary mapping activity types to the icons associated to them -activity_stream_string_icons = { - 'added tag': 'tag', - 'changed group': 'users', - 'changed package': 'sitemap', - 'changed package_extra': 'pencil-square-o', - 'changed resource': 'file', - 'changed user': 'user', - 'deleted group': 'users', - 'deleted package': 'sitemap', - 'deleted package_extra': 'pencil-square-o', - 'deleted resource': 'file', - 'new group': 'users', - 'new package': 'sitemap', - 'new package_extra': 'pencil-square-o', - 'new resource': 'file', - 'new user': 'user', - 'removed tag': 'tag', - 'follow dataset': 'sitemap', - 'follow user': 'user', - 'follow group': 'users', - 'changed organization': 'briefcase', - 'deleted organization': 'briefcase', - 'new organization': 'briefcase', - 'undefined': 'certificate', # This is when no activity icon can be found -} - -# A list of activity types that may have details -activity_stream_actions_with_detail = ['changed package'] - -def activity_list_to_html(context, activity_stream, extra_vars): - '''Return the given activity stream as a snippet of HTML. - - :param activity_stream: the activity stream to render - :type activity_stream: list of activity dictionaries - :param extra_vars: extra variables to pass to the activity stream items - template when rendering it - :type extra_vars: dictionary - - :rtype: HTML-formatted string - - ''' - activity_list = [] # These are the activity stream messages. - for activity in activity_stream: - detail = None - activity_type = activity['activity_type'] - # Some activity types may have details. - if activity_type in activity_stream_actions_with_detail: - details = logic.get_action('activity_detail_list')(context=context, - data_dict={'id': activity['id']}) - # If an activity has just one activity detail then render the - # detail instead of the activity. - if len(details) == 1: - detail = details[0] - object_type = detail['object_type'] - - if object_type == 'PackageExtra': - object_type = 'package_extra' - - new_activity_type = '%s %s' % (detail['activity_type'], - object_type.lower()) - if new_activity_type in activity_stream_string_functions: - activity_type = new_activity_type - - if not activity_type in activity_stream_string_functions: - raise NotImplementedError("No activity renderer for activity " - "type '%s'" % activity_type) - - if activity_type in activity_stream_string_icons: - activity_icon = activity_stream_string_icons[activity_type] - else: - activity_icon = activity_stream_string_icons['undefined'] - - activity_msg = activity_stream_string_functions[activity_type](context, - activity) - - # Get the data needed to render the message. - matches = re.findall('\{([^}]*)\}', activity_msg) - data = {} - for match in matches: - snippet = activity_snippet_functions[match](activity, detail) - data[str(match)] = snippet - - activity_list.append({'msg': activity_msg, - 'type': activity_type.replace(' ', '-').lower(), - 'icon': activity_icon, - 'data': data, - 'timestamp': activity['timestamp'], - 'is_new': activity.get('is_new', False)}) - extra_vars['activities'] = activity_list - return literal(base.render('activity_streams/activity_stream_items.html', - extra_vars=extra_vars)) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 15b4fca89bc..a6c57b3f38c 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -1723,15 +1723,15 @@ def dashboard_activity_stream(user_id, filter_type=None, filter_id=None, if filter_type: action_functions = { - 'dataset': 'package_activity_list_html', - 'user': 'user_activity_list_html', - 'group': 'group_activity_list_html', - 'organization': 'organization_activity_list_html', + 'dataset': 'package_activity_list', + 'user': 'user_activity_list', + 'group': 'group_activity_list', + 'organization': 'organization_activity_list', } action_function = logic.get_action(action_functions.get(filter_type)) return action_function(context, {'id': filter_id, 'offset': offset}) else: - return logic.get_action('dashboard_activity_list_html')( + return logic.get_action('dashboard_activity_list')( context, {'offset': offset}) diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index d7b92a29e9a..ae272be811d 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -2637,10 +2637,12 @@ def organization_activity_list(context, data_dict): org_show = logic.get_action('organization_show') org_id = org_show(context, {'id': org_id})['id'] - _activity_objects = model.activity.group_activity_list(org_id, + activity_objects = model.activity.group_activity_list(org_id, limit=limit, offset=offset) + """ activity_objects = _filter_activity_by_user(_activity_objects, _activity_stream_get_filtered_users()) + """ return model_dictize.activity_list_dictize(activity_objects, context) @@ -2723,123 +2725,6 @@ def user_activity_list_html(context, data_dict): context, activity_stream, extra_vars) -def package_activity_list_html(context, data_dict): - '''Return a package's activity stream as HTML. - - The activity stream is rendered as a snippet of HTML meant to be included - in an HTML page, i.e. it doesn't have any HTML header or footer. - - :param id: the id or name of the package - :type id: string - :param offset: where to start getting activity items from - (optional, default: 0) - :type offset: int - :param limit: the maximum number of activities to return - (optional, default: 31, the default value is configurable via the - ckan.activity_list_limit setting) - :type limit: int - - :rtype: string - - ''' - activity_stream = package_activity_list(context, data_dict) - offset = int(data_dict.get('offset', 0)) - extra_vars = { - 'controller': 'package', - 'action': 'activity', - 'id': data_dict['id'], - 'offset': offset, - } - return activity_streams.activity_list_to_html( - context, activity_stream, extra_vars) - - -def group_activity_list_html(context, data_dict): - '''Return a group's activity stream as HTML. - - The activity stream is rendered as a snippet of HTML meant to be included - in an HTML page, i.e. it doesn't have any HTML header or footer. - - :param id: the id or name of the group - :type id: string - :param offset: where to start getting activity items from - (optional, default: 0) - :type offset: int - :param limit: the maximum number of activities to return - (optional, default: 31, the default value is configurable via the - ckan.activity_list_limit setting) - :type limit: int - - :rtype: string - - ''' - activity_stream = group_activity_list(context, data_dict) - offset = int(data_dict.get('offset', 0)) - extra_vars = { - 'controller': 'group', - 'action': 'activity', - 'id': data_dict['id'], - 'offset': offset, - } - return activity_streams.activity_list_to_html( - context, activity_stream, extra_vars) - - -def organization_activity_list_html(context, data_dict): - '''Return a organization's activity stream as HTML. - - The activity stream is rendered as a snippet of HTML meant to be included - in an HTML page, i.e. it doesn't have any HTML header or footer. - - :param id: the id or name of the organization - :type id: string - - :rtype: string - - ''' - activity_stream = organization_activity_list(context, data_dict) - offset = int(data_dict.get('offset', 0)) - extra_vars = { - 'controller': 'organization', - 'action': 'activity', - 'id': data_dict['id'], - 'offset': offset, - } - - return activity_streams.activity_list_to_html( - context, activity_stream, extra_vars) - - -def recently_changed_packages_activity_list_html(context, data_dict): - '''Return the activity stream of all recently changed packages as HTML. - - The activity stream includes all recently added or changed packages. It is - rendered as a snippet of HTML meant to be included in an HTML page, i.e. it - doesn't have any HTML header or footer. - - :param offset: where to start getting activity items from - (optional, default: 0) - :type offset: int - :param limit: the maximum number of activities to return - (optional, default: 31, the default value is configurable via the - ckan.activity_list_limit setting) - :type limit: int - - :rtype: string - - ''' - activity_stream = recently_changed_packages_activity_list( - context, data_dict) - offset = int(data_dict.get('offset', 0)) - extra_vars = { - 'controller': 'package', - 'action': 'activity', - 'offset': offset, - } - return activity_streams.activity_list_to_html( - context, activity_stream, extra_vars) - - def _follower_count(context, data_dict, default_schema, ModelClass): schema = context.get('schema', default_schema) data_dict, errors = _validate(data_dict, schema, context) diff --git a/ckan/templates/base.html b/ckan/templates/base.html index 2d13f4eb520..19236edd74d 100644 --- a/ckan/templates/base.html +++ b/ckan/templates/base.html @@ -68,7 +68,7 @@ {% endblock %} #} {%- block styles %} - {% resource g.main_css[6:] %} + {% resource g.main_css %} {% endblock %} {% block head_extras %} diff --git a/ckan/templates/group/activity_stream.html b/ckan/templates/group/activity_stream.html index 47a6d029bb4..3353b20bd20 100644 --- a/ckan/templates/group/activity_stream.html +++ b/ckan/templates/group/activity_stream.html @@ -3,8 +3,10 @@ {% block subtitle %}{{ _('Activity Stream') }} - {{ super() }}{% endblock %} {% block primary_content_inner %} -

{% block page_heading %}{{ _('Activity Stream') }}{% endblock %}

- {% block activity_stream %} - {{ c.group_activity_stream | safe }} - {% endblock %} +

+ {% block page_heading %} + {{ _('Activity Stream') }} + {% endblock %} +

+ {% snippet 'snippets/activity_stream.html', activity_stream=activity_stream %} {% endblock %} diff --git a/ckan/templates/organization/activity_stream.html b/ckan/templates/organization/activity_stream.html index ffa029d951b..d5ed8726153 100644 --- a/ckan/templates/organization/activity_stream.html +++ b/ckan/templates/organization/activity_stream.html @@ -3,8 +3,10 @@ {% block subtitle %}{{ _('Activity Stream') }} - {{ super() }}{% endblock %} {% block primary_content_inner %} -

{% block page_heading %}{{ _('Activity Stream') }}{% endblock %}

- {% block activity_stream %} - {{ c.group_activity_stream | safe }} - {% endblock %} +

+ {% block page_heading -%} + {{ _('Activity Stream') }} + {%- endblock %} +

+ {% snippet 'snippets/activity_stream.html', activity_stream=activity_stream %} {% endblock %} diff --git a/ckan/templates/package/activity.html b/ckan/templates/package/activity.html index 3941a6dda02..b54cf190c04 100644 --- a/ckan/templates/package/activity.html +++ b/ckan/templates/package/activity.html @@ -3,8 +3,10 @@ {% block subtitle %}{{ _('Activity Stream') }} - {{ super() }}{% endblock %} {% block primary_content_inner %} -

{% block page_heading %}{{ _('Activity Stream') }}{% endblock %}

- {% block activity_stream %} - {{ c.package_activity_stream | safe }} - {% endblock %} +

+ {% block page_heading %} + {{ _('Activity Stream') }} + {% endblock %} +

+ {% snippet 'snippets/activity_stream.html', activity_stream=activity_stream %} {% endblock %} diff --git a/ckan/templates/snippets/activities/added_tag.html b/ckan/templates/snippets/activities/added_tag.html new file mode 100644 index 00000000000..d9969d3c3f2 --- /dev/null +++ b/ckan/templates/snippets/activities/added_tag.html @@ -0,0 +1,14 @@ +
  • + +

    + {{ _('{actor} added the tag {tag} to the dataset {dataset}').format( + actor=ah.actor(activity), + dataset=ah.dataset(activity), + tag=ah.tag(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/changed_group.html b/ckan/templates/snippets/activities/changed_group.html new file mode 100644 index 00000000000..19825576639 --- /dev/null +++ b/ckan/templates/snippets/activities/changed_group.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} updated the group {group}').format( + actor=ah.actor(activity), + group=ah.group(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/changed_organization.html b/ckan/templates/snippets/activities/changed_organization.html new file mode 100644 index 00000000000..073f8047318 --- /dev/null +++ b/ckan/templates/snippets/activities/changed_organization.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} updated the organization {organization}').format( + actor=ah.actor(activity), + organization=ah.organization(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/changed_package.html b/ckan/templates/snippets/activities/changed_package.html new file mode 100644 index 00000000000..8d751afc7c7 --- /dev/null +++ b/ckan/templates/snippets/activities/changed_package.html @@ -0,0 +1,15 @@ +
  • + +

    + {{ _('{actor} updated the dataset {dataset}').format( + actor=ah.actor(activity), + dataset=ah.dataset(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} +  |  + {{ _('View this version') }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/changed_resource.html b/ckan/templates/snippets/activities/changed_resource.html new file mode 100644 index 00000000000..28192bb62ee --- /dev/null +++ b/ckan/templates/snippets/activities/changed_resource.html @@ -0,0 +1,14 @@ +
  • + +

    + {{ _('{actor} updated the resource {resource} in the dataset {dataset}').format( + actor=ah.actor(activity), + resource=ah.resource(activity), + dataset=ah.datset(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/changed_user.html b/ckan/templates/snippets/activities/changed_user.html new file mode 100644 index 00000000000..c4ea1aa2155 --- /dev/null +++ b/ckan/templates/snippets/activities/changed_user.html @@ -0,0 +1,12 @@ +
  • + +

    + {{ _('{actor} updated their profile').format( + actor=ah.actor(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/deleted_group.html b/ckan/templates/snippets/activities/deleted_group.html new file mode 100644 index 00000000000..bb5f92b3ae6 --- /dev/null +++ b/ckan/templates/snippets/activities/deleted_group.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} deleted the group {group}').format( + actor=ah.actor(activity), + group=ah.group(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/deleted_organization.html b/ckan/templates/snippets/activities/deleted_organization.html new file mode 100644 index 00000000000..27753e9151b --- /dev/null +++ b/ckan/templates/snippets/activities/deleted_organization.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} deleted the organization {organization}').format( + actor=ah.actor(activity), + organization=ah.organization(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/deleted_package.html b/ckan/templates/snippets/activities/deleted_package.html new file mode 100644 index 00000000000..5731125f177 --- /dev/null +++ b/ckan/templates/snippets/activities/deleted_package.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} deleted the dataset {dataset}').format( + actor=ah.actor(activity), + dataset=ah.dataset(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/deleted_resource.html b/ckan/templates/snippets/activities/deleted_resource.html new file mode 100644 index 00000000000..d78d21234b1 --- /dev/null +++ b/ckan/templates/snippets/activities/deleted_resource.html @@ -0,0 +1,14 @@ +
  • + +

    + {{ _('{actor} deleted the resource {resource} from the dataset {dataset}').format( + actor=ah.actor(activity), + resource=ah.resource(activity), + dataset=ah.dataset(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/follow_dataset.html b/ckan/templates/snippets/activities/follow_dataset.html new file mode 100644 index 00000000000..f4487e4fdc0 --- /dev/null +++ b/ckan/templates/snippets/activities/follow_dataset.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} started following {dataset}').format( + actor=ah.actor(activity), + dataset=ah.dataset(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/follow_group.html b/ckan/templates/snippets/activities/follow_group.html new file mode 100644 index 00000000000..30a4bb12447 --- /dev/null +++ b/ckan/templates/snippets/activities/follow_group.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} started following {group}').format( + actor=ah.actor(activity), + group=ah.group(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/follow_user.html b/ckan/templates/snippets/activities/follow_user.html new file mode 100644 index 00000000000..9259ee49079 --- /dev/null +++ b/ckan/templates/snippets/activities/follow_user.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} started following {user}').format( + actor=ah.actor(activity), + user=ah.user(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/new_group.html b/ckan/templates/snippets/activities/new_group.html new file mode 100644 index 00000000000..50601aba535 --- /dev/null +++ b/ckan/templates/snippets/activities/new_group.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} created the group {group}').format( + actor=ah.actor(activity), + group=ah.group(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/new_organization.html b/ckan/templates/snippets/activities/new_organization.html new file mode 100644 index 00000000000..ef191615f53 --- /dev/null +++ b/ckan/templates/snippets/activities/new_organization.html @@ -0,0 +1,13 @@ +
  • + +

    + {{ _('{actor} created the organization {organization}').format( + actor=ah.actor(activity), + organization=ah.organization(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/new_package.html b/ckan/templates/snippets/activities/new_package.html new file mode 100644 index 00000000000..a4738722f4a --- /dev/null +++ b/ckan/templates/snippets/activities/new_package.html @@ -0,0 +1,15 @@ +
  • + +

    + {{ _('{actor} created the dataset {dataset}').format( + actor=ah.actor(activity), + dataset=ah.dataset(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} +  |  + {{ _('View this version') }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/new_resource.html b/ckan/templates/snippets/activities/new_resource.html new file mode 100644 index 00000000000..d3f33c9882b --- /dev/null +++ b/ckan/templates/snippets/activities/new_resource.html @@ -0,0 +1,14 @@ +
  • + +

    + {{ _('{actor} added the resource {resource} to the dataset {dataset}').format( + actor=ah.actor(activity), + resource=ah.resource(activity), + dataset=ah.dataset(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/new_user.html b/ckan/templates/snippets/activities/new_user.html new file mode 100644 index 00000000000..1293f146c7b --- /dev/null +++ b/ckan/templates/snippets/activities/new_user.html @@ -0,0 +1,12 @@ +
  • + +

    + {{ _('{actor} signed up').format( + actor=ah.actor(activity) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activities/removed_tag.html b/ckan/templates/snippets/activities/removed_tag.html new file mode 100644 index 00000000000..00acfa15ff6 --- /dev/null +++ b/ckan/templates/snippets/activities/removed_tag.html @@ -0,0 +1,14 @@ +
  • + +

    + {{ _('{actor} removed the tag {tag} from the dataset {dataset}').format( + actor=ah.actor(activity), + tag=ah.tag(activity), + dataset=ah.dataset(dataset) + )|safe }} +
    + + {{ h.time_ago_from_timestamp(activity.timestamp) }} + +

    +
  • diff --git a/ckan/templates/snippets/activity_item.html b/ckan/templates/snippets/activity_item.html deleted file mode 100644 index 46619123479..00000000000 --- a/ckan/templates/snippets/activity_item.html +++ /dev/null @@ -1,10 +0,0 @@ -
  • - {% if activity.is_new %} - {{ _('New activity item') }} - {% endif %} - -

    - {{ h.literal(activity.msg.format(**activity.data)) }} - {{ h.time_ago_from_timestamp(activity.timestamp) }} -

    -
  • diff --git a/ckan/templates/snippets/activity_stream.html b/ckan/templates/snippets/activity_stream.html new file mode 100644 index 00000000000..8ea29f0f16f --- /dev/null +++ b/ckan/templates/snippets/activity_stream.html @@ -0,0 +1,51 @@ +{% macro actor(activity) %} + + {{ h.linked_user(activity.user_id, 0, 30) }} + +{% endmacro %} + +{% macro dataset(activity) %} + + {{ h.dataset_link(activity.data.package) }} + +{% endmacro %} + +{% macro organization(activity) %} +{{ h.organization_link(activity.data.group) }} +{% endmacro %} + +{% macro user(activity) %} + + {{ h.linked_user(activity.object_id, 0, 20) }} + +{% endmacro %} + +{% macro tag(activity) %} + + {{ h.tag_link(activity.data.tag) }} + +{% endmacro %} + +{% macro group(activity) %} + + {{ h.group_link(activity.data.group) }} + +{% endmacro %} + +{% block activity_stream %} + +{% endblock %} diff --git a/ckan/templates/user/activity_stream.html b/ckan/templates/user/activity_stream.html index 290d34d5fa6..6b7579c4426 100644 --- a/ckan/templates/user/activity_stream.html +++ b/ckan/templates/user/activity_stream.html @@ -4,7 +4,5 @@ {% block primary_content_inner %}

    {% block page_heading %}{{ _('Activity Stream') }}{% endblock %}

    - {% block activity_stream %} - {{ c.user_activity_stream | safe }} - {% endblock %} + {% snippet 'snippets/activity_stream.html', activity_stream=activity_stream %} {% endblock %} diff --git a/ckan/templates/user/dashboard.html b/ckan/templates/user/dashboard.html index dd6c346e6ec..0ec849a3b67 100644 --- a/ckan/templates/user/dashboard.html +++ b/ckan/templates/user/dashboard.html @@ -38,9 +38,7 @@

    {% endblock %} {{ _("Activity from items that I'm following") }}

    - {% block activity_stream %} - {{ c.dashboard_activity_stream }} - {% endblock %} + {% snippet 'snippets/activity_stream.html', activity_stream=activity_stream %} {% endblock %}