Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

History pagination 841124 #944

Merged
merged 4 commits into from
Mar 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions apps/wiki/templates/wiki/document_revisions.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ <h1 class="title">{{ _('History of') }} <a href="{{ url('wiki.document', documen
{% if document.current_revision == rev %} {% if document.current_revision == rev %}
{% set reached_current = True %} {% set reached_current = True %}
{% endif %} {% endif %}
{% set is_current = document.current_revision.id == rev %}
{% if loop.first %}<ul>{% endif %} {% 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"> <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>
<div class="radio"> <div class="radio">
{% if not loop.last %}<input type="radio" name="to" value="{{ rev.id }}" {% if loop.first %}checked="checked"{% endif %} />{% endif %} {% if not loop.last %}<input type="radio" name="to" value="{{ rev.id }}" {% if loop.first %}checked="checked"{% endif %} />{% endif %}
Expand Down Expand Up @@ -99,8 +100,27 @@ <h1 class="title">{{ _('History of') }} <a href="{{ url('wiki.document', documen
{% endif %} {% endif %}
</div> </div>
</article> </article>
{% if page %}
{{ page|paginator }}
{% endif %}

</div> </div>
</div> </div>
</section> </section>
{% endblock %} {% 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 %}
26 changes: 26 additions & 0 deletions apps/wiki/tests/test_views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -161,6 +161,32 @@ def test_json_view(self):
eq_('an article title', data['title']) eq_('an article title', data['title'])
ok_('translations' in data) 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): def test_toc_view(self):
slug = 'toc_test_doc' slug = 'toc_test_doc'
html = '<h2>Head 2</h2><h3>Head 3</h3>' html = '<h2>Head 2</h2><h3>Head 3</h3>'
Expand Down
13 changes: 12 additions & 1 deletion apps/wiki/views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1356,15 +1356,26 @@ def document_revisions(request, document_slug, document_locale):
revs = (Revision.objects.filter(document=doc) revs = (Revision.objects.filter(document=doc)
.defer('summary', 'content') .defer('summary', 'content')
.order_by('-created', '-id')) .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 # Ensure the current revision appears at the top, no matter where it
# appears in the order. # appears in the order.
curr_id = doc.current_revision.id curr_id = doc.current_revision.id
revs_out = [r for r in revs if r.id == curr_id] revs_out = [r for r in revs if r.id == curr_id]
revs_out.extend([r for r in revs if r.id != curr_id]) revs_out.extend([r for r in revs if r.id != curr_id])


return jingo.render(request, 'wiki/document_revisions.html', 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 @login_required
Expand Down