Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

History pagination 841124 #944

Merged
merged 4 commits into from
Commits on Mar 21, 2013
  1. @ubernostrum @groovecoder
  2. @darkwing @groovecoder

    Adding 'View All' link

    darkwing authored groovecoder committed
  3. @ubernostrum @groovecoder

    Add unit test for history view pagination.

    ubernostrum authored groovecoder committed
  4. @ubernostrum @groovecoder
This page is out of date. Refresh to see the latest.
View
24 apps/wiki/templates/wiki/document_revisions.html
@@ -39,10 +39,11 @@ <h1 class="title">{{ _('History of') }} <a href="{{ url('wiki.document', documen
{% if document.current_revision == rev %}
{% set reached_current = True %}
{% endif %}
+ {% set is_current = document.current_revision.id == rev %}
{% if loop.first %}<ul>{% endif %}
- <li class="{% if document.current_revision == rev %}current{% endif %}{% if rev.reviewed and not rev.is_approved %}rejected{% endif %}">
+ <li class="{% if document.current_revision.id == rev %}current{% endif %}{% if rev.reviewed and not rev.is_approved %}rejected{% endif %}">
<div class="radio">
- {% if not loop.first %}<input type="radio" name="from" value="{{ rev.id }}" {% if loop.index == 2 %}checked="checked"{% endif %} />{% endif %}
+ {% if not current %}<input type="radio" name="from" value="{{ rev.id }}" {% if loop.index == 2 %}checked="checked"{% endif %} />{% endif %}
</div>
<div class="radio">
{% if not loop.last %}<input type="radio" name="to" value="{{ rev.id }}" {% if loop.first %}checked="checked"{% endif %} />{% endif %}
@@ -99,8 +100,27 @@ <h1 class="title">{{ _('History of') }} <a href="{{ url('wiki.document', documen
{% endif %}
</div>
</article>
+ {% if page %}
+ {{ page|paginator }}
+ {% endif %}
+
</div>
</div>
</section>
{% endblock %}
+ {% block site_js %}
+ {{ super() }}
+ {{ js('framebuster') }}
+
+ <script type="text/javascript">
+ $(document).ready(function() {
+ function gettext(a){return a}
+ var pagination = $('.pagination'),
+ next = pagination.find('.next');
+ if(next.length) {
+ pagination.append('<li><a href="?limit=all" id="pagination-all">' + gettext('View All') + '</a></li>');
+ }
+ });
+ </script>
+{% endblock %}
View
26 apps/wiki/tests/test_views.py
@@ -161,6 +161,32 @@ def test_json_view(self):
eq_('an article title', data['title'])
ok_('translations' in data)
+ def test_history_view(self):
+ slug = 'history-view-test-doc'
+ html = 'history view test doc'
+
+ doc = document(title='History view test doc', slug=slug,
+ html=html, save=True,
+ locale=settings.WIKI_DEFAULT_LANGUAGE)
+
+ for i in xrange(1, 51):
+ rev = revision(document=doc, content=html,
+ comment='Revision %s' % i,
+ is_approved=True, save=True)
+ rev.save()
+
+ url = reverse('wiki.document_revisions', args=(slug,),
+ locale=settings.WIKI_DEFAULT_LANGUAGE)
+
+ resp = self.client.get(url)
+ eq_(200, resp.status_code)
+
+ all_url = urlparams(reverse('wiki.document_revisions', args=(slug,),
+ locale=settings.WIKI_DEFAULT_LANGUAGE),
+ limit='all')
+ resp = self.client.get(url)
+ eq_(200, resp.status_code)
+
def test_toc_view(self):
slug = 'toc_test_doc'
html = '<h2>Head 2</h2><h3>Head 3</h3>'
View
13 apps/wiki/views.py
@@ -1356,7 +1356,17 @@ def document_revisions(request, document_slug, document_locale):
revs = (Revision.objects.filter(document=doc)
.defer('summary', 'content')
.order_by('-created', '-id'))
+ page = None
+ per_page = request.GET.get('limit', 10)
+ if per_page != 'all':
+ try:
+ per_page = int(per_page)
+ except ValueError:
+ per_page = DOCUMENTS_PER_PAGE
+ page = paginate(request, revs, per_page)
+ revs = [r for r in page.object_list]
+
# Ensure the current revision appears at the top, no matter where it
# appears in the order.
curr_id = doc.current_revision.id
@@ -1364,7 +1374,8 @@ def document_revisions(request, document_slug, document_locale):
revs_out.extend([r for r in revs if r.id != curr_id])
return jingo.render(request, 'wiki/document_revisions.html',
- {'revisions': revs_out, 'document': doc})
+ {'revisions': revs_out, 'document': doc,
+ 'page': page, 'revs': revs, 'curr_id': curr_id})
@login_required
Something went wrong with that request. Please try again.