Skip to content

Commit

Permalink
Tidy up activity streams templates
Browse files Browse the repository at this point in the history
Remove HTML/CSS code repetition, make more consistent.

All activities are rendered using an activity_stream_event macro in
_util.html.

The macro has CSS classes instead of inline styles.

Also added a couple of helper functions that I needed.
  • Loading branch information
Sean Hammond committed Feb 2, 2012
1 parent bf5238e commit f14ea0f
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 186 deletions.
7 changes: 7 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -345,3 +345,10 @@ def resource_link(resource_dict, package_id):
resource_id=resource_dict['id'])
return link_to(text, url)

def tag_link(tag):
url = url_for(controller='tag', action='read', id=tag['name'])
return link_to(tag['name'], url)

def group_link(group):
url = url_for(controller='group', action='read', id=group['name'])
return link_to(group['name'], url)
19 changes: 19 additions & 0 deletions ckan/templates/_util.html
Expand Up @@ -451,4 +451,23 @@
</tr>
</table>

<div py:def="activity_stream_event(subject, verb, object=None)">
<span class="activity_stream_event_subject">
${subject}
</span>
<span class="activity_stream_event_verb">
${verb}
</span>
<py:choose>
<span class="activity_stream_event_object" py:when="object">
${object}
</span>
<py:otherwise>
</py:otherwise>
</py:choose>
<span class="activity_stream_event_date">
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</span>
</div>

</html>
21 changes: 7 additions & 14 deletions ckan/templates/activity_streams/added_tag.html
Expand Up @@ -6,18 +6,11 @@
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 tag
<a href="${h.url_for(controller='tag', action='read',
id=detail.data.tag.name)}">
${detail.data.tag.name}
</a>
to the dataset
${package_summary(detail.data.package)}
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
</div>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='added',
object=("the tag "+h.tag_link(detail.data.tag)+
" to the dataset "+h.dataset_link(detail.data.package)),
activity=activity
)}
</html>
20 changes: 6 additions & 14 deletions ckan/templates/activity_streams/changed_group.html
Expand Up @@ -6,18 +6,10 @@
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">updated</span>
the group
<a href="${h.url_for(controller='group', action='read', id=activity.data.group.name)}">
${activity.data.group.name}
</a>
<div style="color:#999;">
${h.truncate(activity.data.group.description, length=80, whole_word=True)}
</div>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
</div>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='updated',
object="the group "+h.group_link(activity.data.group),
activity=activity
)}
</html>
17 changes: 5 additions & 12 deletions ckan/templates/activity_streams/changed_package.html
Expand Up @@ -6,16 +6,9 @@
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">updated</span>
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='updated',
object="the dataset "+h.dataset_link(activity.data.package),
activity=activity)}
</html>
19 changes: 7 additions & 12 deletions ckan/templates/activity_streams/changed_package_extra.html
Expand Up @@ -6,16 +6,11 @@
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='changed',
object=('the extra "'+detail.data.package_extra.key+'" of the dataset '
+h.dataset_link(activity.data.package)),
activity=activity
)}
</html>
20 changes: 8 additions & 12 deletions ckan/templates/activity_streams/changed_resource.html
Expand Up @@ -6,16 +6,12 @@
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">updated</span>
the resource ${resource_summary(activity.data.package, detail.data.resource)}
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='updated',
object=('the resource '+h.resource_link(detail.data.resource,
activity.data.package.id)+' in the dataset '
+h.dataset_link(activity.data.package)),
activity=activity
)}
</html>
12 changes: 5 additions & 7 deletions ckan/templates/activity_streams/changed_user.html
Expand Up @@ -6,11 +6,9 @@
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">updated their profile</span>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
</div>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='updated their profile.',
activity=activity
)}
</html>
17 changes: 6 additions & 11 deletions ckan/templates/activity_streams/deleted_group.html
Expand Up @@ -6,15 +6,10 @@
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 group ${activity.data.group.name}
<div style="color:#999;">
${h.truncate(activity.data.group.description, length=80, whole_word=True)}
</div>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
</div>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='deleted',
object="the group "+h.group_link(activity.data.group),
activity=activity
)}
</html>
17 changes: 5 additions & 12 deletions ckan/templates/activity_streams/deleted_package.html
Expand Up @@ -6,16 +6,9 @@
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 dataset
${activity.data.package.name} - ${activity.data.package.title}
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
<div style="color:#999;">
${h.markdown_extract(activity.data.package.notes)}
</div>
</div>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='updated',
object="the dataset "+h.dataset_link(activity.data.package),
activity=activity)}
</html>
19 changes: 7 additions & 12 deletions ckan/templates/activity_streams/deleted_package_extra.html
Expand Up @@ -6,16 +6,11 @@
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='deleted',
object=('the extra "'+detail.data.package_extra.key+'" from the dataset '
+h.dataset_link(activity.data.package)),
activity=activity
)}
</html>
20 changes: 8 additions & 12 deletions ckan/templates/activity_streams/deleted_resource.html
Expand Up @@ -6,16 +6,12 @@
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 resource ${h.resource_display_name(detail.data.resource)}
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='deleted',
object=('the resource '+h.resource_link(detail.data.resource,
activity.data.package.id)+' from the dataset '
+h.dataset_link(activity.data.package)),
activity=activity
)}
</html>
17 changes: 6 additions & 11 deletions ckan/templates/activity_streams/new_group.html
Expand Up @@ -6,15 +6,10 @@
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">created</span>
the group
<a href="${h.url_for(controller='group', action='read', id=activity.data.group.name)}">
${activity.data.group.name}
</a>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
</div>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='created',
object="the group "+h.group_link(activity.data.group),
activity=activity
)}
</html>
17 changes: 5 additions & 12 deletions ckan/templates/activity_streams/new_package.html
Expand Up @@ -6,16 +6,9 @@
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">created</span>
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='created',
object="the dataset "+h.dataset_link(activity.data.package),
activity=activity)}
</html>
19 changes: 7 additions & 12 deletions ckan/templates/activity_streams/new_package_extra.html
Expand Up @@ -6,16 +6,11 @@
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='added',
object=('the extra "'+detail.data.package_extra.key+'" to the dataset '
+h.dataset_link(activity.data.package)),
activity=activity
)}
</html>
20 changes: 8 additions & 12 deletions ckan/templates/activity_streams/new_resource.html
Expand Up @@ -6,16 +6,12 @@
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 resource ${resource_summary(activity.data.package, detail.data.resource)}
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>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='added',
object=('the resource '+h.resource_link(detail.data.resource,
activity.data.package.id)+' to the dataset '
+h.dataset_link(activity.data.package)),
activity=activity
)}
</html>
12 changes: 5 additions & 7 deletions ckan/templates/activity_streams/new_user.html
Expand Up @@ -6,11 +6,9 @@
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">signed up</span>
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
</div>
${activity_stream_event(
subject=h.linked_user(activity.user_id),
verb='signed up.',
activity=activity
)}
</html>

0 comments on commit f14ea0f

Please sign in to comment.