From 0eb9317fc29040ef0690a283ed6696ae715d0d66 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sat, 23 May 2015 04:53:17 +0100 Subject: [PATCH] More UI stuff, and pagination on activity stream --- RIGS/templates/RIGS/activity_stream.html | 86 +++++++++++-------- .../templates/RIGS/event_version_changes.html | 4 +- RIGS/templates/RIGS/event_version_list.html | 8 +- RIGS/versioning.py | 38 ++++---- 4 files changed, 80 insertions(+), 56 deletions(-) diff --git a/RIGS/templates/RIGS/activity_stream.html b/RIGS/templates/RIGS/activity_stream.html index 6c0fabc4..bd4e5167 100644 --- a/RIGS/templates/RIGS/activity_stream.html +++ b/RIGS/templates/RIGS/activity_stream.html @@ -1,5 +1,6 @@ {% extends request.is_ajax|yesno:"base_ajax.html,base.html" %} {% load static %} +{% load paginator from filters %} {% block title %}Rigboard Activity Stream{% endblock %} @@ -40,48 +41,62 @@ {% endblock %} {% block content %} -{# comment "table view" #} +
+
+
+

Rigboard Activity Stream

+
+
{% paginator %}
+
+
-

Rigboard Activity Stream - Table View

-
- - - - - - - - - - - - {% for version in object_list %} - {% if version.item_changes or version.field_changes or version.old == None%} - - - - - - - - {% endif %} - {% endfor %} +
DateEventVersion IDUserChanges
{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}N{{ version.new.pk|stringformat:"05d" }}{{ version.version.pk }}|{{ version.revision.pk }}{{ version.revision.user.name }} - {% if version.old == None %} - Event Created - {% else %} - {% include 'RIGS/event_version_changes.html' %} - {% endif %}
+ + + + + + + + + + + {% for version in object_list %} + + + + + + + + + + {% endfor %} + + +
DateEventVersion IDUserChanges
{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}N{{ version.new.pk|stringformat:"05d" }}{{ version.version.pk }}|{{ version.revision.pk }}{{ version.revision.user.name }} + {% if version.old == None %} + Event Created + {% else %} + {% include 'RIGS/event_version_changes.html' %} + {% endif %}
+ +
+
{% paginator %}
+
- - -{# endcomment #}

-

Rigboard Activity Stream - Stream View

+

Rigboard Activity Stream - Scrollable Stream View
Possibly to go on homepage


+
{% for version in object_list %} {% if version.item_changes or version.field_changes or version.old == None %}
@@ -97,9 +112,8 @@
{% endif %} {% endfor %} - +
- {{ thediff }} {% endblock %} \ No newline at end of file diff --git a/RIGS/templates/RIGS/event_version_changes.html b/RIGS/templates/RIGS/event_version_changes.html index 910c7382..9f116fd7 100644 --- a/RIGS/templates/RIGS/event_version_changes.html +++ b/RIGS/templates/RIGS/event_version_changes.html @@ -10,7 +10,7 @@ {% endfor %} {% for itemChange in version.item_changes %} - + '>item '{{ itemChange.new.name|default:itemChange.old.name }}' {% endfor %} \ No newline at end of file diff --git a/RIGS/templates/RIGS/event_version_list.html b/RIGS/templates/RIGS/event_version_list.html index db4299ea..1e110b36 100644 --- a/RIGS/templates/RIGS/event_version_list.html +++ b/RIGS/templates/RIGS/event_version_list.html @@ -8,8 +8,12 @@ {% endblock %} diff --git a/RIGS/versioning.py b/RIGS/versioning.py index 49cd0ae0..13763a2a 100644 --- a/RIGS/versioning.py +++ b/RIGS/versioning.py @@ -14,6 +14,7 @@ import reversion import simplejson from reversion.models import Version from django.contrib.contenttypes.models import ContentType # Used to lookup the content_type +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from RIGS import models, forms import datetime @@ -85,8 +86,8 @@ def compare_event_items(old, new): changes = [] for (_, compare) in item_dict.items(): - if compare.old != compare.new: # has it changed at all (or been created/deleted) - compare.changes = model_compare(compare.old, compare.new, ['id','event','order']) # see what's changed + compare.changes = model_compare(compare.old, compare.new, ['id','event','order']) # see what's changed + if len(compare.changes) >= 1: changes.append(compare) # transfer into a sequential array to make it easier to deal with later return changes @@ -95,7 +96,7 @@ def get_versions_for_model(model): content_type = ContentType.objects.get_for_model(model) versions = reversion.models.Version.objects.filter( content_type = content_type, - ).select_related("revision").order_by("-pk") + ).select_related("revision","revision.version_set").order_by("-pk") return versions @@ -105,12 +106,12 @@ def get_previous_version(version): versions = reversion.get_for_object_reference(models.Event, thisEventId) - previousVersions = versions.filter(pk__lt=thisVersionId) + try: + previousVersions = versions.filter(pk__lt=thisVersionId).latest(field_name='pk') # this is very slow :( + except: + return False - if len(previousVersions) >= 1: - return previousVersions[0] - else: #this is probably the initial version - return False + return previousVersions def get_changes_for_version(newVersion, oldVersion=None): #Pass in a previous version if you already know it (for efficiancy) @@ -132,7 +133,7 @@ def get_changes_for_version(newVersion, oldVersion=None): return compare -class EventRevisions(generic.ListView): +class EventRevisions(generic.TemplateView): model = reversion.revisions.Version template_name = "RIGS/event_version_list.html" @@ -158,19 +159,24 @@ class EventRevisions(generic.ListView): class ActivityStream(generic.ListView): model = reversion.revisions.Version template_name = "RIGS/activity_stream.html" + paginate_by = 25 - def get_context_data(self, **kwargs): - - versions = get_versions_for_model(models.Event); + def get_queryset(self): + versions = get_versions_for_model(models.Event) + return versions + def get_context_data(self, **kwargs): + + # Call the base implementation first to get a context + context = super(ActivityStream, self).get_context_data(**kwargs) + items = [] - for thisVersion in versions[:20]: + for thisVersion in context['object_list']: thisItem = get_changes_for_version(thisVersion, None) items.append(thisItem) - context = { - 'object_list': items, - } + context ['object_list'] = items + return context \ No newline at end of file