From 1eb7ea118119cd415634e18e186701c85732398d Mon Sep 17 00:00:00 2001 From: Tom Price Date: Tue, 26 May 2015 00:20:09 +0100 Subject: [PATCH] Move selection logic from template to view Required adding some extra data to the dict directly. In theory this should produce better performance. --- RIGS/templates/RIGS/activity_feed_data.html | 6 ++---- RIGS/versioning.py | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/RIGS/templates/RIGS/activity_feed_data.html b/RIGS/templates/RIGS/activity_feed_data.html index 7b335bf1..d4210ebf 100644 --- a/RIGS/templates/RIGS/activity_feed_data.html +++ b/RIGS/templates/RIGS/activity_feed_data.html @@ -9,10 +9,9 @@
{% for version in object_list %} - {% if version.item_changes or version.field_changes or version.old == None %} {% ifchanged version.revision.user %} - {% if version != object_list|first %} + {% if not forloop.first %}
{#/.media-body#}
{#/.media#} @@ -38,8 +37,7 @@ {% include 'RIGS/object_button.html' with object=version.new %}

- - {% endif %} + {% endfor %} diff --git a/RIGS/versioning.py b/RIGS/versioning.py index 0d87bfa4..54522b6d 100644 --- a/RIGS/versioning.py +++ b/RIGS/versioning.py @@ -128,11 +128,17 @@ def get_changes_for_version(newVersion, oldVersion=None): modelClass = newVersion.content_type.model_class() - compare = {} - compare['revision'] = newVersion.revision - compare['new'] = newVersion.object_version.object - compare['current'] = modelClass.objects.filter(pk=compare['new'].pk).first() - compare['version'] = newVersion + compare = { + 'revision': newVersion.revision, + 'new': newVersion.object_version.object, + 'current': modelClass.objects.filter(pk=newVersion.pk).first(), + 'version': newVersion, + + # Old things that may not be used + 'old': None, + 'field_changes': None, + 'item_changes': None, + } if oldVersion: compare['old'] = oldVersion.object_version.object @@ -219,7 +225,8 @@ class ActivityFeed(generic.ListView): for thisVersion in context['object_list']: thisItem = get_changes_for_version(thisVersion, None) - items.append(thisItem) + if thisItem['item_changes'] or thisItem['field_changes'] or thisItem['old'] == None: + items.append(thisItem) context ['object_list'] = items