Commits

Benoit Chesneau  committed af88a7d

fix revisions

  • Participants
  • Parent commits b025410

Comments (0)

Files changed (5)

File friendpaste/models.py

         all_revisions.sort(lambda a,b: cmp(a.updated, b.updated))
         all_revisions.reverse()
         
-        if rev is not None:  
+        i = 0
+        if rev is not None:
             for r in all_revisions:
                 if r.revid == rev:
+                    print "%s = %s" % (r.revid, rev)
                     snippet = r
+                    snippet['_id'] = snippet.parent
+                    break
+                i = i + 1
         else:
             snippet = all_revisions[0]
-        return snippet, all_revisions
+        print rev
+        
+        return snippet, all_revisions[i:]
     get_with_revisions = classmethod(get_with_revisions)

File friendpaste/views.py

         except:
             raise NotFound
     else:
-        s, revisions = get_snippet(id, rev)
+        s, revisions = Snippet.get_with_revisions(local.db, id, rev)
 
     if not s:
         raise NotFound
 
     # get theme
     theme = _get_theme(request)
-    return render_response('paste/view.html', snippet=s, theme=theme, form=form)
+    return render_response('paste/view.html', snippet=s, theme=theme, form=form, rev=rev)
 
 
 
 def view_rss(request, id):
     try:
-        snippet, revisions = Snippet.get_with_revisions(id, request.values.get('rev'))
+        snippet, revisions = Snippet.get_with_revisions(local.db, id, request.values.get('rev'))
     except:
         raise NotFound
         
 def view_revisions(request, id):
     snippet = None
     revisions = None
+    snippet, revisions = Snippet.get_with_revisions(local.db, id, request.values.get('rev'))
     try:
         snippet, revisions = Snippet.get_with_revisions(local.db, id, request.values.get('rev'))
     except:
     if 'application/json' in request.accept_mimetypes:
         if revisions is None <= 0:
             return send_json([])
-        return send_json(revisions)
+        _revisions = []
+        for rev in revisions:
+            _revisions.append(rev._data)
+        return send_json(_revisions)
 
     if snippet is None:
         raise NotFound

File static/js/friendpaste.js

     },
 
     do_history: function(event) {
-        $.getJSON("/" + snippet_id + "/revisions",
+        url = "/" + snippet_id + "/revisions";
+        if (typeof(revid) != "undefined") {
+            url = url + "?rev=" + revid;
+        }
+        $.getJSON(url,
         function(data) {
             $(".revisionstable tbody.content").html("");
             $.each(data,

File templates/paste/revisions.html

 
     {% for rev in revisions %}
         <tr>
-            <td class="since">{{ rev.value['updated']|timesince }}</td>
-            <td class="rev">rev. <a href="/{{ snippet.id }}?rev={{ rev.value['revid'] }}">{{ rev.value['revid'] }}</a></td>
-            <td class="changeset"><a href="/{{ snippet.id }}/changeset?rev={{ rev.value['revid'] }}">Diff</a></td>
-            <td class="view-rev"><a href="/{{ snippet.id }}?rev={{ rev.value['revid'] }}">View</a></td>
+            <td class="since">{{ rev['updated']|timesince }}</td>
+            <td class="rev">rev. <a href="/{{ snippet.id }}?rev={{ rev['revid'] }}">{{ rev['revid'] }}</a></td>
+            <td class="changeset"><a href="/{{ snippet.id }}/changeset?rev={{ rev['revid'] }}">Diff</a></td>
+            <td class="view-rev"><a href="/{{ snippet.id }}?rev={{ rev['revid'] }}">View</a></td>
         </tr>
     {% endfor %}
     </table>

File templates/paste/view.html

 
 <script type="text/javascript">
     snippet_id = "{{ snippet.id }}";
+    {% if rev %}revid = "{{ snippet.revid }}";{% endif %}
 </script>
 <script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
 <script type="text/javascript" src="/static/js/jquery.resizer.js"></script>
                     </form>
                 </li>
                 <li>
-                    <form action="/{{ snippet.id }}/revisions" method="get">
+                    <form action="/{{ snippet.id }}/revisions{% if rev %}?rev={{ rev }}{% endif %}" method="get">
                         <input type="submit" class="show-history" value="Older revisions..." />
                     </form>
                 </li>