mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-23 08:22:15 +00:00
More UI stuff, and pagination on activity stream
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
|
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load paginator from filters %}
|
||||||
|
|
||||||
{% block title %}Rigboard Activity Stream{% endblock %}
|
{% block title %}Rigboard Activity Stream{% endblock %}
|
||||||
|
|
||||||
@@ -40,48 +41,62 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{# comment "table view" #}
|
<div class="col-sm-12">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<h3>Rigboard Activity Stream</h3>
|
||||||
|
</div>
|
||||||
|
<div class="text-right col-sm-12">{% paginator %}</div>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
|
||||||
<h2>Rigboard Activity Stream - Table View</h2>
|
<table class="table table-striped">
|
||||||
<br>
|
<thead>
|
||||||
<table class="table table-striped">
|
<tr>
|
||||||
<thead>
|
<td>Date</td>
|
||||||
<tr>
|
<td>Event</td>
|
||||||
<td>Date</td>
|
<td>Version ID</td>
|
||||||
<td>Event</td>
|
<td>User</td>
|
||||||
<td>Version ID</td>
|
<td>Changes</td>
|
||||||
<td>User</td>
|
</tr>
|
||||||
<td>Changes</td>
|
</thead>
|
||||||
</tr>
|
<tbody>
|
||||||
</thead>
|
{% for version in object_list %}
|
||||||
<tbody>
|
|
||||||
{% for version in object_list %}
|
<tr>
|
||||||
{% if version.item_changes or version.field_changes or version.old == None%}
|
<td>{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}</td>
|
||||||
<tr>
|
<td><a href="{% url 'event_detail' version.new.pk %}">N{{ version.new.pk|stringformat:"05d" }}</a></td>
|
||||||
<td>{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}</td>
|
<td>{{ version.version.pk }}|{{ version.revision.pk }}</td>
|
||||||
<td><a href="{% url 'event_detail' version.new.pk %}">N{{ version.new.pk|stringformat:"05d" }}</a></td>
|
<td>{{ version.revision.user.name }}</td>
|
||||||
<td>{{ version.version.pk }}|{{ version.revision.pk }}</td>
|
<td>
|
||||||
<td>{{ version.revision.user.name }}</td>
|
{% if version.old == None %}
|
||||||
<td>
|
Event Created
|
||||||
{% if version.old == None %}
|
{% else %}
|
||||||
Event Created
|
{% include 'RIGS/event_version_changes.html' %}
|
||||||
{% else %}
|
{% endif %} </td>
|
||||||
{% include 'RIGS/event_version_changes.html' %}
|
</tr>
|
||||||
{% endif %} </td>
|
|
||||||
</tr>
|
{% endfor %}
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="align-right">{% paginator %}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{# endcomment #}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<br>
|
<br>
|
||||||
<h2>Rigboard Activity Stream - Stream View</h2>
|
<h2>Rigboard Activity Stream - Scrollable Stream View <br/><small>Possibly to go on homepage</small></h2>
|
||||||
<br>
|
<br>
|
||||||
|
<div style="
|
||||||
|
max-height: 500px;
|
||||||
|
max-width: 300px;
|
||||||
|
overflow-y:scroll;
|
||||||
|
border:1px solid black;">
|
||||||
{% for version in object_list %}
|
{% for version in object_list %}
|
||||||
{% if version.item_changes or version.field_changes or version.old == None %}
|
{% if version.item_changes or version.field_changes or version.old == None %}
|
||||||
<div class="well">
|
<div class="well">
|
||||||
@@ -97,9 +112,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ thediff }}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for itemChange in version.item_changes %}
|
{% for itemChange in version.item_changes %}
|
||||||
<button title="Changes to item '{{ itemChange.new.name }}'" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
|
<button title="Changes to item '{{ itemChange.new.name|default:itemChange.old.name }}'" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
|
||||||
{% for change in itemChange.changes %}
|
{% for change in itemChange.changes %}
|
||||||
<h4>{{ change.field.verbose_name }}</h4>
|
<h4>{{ change.field.verbose_name }}</h4>
|
||||||
|
|
||||||
@@ -19,5 +19,5 @@
|
|||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
'>item '{{ itemChange.new.name }}'</button>
|
'>item '{{ itemChange.new.name|default:itemChange.old.name }}'</button>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -8,8 +8,12 @@
|
|||||||
<script src="{% static "js/popover.js" %}"></script>
|
<script src="{% static "js/popover.js" %}"></script>
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
$('[data-toggle="popover"]').popover()
|
$('[data-toggle="popover"]').popover().click(function(){
|
||||||
})
|
if($(this).attr('href')){
|
||||||
|
window.location.href = $(this).attr('href');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import reversion
|
|||||||
import simplejson
|
import simplejson
|
||||||
from reversion.models import Version
|
from reversion.models import Version
|
||||||
from django.contrib.contenttypes.models import ContentType # Used to lookup the content_type
|
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
|
from RIGS import models, forms
|
||||||
import datetime
|
import datetime
|
||||||
@@ -85,8 +86,8 @@ def compare_event_items(old, new):
|
|||||||
|
|
||||||
changes = []
|
changes = []
|
||||||
for (_, compare) in item_dict.items():
|
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
|
changes.append(compare) # transfer into a sequential array to make it easier to deal with later
|
||||||
|
|
||||||
return changes
|
return changes
|
||||||
@@ -95,7 +96,7 @@ def get_versions_for_model(model):
|
|||||||
content_type = ContentType.objects.get_for_model(model)
|
content_type = ContentType.objects.get_for_model(model)
|
||||||
versions = reversion.models.Version.objects.filter(
|
versions = reversion.models.Version.objects.filter(
|
||||||
content_type = content_type,
|
content_type = content_type,
|
||||||
).select_related("revision").order_by("-pk")
|
).select_related("revision","revision.version_set").order_by("-pk")
|
||||||
|
|
||||||
return versions
|
return versions
|
||||||
|
|
||||||
@@ -105,12 +106,12 @@ def get_previous_version(version):
|
|||||||
|
|
||||||
versions = reversion.get_for_object_reference(models.Event, thisEventId)
|
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
|
||||||
return previousVersions[0]
|
|
||||||
else: #this is probably the initial version
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_changes_for_version(newVersion, oldVersion=None):
|
def get_changes_for_version(newVersion, oldVersion=None):
|
||||||
#Pass in a previous version if you already know it (for efficiancy)
|
#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
|
return compare
|
||||||
|
|
||||||
class EventRevisions(generic.ListView):
|
class EventRevisions(generic.TemplateView):
|
||||||
model = reversion.revisions.Version
|
model = reversion.revisions.Version
|
||||||
template_name = "RIGS/event_version_list.html"
|
template_name = "RIGS/event_version_list.html"
|
||||||
|
|
||||||
@@ -158,19 +159,24 @@ class EventRevisions(generic.ListView):
|
|||||||
class ActivityStream(generic.ListView):
|
class ActivityStream(generic.ListView):
|
||||||
model = reversion.revisions.Version
|
model = reversion.revisions.Version
|
||||||
template_name = "RIGS/activity_stream.html"
|
template_name = "RIGS/activity_stream.html"
|
||||||
|
paginate_by = 25
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
versions = get_versions_for_model(models.Event)
|
||||||
|
return versions
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
||||||
versions = get_versions_for_model(models.Event);
|
# Call the base implementation first to get a context
|
||||||
|
context = super(ActivityStream, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
|
||||||
for thisVersion in versions[:20]:
|
for thisVersion in context['object_list']:
|
||||||
thisItem = get_changes_for_version(thisVersion, None)
|
thisItem = get_changes_for_version(thisVersion, None)
|
||||||
items.append(thisItem)
|
items.append(thisItem)
|
||||||
|
|
||||||
context = {
|
context ['object_list'] = items
|
||||||
'object_list': items,
|
|
||||||
}
|
|
||||||
|
|
||||||
return context
|
return context
|
||||||
Reference in New Issue
Block a user