mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-29 03:12:15 +00:00
Added activity stream view
This commit is contained in:
156
RIGS/templates/RIGS/activity_stream.html
Normal file
156
RIGS/templates/RIGS/activity_stream.html
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block title %}Rigboard Activity Stream{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script src="{% static "js/tooltip.js" %}"></script>
|
||||||
|
<script src="{% static "js/popover.js" %}"></script>
|
||||||
|
<script src="{% static "js/moment.min.js" %}"></script>
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
$('[data-toggle="popover"]').popover();
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
$('.date').each(function (index, dateElem) {
|
||||||
|
var $dateElem = $(dateElem);
|
||||||
|
var formatted = moment($dateElem.text()).fromNow();
|
||||||
|
$dateElem.text(formatted);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Rigboard Activity Stream</h2>
|
||||||
|
<br>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>Date</td>
|
||||||
|
<td>Event</td>
|
||||||
|
<td>Version ID</td>
|
||||||
|
<td>User</td>
|
||||||
|
<td>Changes</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for version in object_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ version.revision.date_created|date:"Y-m-d H:i:s" }}</td>
|
||||||
|
<td><a href="{% url 'event_detail' version.thisVersion.object_id_int %}">N{{ version.thisVersion.object_id_int|stringformat:"05d" }}</a></td>
|
||||||
|
<td>{{ version.pk }}|{{ version.revision.pk }}</td>
|
||||||
|
<td>{{ version.revision.user.name }}</td>
|
||||||
|
<td>{% for key, old, new in version.changes %}
|
||||||
|
<button title="Changes to {{ key }}" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-placement='left' data-toggle="popover" data-content='
|
||||||
|
|
||||||
|
{% if new %}<div class="alert alert-success">{{new}}</div>{% endif %}
|
||||||
|
{% if old %}<div class="alert alert-danger">{{old}}</div>{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
'>{{ key }}</button>
|
||||||
|
{% endfor %}
|
||||||
|
{% for key, old, new in version.item_changes %}
|
||||||
|
<button title="{{ key }}" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-placement='left' data-toggle="popover" data-content='
|
||||||
|
|
||||||
|
{% if new %}
|
||||||
|
<div class="alert alert-success">
|
||||||
|
<dl>
|
||||||
|
<dt>Name</dt>
|
||||||
|
<dd>{{new.name}}</dd>
|
||||||
|
<dt>Description</dt>
|
||||||
|
<dd>{{new.description}}</dd>
|
||||||
|
<dt>Quantity</dt>
|
||||||
|
<dd>{{new.quantity}}</dd>
|
||||||
|
<dt>Price</dt>
|
||||||
|
<dd>{{new.cost}}
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if old %}
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<dl>
|
||||||
|
<dt>Name</dt>
|
||||||
|
<dd>{{old.name}}</dd>
|
||||||
|
<dt>Description</dt>
|
||||||
|
<dd>{{old.description}}</dd>
|
||||||
|
<dt>Quantity</dt>
|
||||||
|
<dd>{{old.quantity}}</dd>
|
||||||
|
<dt>Price</dt>
|
||||||
|
<dd>{{old.cost}}
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
'>{{ key }}</button>
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h2>Stream View</h2>
|
||||||
|
{% for version in object_list %}
|
||||||
|
<div class="well">
|
||||||
|
<button title="title" type="button" class="btn btn-default btn-xs">{{ version.revision.user.first_name|default_if_none:"(unknown)" }}</button> changed
|
||||||
|
{% for key, old, new in version.changes %}
|
||||||
|
<button title="Changes to {{ key }}" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
|
||||||
|
|
||||||
|
{% if new %}<div class="alert alert-success">{{new}}</div>{% endif %}
|
||||||
|
{% if old %}<div class="alert alert-danger">{{old}}</div>{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
'>{{ key }}</button>
|
||||||
|
{% endfor %}
|
||||||
|
{% for key, old, new in version.item_changes %}
|
||||||
|
<button title="{{ key }}" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-placement='left' data-toggle="popover" data-content='
|
||||||
|
|
||||||
|
{% if new %}
|
||||||
|
<div class="alert alert-success">
|
||||||
|
<dl>
|
||||||
|
<dt>Name</dt>
|
||||||
|
<dd>{{new.name}}</dd>
|
||||||
|
<dt>Description</dt>
|
||||||
|
<dd>{{new.description}}</dd>
|
||||||
|
<dt>Quantity</dt>
|
||||||
|
<dd>{{new.quantity}}</dd>
|
||||||
|
<dt>Price</dt>
|
||||||
|
<dd>{{new.cost}}
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if old %}
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<dl>
|
||||||
|
<dt>Name</dt>
|
||||||
|
<dd>{{old.name}}</dd>
|
||||||
|
<dt>Description</dt>
|
||||||
|
<dd>{{old.description}}</dd>
|
||||||
|
<dt>Quantity</dt>
|
||||||
|
<dd>{{old.quantity}}</dd>
|
||||||
|
<dt>Price</dt>
|
||||||
|
<dd>{{old.cost}}
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
'>{{ key }}</button>
|
||||||
|
{% endfor %}
|
||||||
|
in <button title="title" type="button" class="btn btn-default btn-xs">N{{ version.thisVersion.object_id_int|stringformat:"05d" }}</button> <small>(<span class="date">{{ version.revision.date_created|date:"Y-m-d H:i:s" }}</span>)</small>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ thediff }}
|
||||||
|
{% endblock %}
|
||||||
@@ -84,6 +84,10 @@ urlpatterns = patterns('',
|
|||||||
permission_required_with_403('RIGS.view_event')(versioning.EventRevisions.as_view()),
|
permission_required_with_403('RIGS.view_event')(versioning.EventRevisions.as_view()),
|
||||||
name='event_history'),
|
name='event_history'),
|
||||||
|
|
||||||
|
url(r'^rigboard/activity$',
|
||||||
|
permission_required_with_403('RIGS.view_event')(versioning.ActivityStream.as_view()),
|
||||||
|
name='activity_stream'),
|
||||||
|
|
||||||
# Finance
|
# Finance
|
||||||
url(r'^invoice/$',
|
url(r'^invoice/$',
|
||||||
permission_required_with_403('RIGS.view_invoice')(finance.InvoiceIndex.as_view()),
|
permission_required_with_403('RIGS.view_invoice')(finance.InvoiceIndex.as_view()),
|
||||||
|
|||||||
@@ -95,6 +95,57 @@ def compare_items(old, new):
|
|||||||
|
|
||||||
return zip(key,old,new)
|
return zip(key,old,new)
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
return versions
|
||||||
|
|
||||||
|
def strip_duplicate_versions(versions): #probably don't need this function
|
||||||
|
changed_versions = []
|
||||||
|
last_serialized_data = None
|
||||||
|
for version in versions:
|
||||||
|
if last_serialized_data != version.serialized_data:
|
||||||
|
changed_versions.append(version)
|
||||||
|
last_serialized_data = version.serialized_data
|
||||||
|
|
||||||
|
return changed_versions
|
||||||
|
|
||||||
|
def get_previous_version(version):
|
||||||
|
thisEventId = version.object_id
|
||||||
|
thisVersionId = version.pk
|
||||||
|
|
||||||
|
versions = reversion.get_for_object_reference(models.Event, thisEventId)
|
||||||
|
|
||||||
|
previousVersions = versions.filter(pk__lt=thisVersionId)
|
||||||
|
|
||||||
|
if len(previousVersions) >= 1:
|
||||||
|
return previousVersions[0]
|
||||||
|
else: #this is probably the initial version
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_changes_for_version(thisVersion, previousVersion=None):
|
||||||
|
|
||||||
|
if previousVersion == None:
|
||||||
|
previousVersion = get_previous_version(thisVersion)
|
||||||
|
|
||||||
|
compare = {}
|
||||||
|
compare['pk'] = thisVersion.pk
|
||||||
|
compare['thisVersion'] = thisVersion
|
||||||
|
compare['prevVersion'] = previousVersion
|
||||||
|
compare['revision'] = thisVersion.revision
|
||||||
|
|
||||||
|
if previousVersion:
|
||||||
|
compare['changes'] = compare_events(previousVersion.field_dict,thisVersion.field_dict)
|
||||||
|
compare['item_changes'] = compare_items(previousVersion, thisVersion)
|
||||||
|
else:
|
||||||
|
compare['changes'] = [["(initial version)",None,"Event Created"]]
|
||||||
|
|
||||||
|
return compare
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EventRevisions(generic.ListView):
|
class EventRevisions(generic.ListView):
|
||||||
model = reversion.revisions.Version
|
model = reversion.revisions.Version
|
||||||
@@ -104,22 +155,13 @@ class EventRevisions(generic.ListView):
|
|||||||
thisEvent = get_object_or_404(models.Event, pk=self.kwargs['pk'])
|
thisEvent = get_object_or_404(models.Event, pk=self.kwargs['pk'])
|
||||||
versions = reversion.get_for_object(thisEvent)
|
versions = reversion.get_for_object(thisEvent)
|
||||||
items = []
|
items = []
|
||||||
for revisionNo, thisRevision in enumerate(versions):
|
for versionNo, thisVersion in enumerate(versions):
|
||||||
thisItem = {'pk': thisRevision.pk}
|
if versionNo >= len(versions)-1:
|
||||||
thisItem['revision'] = thisRevision.revision
|
thisItem = get_changes_for_version(thisVersion, None)
|
||||||
logger.info(thisRevision.revision.version_set.all())
|
|
||||||
|
|
||||||
if revisionNo >= len(revisions)-1:
|
|
||||||
# oldest version
|
|
||||||
thisItem['changes'] = [["(initial version)",None,"Event Created"]]
|
|
||||||
else:
|
else:
|
||||||
changes = compare_events(revisions[revisionNo+1].field_dict,thisRevision.field_dict)
|
thisItem = get_changes_for_version(thisVersion, versions[versionNo+1])
|
||||||
thisItem['item_changes'] = compare_items(revisions[revisionNo+1], thisRevision)
|
|
||||||
logger.debug(thisItem['item_changes'])
|
|
||||||
thisItem['changes'] = changes
|
|
||||||
|
|
||||||
items.append(thisItem)
|
items.append(thisItem)
|
||||||
logger.info(thisItem)
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'object_list': items,
|
'object_list': items,
|
||||||
@@ -128,3 +170,22 @@ class EventRevisions(generic.ListView):
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
class ActivityStream(generic.ListView):
|
||||||
|
model = reversion.revisions.Version
|
||||||
|
template_name = "RIGS/activity_stream.html"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
|
||||||
|
versions = get_versions_for_model(models.Event);
|
||||||
|
|
||||||
|
items = []
|
||||||
|
|
||||||
|
for thisVersion in versions[:20]:
|
||||||
|
thisItem = get_changes_for_version(thisVersion, None)
|
||||||
|
items.append(thisItem)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'object_list': items,
|
||||||
|
}
|
||||||
|
|
||||||
|
return context
|
||||||
Reference in New Issue
Block a user