Repository: carpentries/amy

Issue:
Revision webpages are messed up
1. Go to https://amy.software-carpentry.org/workshops/person/9963/
2. Click links next to "Created on" and "Last modified on".
3. You can see that both revisions have nothing in common with the person.
Revision webpages are messed up
1. Go to https://amy.software-carpentry.org/workshops/person/9963/
2. Click links next to "Created on" and "Last modified on".
3. You can see that both revisions have nothing in common with the person.


Discussion:
This is due to an assumption [here](https://github.com/swcarpentry/amy/blob/develop/workshops/views.py#L2166) that each revision consists of only one version. (Version is a change to one record. Revision is a bunch of versions.)

@maneesha does anybody uses revisions? Has it ever been used? If not, we could remove this feature from frontend.
I use this feature and would like to fix and keep it.
This is due to an assumption [here](https://github.com/swcarpentry/amy/blob/develop/workshops/views.py#L2166) that each revision consists of only one version. (Version is a change to one record. Revision is a bunch of versions.)

@maneesha does anybody uses revisions? Has it ever been used? If not, we could remove this feature from frontend.
I use this feature and would like to fix and keep it.

Resolving patch:
diff --git a/workshops/urls.py b/workshops/urls.py
--- a/workshops/urls.py
+++ b/workshops/urls.py
@@ -132,7 +132,7 @@
         url(r'^duplicates/$', views.duplicates, name='duplicates'),
     ])),
 
-    url(r'^revision/(?P<revision_id>[\d]+)/$', views.object_changes, name='object_changes'),
+    url(r'^version/(?P<version_id>[\d]+)/$', views.object_changes, name='object_changes'),
 
     url(r'^requests/$', views.AllEventRequests.as_view(), name='all_eventrequests'),
     url(r'^request/(?P<request_id>\d+)/', include([
diff --git a/workshops/views.py b/workshops/views.py
--- a/workshops/views.py
+++ b/workshops/views.py
@@ -42,7 +42,7 @@
     ModelFormMixin,
 )
 from github.GithubException import GithubException
-from reversion.models import Revision
+from reversion.models import Version
 from reversion.revisions import get_for_object
 
 from api.filters import (
@@ -2075,11 +2075,8 @@ def instructor_issues(request):
 
 
 @admin_required
-def object_changes(request, revision_id):
-    revision = get_object_or_404(Revision, pk=revision_id)
-
-    # we assume there's only one version per revision
-    current_version = revision.version_set.all()[0]
+def object_changes(request, version_id):
+    current_version = get_object_or_404(Version, pk=version_id)
     obj = current_version.object
 
     try:
@@ -2096,7 +2093,7 @@ def object_changes(request, revision_id):
         'object': obj,
         'previous_version': previous_version,
         'current_version': current_version,
-        'revision': revision,
+        'revision': current_version.revision,
         'title': str(obj),
         'verbose_name': obj._meta.verbose_name,
         'fields': [


Test patch:
diff --git a/workshops/test/test_diff.py b/workshops/test/test_diff.py
--- a/workshops/test/test_diff.py
+++ b/workshops/test/test_diff.py
@@ -1,8 +1,8 @@
 from django.core.urlresolvers import reverse
 from reversion.revisions import get_for_object, create_revision
+from reversion import revisions as reversion
 
 from workshops.models import Event, Person, Tag
-
 from .base import TestBase
 
 
@@ -94,3 +94,34 @@ def test_diff_shows_PK_for_deleted_relationships(self):
             '<a class="label label-success" href="#">+2</a>',
             html=True
         )
+
+
+class TestRegression1083(TestBase):
+    def setUp(self):
+        self._setUpUsersAndLogin()
+
+    def test_regression_1083(self):
+        with reversion.create_revision():
+            alice = Person.objects.create_user(
+                username='alice', personal='Alice', family='Jones',
+                email='alice@jones.pl')
+
+        with reversion.create_revision():
+            bob = Person.objects.create_user(
+                username='bob', personal='Bob', family='Smith',
+                email='bob@smith.pl')
+
+        with reversion.create_revision():
+            alice.family = 'Williams'
+            alice.save()
+            bob.family = 'Brown'
+            bob.save()
+
+        res = self.app.get(reverse('person_details', args=[bob.pk]), user='admin')
+
+        revision = res.click('Last modified on')
+        self.assertIn('Smith', revision)
+        self.assertIn('Brown', revision)
+
+        back_to_person_view = revision.click('View newest')
+        self.assertIn('Brown', back_to_person_view)