More work on other model support

This commit is contained in:
David Taylor
2015-05-23 16:49:54 +01:00
parent 6ab0715376
commit 3ed95d6687
7 changed files with 98 additions and 85 deletions

View File

@@ -71,7 +71,7 @@
<td>{{ version.revision.user.name }}</td> <td>{{ version.revision.user.name }}</td>
<td> <td>
{% if version.old == None %} {% if version.old == None %}
Event Created Object Created
{% else %} {% else %}
{% include 'RIGS/version_changes.html' %} {% include 'RIGS/version_changes.html' %}
{% endif %} </td> {% endif %} </td>
@@ -108,7 +108,7 @@
{% else %} {% else %}
changed {% include 'RIGS/version_changes.html' %} in changed {% include 'RIGS/version_changes.html' %} in
{% endif %} {% endif %}
{% include 'RIGS/event_button.html' with event=version.current %} {% include 'RIGS/object_button.html' with object=version.current %}
</div> </div>
{% endif %} {% endif %}

View File

@@ -1,18 +0,0 @@
{# pass in variable "event" to this template #}
<button title="N{{ event.pk|stringformat:"05d" }} | {{event.name}}" type="button" href="{% url 'event_detail' event.pk %}" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
<dl class="dl-vertical">
<dt>Date</dt>
<dd>{{event.start_date|date:"RIGS_DATE_FORMAT"}}</dd>
<dt>Status</dt>
<dd>{{event.get_status_display}}</dd>
<dt>MIC</dt>
<dd>{{event.mic.name}}</dd>
<dt>Venue</dt>
<dd>{{event.venue}}</dd>
</dl>
'>N{{ event.pk|stringformat:"05d" }}</button>

View File

@@ -1,52 +0,0 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% load static %}
{% block title %}N{{ object.pk|stringformat:"05d" }} - Revision History{% endblock %}
{% block js %}
<script src="{% static "js/tooltip.js" %}"></script>
<script src="{% static "js/popover.js" %}"></script>
<script>
$(function () {
$('[data-toggle="popover"]').popover().click(function(){
if($(this).attr('href')){
window.location.href = $(this).attr('href');
}
});
})
</script>
{% endblock %}
{% block content %}
<h2>N{{ object.pk|stringformat:"05d" }} - Revision History </h2>
<br>
<table class="table table-striped">
<thead>
<tr>
<td>Version ID</td>
<td>Date</td>
<td>User</td>
<td>Changes</td>
</tr>
</thead>
<tbody>
{% for version in object_list %}
{% if version.item_changes or version.field_changes or version.old == None %}
<tr>
<td>{{ version.version.pk }}|{{ version.revision.pk }}</td>
<td>{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}</td>
<td>{{ version.revision.user.name }}</td>
<td>
{% if version.old == None %}
Event Created
{% else %}
{% include 'RIGS/version_changes.html' %}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@@ -0,0 +1,4 @@
{% load to_class_name from filters %}
{# pass in variable "object" to this template #}
<a title="{{object|to_class_name}} {{ object.pk|stringformat:"05d" }} | {{object.name}}" type="button" href="{{ object.get_absolute_url }}" class="btn btn-default btn-xs">{{object|to_class_name}} {{ object.pk|stringformat:"05d" }}</a>

View File

@@ -0,0 +1,63 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% load to_class_name from filters %}
{% load paginator from filters %}
{% load static %}
{% block title %}{{object|to_class_name}} {{ object.pk|stringformat:"05d" }} - Revision History{% endblock %}
{% block js %}
<script src="{% static "js/tooltip.js" %}"></script>
<script src="{% static "js/popover.js" %}"></script>
<script>
$(function () {
$('[data-toggle="popover"]').popover().click(function(){
if($(this).attr('href')){
window.location.href = $(this).attr('href');
}
});
})
</script>
{% endblock %}
{% block content %}
<div class="col-sm-12">
<div class="row">
<div class="col-sm-12">
<h3><a href="{{ object.get_absolute_url }}">{{object|to_class_name}} {{ object.pk|stringformat:"05d" }}</a> - Revision History</h3>
</div>
<div class="text-right col-sm-12">{% paginator %}</div>
</div>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<td>Date</td>
<td>Version ID</td>
<td>User</td>
<td>Changes</td>
</tr>
</thead>
<tbody>
{% for version in object_list %}
{% if version.item_changes or version.field_changes or version.old == None %}
<tr>
<td>{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}</td>
<td>{{ version.version.pk }}|{{ version.revision.pk }}</td>
<td>{{ version.revision.user.name }}</td>
<td>
{% if version.old == None %}
Object Created
{% else %}
{% include 'RIGS/version_changes.html' %}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
<div class="align-right">{% paginator %}</div>
</div>
{% endblock %}

View File

@@ -1,6 +1,6 @@
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from RIGS import views, rigboard, finance, ical, versioning, forms from RIGS import models, views, rigboard, finance, ical, versioning, forms
from django.views.generic import RedirectView from django.views.generic import RedirectView
from PyRIGS.decorators import permission_required_with_403 from PyRIGS.decorators import permission_required_with_403
@@ -25,6 +25,9 @@ urlpatterns = patterns('',
url(r'^people/(?P<pk>\d+)/$', url(r'^people/(?P<pk>\d+)/$',
permission_required_with_403('RIGS.view_person')(views.PersonDetail.as_view()), permission_required_with_403('RIGS.view_person')(views.PersonDetail.as_view()),
name='person_detail'), name='person_detail'),
url(r'^people/(?P<pk>\d+)/history/$',
permission_required_with_403('RIGS.view_person')(versioning.VersionHistory.as_view()),
name='person_history', kwargs={'model': models.Person}),
url(r'^people/(?P<pk>\d+)/edit/$', url(r'^people/(?P<pk>\d+)/edit/$',
permission_required_with_403('RIGS.change_person')(views.PersonUpdate.as_view()), permission_required_with_403('RIGS.change_person')(views.PersonUpdate.as_view()),
name='person_update'), name='person_update'),
@@ -81,8 +84,8 @@ urlpatterns = patterns('',
name='event_archive'), name='event_archive'),
url(r'^event/(?P<pk>\d+)/history/$', url(r'^event/(?P<pk>\d+)/history/$',
permission_required_with_403('RIGS.view_event')(versioning.EventRevisions.as_view()), permission_required_with_403('RIGS.view_event')(versioning.VersionHistory.as_view()),
name='event_history'), name='event_history', kwargs={'model': models.Event}),
url(r'^rigboard/activity$', url(r'^rigboard/activity$',
permission_required_with_403('RIGS.view_event')(versioning.ActivityStream.as_view()), permission_required_with_403('RIGS.view_event')(versioning.ActivityStream.as_view()),

View File

@@ -139,14 +139,29 @@ def get_changes_for_version(newVersion, oldVersion=None):
return compare return compare
class EventRevisions(generic.TemplateView): class VersionHistory(generic.ListView):
model = reversion.revisions.Version model = reversion.revisions.Version
template_name = "RIGS/event_version_list.html" template_name = "RIGS/version_history.html"
paginate_by = 25
def get_queryset(self, **kwargs):
thisModel = self.kwargs['model']
# thisObject = get_object_or_404(thisModel, pk=self.kwargs['pk'])
versions = reversion.get_for_object_reference(thisModel, self.kwargs['pk'])
return versions
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
thisEvent = get_object_or_404(models.Event, pk=self.kwargs['pk']) thisModel = self.kwargs['model']
versions = reversion.get_for_object(thisEvent)
context = super(VersionHistory, self).get_context_data(**kwargs)
versions = context['object_list']
thisObject = get_object_or_404(thisModel, pk=self.kwargs['pk'])
items = [] items = []
for versionNo, thisVersion in enumerate(versions): for versionNo, thisVersion in enumerate(versions):
if versionNo >= len(versions)-1: if versionNo >= len(versions)-1:
thisItem = get_changes_for_version(thisVersion, None) thisItem = get_changes_for_version(thisVersion, None)
@@ -155,11 +170,9 @@ class EventRevisions(generic.TemplateView):
items.append(thisItem) items.append(thisItem)
context = { context['object_list'] = items
'object_list': items, context['object'] = thisObject
'object': thisEvent
}
return context return context
class ActivityStream(generic.ListView): class ActivityStream(generic.ListView):