Editor fix - fix jumping to a different document version
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 7 Aug 2014 10:24:08 +0000 (12:24 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 12 Aug 2014 09:47:15 +0000 (11:47 +0200)
apps/wiki/static/wiki/editor
apps/wiki/templates/wiki/bootstrap.html
apps/wiki/views.py

index a892115..a6919c0 160000 (submodule)
@@ -1 +1 @@
-Subproject commit a892115bc1f94bfd53873dd442854b5ebe3fd03c
+Subproject commit a6919c029590f1b93e156264b063f2a9bbcff8dc
index 73e47ca..cbf0232 100644 (file)
                 documentAttachmentUrl: function(attachmentName) {
                     return '{{MEDIA_URL}}{{IMAGE_DIR}}{{slug}}/' + attachmentName;
                 },
                 documentAttachmentUrl: function(attachmentName) {
                     return '{{MEDIA_URL}}{{IMAGE_DIR}}{{slug}}/' + attachmentName;
                 },
+                documentUrl: function(id, version) {
+                    var url = '{% url 'wiki_editor' slug %}'
+                    if(version) {
+                        url = url + '?version=' + version;
+                    }
+                    return url;
+                },
 
                 documentSaveForm: {
                     fields: [
 
                 documentSaveForm: {
                     fields: [
index d776302..7ecec63 100644 (file)
@@ -83,13 +83,21 @@ def editor(request, slug, chunk=None, template_name='wiki/bootstrap.html'):
     request.session['wiki_last_books'] = last_books
 
     save_form = forms.DocumentTextSaveForm(user=request.user, prefix="textsave")
     request.session['wiki_last_books'] = last_books
 
     save_form = forms.DocumentTextSaveForm(user=request.user, prefix="textsave")
+    try:
+        version = int(request.GET.get('version', None))
+    except:
+        version = None
+    if version:
+        text = chunk.at_revision(version).materialize()
+    else:
+        text = chunk.materialize()
     return render(request, template_name, {
         'serialized_document_data': simplejson.dumps({
     return render(request, template_name, {
         'serialized_document_data': simplejson.dumps({
-            'document': chunk.materialize(),
+            'document': text,
             'document_id': chunk.id,
             'title': chunk.book.title,
             'history': get_history(chunk),
             'document_id': chunk.id,
             'title': chunk.book.title,
             'history': get_history(chunk),
-            'version': chunk.revision(),
+            'version': version or chunk.revision(),
             'stage': chunk.stage.name if chunk.stage else None,
             'assignment': chunk.user.username if chunk.user else None
         }),
             'stage': chunk.stage.name if chunk.stage else None,
             'assignment': chunk.user.username if chunk.user else None
         }),