kopia lustrzana https://github.com/wagtail/wagtail
Merge pull request #201 from davecranwell/master
Added pagination to list of pages using a given content typepull/221/merge
commit
98d616de90
|
@ -5,10 +5,10 @@
|
|||
|
||||
{% block content %}
|
||||
{% trans "Pages using" as pages_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=pages_str subtitle=content_type.model_class.get_verbose_name icon="doc-empty-inverse" %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=pages_str subtitle=page_class.get_verbose_name icon="doc-empty-inverse" %}
|
||||
|
||||
<div class="nice-padding">
|
||||
{% include "wagtailadmin/pages/list.html" with sortable=1 allow_navigation=0 sortable=0 %}
|
||||
<div id="page-results">
|
||||
{% include "wagtailadmin/pages/usage_results.html" with show_parent="True" %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
{% load i18n %}
|
||||
<div class="nice-padding">
|
||||
{% if pages %}
|
||||
{% include "wagtailadmin/pages/list.html" with show_parent=1 allow_navigation=0 %}
|
||||
|
||||
<div class="pagination">
|
||||
<p>{% blocktrans with page_number=pages.number num_pages=pages.paginator.num_pages%}
|
||||
Page {{ page_number }} of {{ num_pages }}.
|
||||
{% endblocktrans %}</p>
|
||||
<ul>
|
||||
<li class="prev">
|
||||
{% if pages.has_previous %}
|
||||
<a href="{% url 'wagtailadmin_pages_type_use' app_name content_type.model %}?p={{ pages.previous_page_number }}" class="icon icon-arrow-left">{% trans "Previous" %}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
<li class="next">
|
||||
{% if pages.has_next %}
|
||||
<a href="{% url 'wagtailadmin_pages_type_use' app_name content_type.model %}?p={{ pages.next_page_number }}" class="icon icon-arrow-right-after">{% trans 'Next' %}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{% trans 'No pages use' %}<em>"{{ page_class.get_verbose_name }}"</em>.</p>
|
||||
{% endif %}
|
||||
</div>
|
|
@ -117,15 +117,32 @@ def content_type_use(request, content_type_app_name, content_type_model_name):
|
|||
except ContentType.DoesNotExist:
|
||||
raise Http404
|
||||
|
||||
p = request.GET.get("p", 1)
|
||||
|
||||
page_class = content_type.model_class()
|
||||
|
||||
# page_class must be a Page type and not some other random model
|
||||
if not issubclass(page_class, Page):
|
||||
raise Http404
|
||||
|
||||
pages = page_class.objects.all()
|
||||
|
||||
paginator = Paginator(pages, 10)
|
||||
|
||||
try:
|
||||
pages = paginator.page(p)
|
||||
except PageNotAnInteger:
|
||||
pages = paginator.page(1)
|
||||
except EmptyPage:
|
||||
pages = paginator.page(paginator.num_pages)
|
||||
|
||||
print page_class
|
||||
|
||||
return render(request, 'wagtailadmin/pages/content_type_use.html', {
|
||||
'pages': page_class.objects.all(),
|
||||
'pages': pages,
|
||||
'app_name': content_type_app_name,
|
||||
'content_type': content_type,
|
||||
'page_class': page_class,
|
||||
})
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue