Commits

Anonymous committed 19e55da

add revisions view (for those who don't have javascript)

  • Participants
  • Parent commits 0f0727d

Comments (0)

Files changed (4)

friendpaste/paste/views.py

 
     # get theme
     theme = _get_theme(request)
-    return render_response('paste/view.html', snippet=s, theme=theme, form=form,
-            revisions=revisions)
+    return render_response('paste/view.html', snippet=s, theme=theme, form=form, revisions=revisions)
+
+def view_revisions(request, id):
+    res = _get_snippet_revisions(id)
+    if not res:
+        raise NotFound 
+    # set revisions
+    revisions = res[1:]
+    revisions.reverse()
+
+    # set snippet
+    data = res[0].value
+    data['_id'] = res[0].id
+    s = Snippet.wrap(data)
+
+
+    return render_response('paste/revisions.html', snippet=s, revisions=revisions)
 
 def view_rawsnippet(request, id):
     db = local.application.db

friendpaste/urls.py

         'paste/raw': paste.view_rawsnippet,
         'paste/original': paste.view_original,
         'paste/edit': paste.edit_snippet,
-        'paste/changeset': paste.view_changeset
+        'paste/changeset': paste.view_changeset,
+        'paste/revisions': paste.view_revisions
 }
 
 
     Rule('/<id>/original', endpoint='paste/original'),
     Rule('/<id>/edit', endpoint='paste/edit'),
     Rule('/<id>/changeset', endpoint='paste/changeset'),
+    Rule('/<id>/revisions', endpoint='paste/revisions'),
     Rule('/<id>', endpoint='paste/view')
 ])
 

templates/paste/diff.html

 {% extends "base.html" %}
 
-{% block title %}{{ snippet['_id'] }} changes{% block title %}
+{% block title %}{{ snippet['_id'] }} changes{% endblock %}
 {% block head %}
 <link rel="stylesheet" href="/static/css/{{theme }}.css" type="text/css" />
 <script type="text/javascript" src="/static/js/friendpaste.js"></script>

templates/paste/revisions.html

+{% extends "base.html" %}
+
+{% block title %}revisions of {{ snippet.id }}{% endblock %}
+
+{% block content %}
+<div id="revisions">
+    <h2><a href="/{{ snippet.id }}" class="root">{{ snippet.id }}</a>&nbsp;/&nbsp;{% if snippet.title %}{{ snippet.title }}{% else %}No title{% endif %}</h2>
+    <p>last change {{ snippet.updated|datetimeformat }}</p>
+    <h3>Older revisions</h3>
+    <table class="revisionstable">
+        <tr>
+            <td class="since">{{ snippet.updated|timesince }}</td>
+            <td class="rev">rev. <a href="/{{ snippet.id }}">{{ snippet.revid }}</a></td>
+            <td class="changeset"><a href="/{{ snippet.id }}/changeset?rev={{ snippet.revid }}">Diff</a></td>
+            <td class="view-rev"><a href="{{ snippet.id }}">View</a></td>
+        </tr>
+    
+
+    {% 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>
+        </tr>
+    {% endfor %}
+    </table>
+    <div>
+        <form action="/{{ snippet.id }}" method="get">
+            <input type="submit" value="Back to the paste..." />
+        </form>
+    </div>
+
+</div>
+{% endblock %}