Move selection logic from template to view

Required adding some extra data to the dict directly.
In theory this should produce better performance.
This commit is contained in:
Tom Price
2015-05-26 00:20:09 +01:00
parent 155eb29dfa
commit 644c12bc55
2 changed files with 15 additions and 10 deletions

View File

@@ -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