mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
[per-object-permissions] Changed pagination to use the paginator tag described on http://code.djangoproject.com/wiki/PaginatorTag
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@3617 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b5cbbf58c0
commit
741df7b44c
@ -58,3 +58,12 @@ fieldset.monospace textarea { font-family:"Bitstream Vera Sans Mono",Monaco,"Cou
|
||||
.vLargeTextField, .vXMLLargeTextField { width:48em; }
|
||||
.flatpages-flatpage #id_content { height:40.2em; }
|
||||
.module table .vPositiveSmallIntegerField { width:2.2em; }
|
||||
|
||||
|
||||
/* PAGINATOR */
|
||||
.paginator { padding: .25em .25em .6em .25em; }
|
||||
.paginate-pages { padding: 2px 3px; border: 1px solid #ddd; cursor: pointer; text-decoration: underline; }
|
||||
.paginate-first, .paginate-last { padding: 2px 6px; border: 1px solid #ddd; font-weight: bold; }
|
||||
.paginate-previous, .paginate-next { padding: 2px 3px; border: 1px solid #ddd; }
|
||||
.paginate-link { padding: 2px 4px; border: 1px solid #ddd; }
|
||||
.paginate-current { padding: 2px 4px; border: 1px solid #ddd; font-weight: bold; background:#417690; color:#f4f379; }
|
13
django/contrib/admin/templates/admin/paginator.html
Normal file
13
django/contrib/admin/templates/admin/paginator.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% spaceless %}
|
||||
{% if show_first %}<span class="paginate-first"><a href="?page=1" title="First Page">«</a></span>{% endif %}
|
||||
{% if has_previous %}<span class="paginate-previous"><a href="?page={{ previous }}" title="Previous Page"><</a></span>{% endif %}
|
||||
{% for num in page_numbers %}
|
||||
{% ifequal num page %}
|
||||
<span class="paginate-current" title="Current Page">{{ num }}</span>
|
||||
{% else %}
|
||||
<span class="paginate-link"><a href="?page={{ num }}" title="Page {{ num }}">{{ num }}</a></span>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
{% if has_next %}<span class="paginate-next"><a href="?page={{ next }}" title="Next Page">></a></span>{% endif %}
|
||||
{% if show_last %}<span class="paginate-last"><a href="?page={{ pages }}" title="Last Page">»</a></span>{% endif %}
|
||||
{% endspaceless %}
|
@ -135,7 +135,10 @@
|
||||
{% if is_paginated %}
|
||||
<tr align="right">
|
||||
<td colspan="5">
|
||||
{% comment %}
|
||||
{% if has_previous %} <a href="?page={{ previous }}"> << </a> {% endif %} {% if has_next %} <a href="?page={{ next }}"> >> </a>{% endif %}
|
||||
{% endcomment %}
|
||||
<div class="paginator">{% paginator %}</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
@ -34,4 +34,27 @@ def objref(parser, token):
|
||||
tok = "object"
|
||||
return objref_class(tok)
|
||||
|
||||
def paginator(context, adjacent_pages=2):
|
||||
"""Adds pagination context variables for first, adjacent and next page links
|
||||
in addition to those already populated by the object_list generic view."""
|
||||
page_numbers = [n for n in \
|
||||
range(context["page"] - adjacent_pages, context["page"] + adjacent_pages + 1) \
|
||||
if n > 0 and n <= context["pages"]]
|
||||
print page_numbers
|
||||
return {
|
||||
"hits": context["hits"],
|
||||
"results_per_page": context["results_per_page"],
|
||||
"page": context["page"],
|
||||
"pages": context["pages"],
|
||||
"page_numbers": page_numbers,
|
||||
"next": context["next"],
|
||||
"previous": context["previous"],
|
||||
"has_next": context["has_next"],
|
||||
"has_previous": context["has_previous"],
|
||||
"show_first": 1 not in page_numbers,
|
||||
"show_last": context["pages"] not in page_numbers,
|
||||
}
|
||||
|
||||
register.inclusion_tag("admin/paginator.html", takes_context=True)(paginator)
|
||||
|
||||
register.tag('objref', objref)
|
@ -29,12 +29,7 @@ def view_row_level_permissions(request, app_label, model_name, object_id):
|
||||
if not request.user.has_perm(RowLevelPermission._meta.app_label + '.' + RowLevelPermission._meta.get_change_permission()):
|
||||
raise PermissionDenied
|
||||
|
||||
#TODO: For now takes the number per page from the model instance not the RLP object
|
||||
paginator = ObjectPaginator(model_instance.row_level_permissions.order_by('owner_ct', 'owner_id'),
|
||||
opts.admin.list_per_page)
|
||||
|
||||
page = int(request.GET.get('page', 0))
|
||||
rlp_list = paginator.get_page(page)
|
||||
|
||||
c = template.RequestContext(request, {
|
||||
'title': _('Edit Row Level Permissions'),
|
||||
@ -42,13 +37,30 @@ def view_row_level_permissions(request, app_label, model_name, object_id):
|
||||
'content_type_id':model_ct.id,
|
||||
'original': model_instance,
|
||||
'opts':opts,
|
||||
})
|
||||
|
||||
|
||||
#TODO: For now takes the number per page from the model instance not the RLP object
|
||||
list_per_page = opts.admin.list_per_page
|
||||
#list_per_page = 5
|
||||
paginator = ObjectPaginator(model_instance.row_level_permissions.order_by('owner_ct', 'owner_id'),
|
||||
list_per_page)
|
||||
page = int(request.GET.get('page', 1))-1
|
||||
rlp_list = paginator.get_page(page)
|
||||
paginator_context = {
|
||||
"is_paginated": paginator.has_next_page(0),
|
||||
"has_next": paginator.has_next_page(page),
|
||||
"has_previous": paginator.has_previous_page(page),
|
||||
"page": page + 1,
|
||||
"next": page + 1,
|
||||
"previous": page - 1,
|
||||
})
|
||||
"page": page+1,
|
||||
"next": page+2,
|
||||
"previous": page,
|
||||
"hits":paginator.hits,
|
||||
"results_per_page":list_per_page,
|
||||
"pages":paginator.pages,
|
||||
"has_next":paginator.has_next_page(page),
|
||||
"has_previous":paginator.has_previous_page(page),
|
||||
}
|
||||
c.update(paginator_context)
|
||||
|
||||
rlp_errors = rlp_new_data = {}
|
||||
add_rlp_manip = AddRLPManipulator(model_instance, model_ct)
|
||||
|
Loading…
x
Reference in New Issue
Block a user