mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
newforms-admin: Moved list_per_page from AdminOptions to ModelAdmin.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4336 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
93e024365d
commit
f72a100b53
@ -37,6 +37,7 @@ class ModelAdmin(object):
|
|||||||
list_display_links = ()
|
list_display_links = ()
|
||||||
list_filter = ()
|
list_filter = ()
|
||||||
list_select_related = False
|
list_select_related = False
|
||||||
|
list_per_page = 100
|
||||||
search_fields = ()
|
search_fields = ()
|
||||||
date_hierarchy = None
|
date_hierarchy = None
|
||||||
save_as = False
|
save_as = False
|
||||||
@ -276,7 +277,7 @@ class ModelAdmin(object):
|
|||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
try:
|
try:
|
||||||
cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
|
cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
|
||||||
self.date_hierarchy, self.search_fields, self.list_select_related)
|
self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page)
|
||||||
except IncorrectLookupParameters:
|
except IncorrectLookupParameters:
|
||||||
# Wacky lookup parameters were given, so redirect to the main
|
# Wacky lookup parameters were given, so redirect to the main
|
||||||
# changelist page, without parameters, and pass an 'invalid=1'
|
# changelist page, without parameters, and pass an 'invalid=1'
|
||||||
|
@ -292,7 +292,7 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current
|
|||||||
perms_needed.add(related.opts.verbose_name)
|
perms_needed.add(related.opts.verbose_name)
|
||||||
|
|
||||||
class ChangeList(object):
|
class ChangeList(object):
|
||||||
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related):
|
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.opts = model._meta
|
self.opts = model._meta
|
||||||
self.lookup_opts = self.opts
|
self.lookup_opts = self.opts
|
||||||
@ -303,6 +303,7 @@ class ChangeList(object):
|
|||||||
self.date_hierarchy = date_hierarchy
|
self.date_hierarchy = date_hierarchy
|
||||||
self.search_fields = search_fields
|
self.search_fields = search_fields
|
||||||
self.list_select_related = list_select_related
|
self.list_select_related = list_select_related
|
||||||
|
self.list_per_page = list_per_page
|
||||||
|
|
||||||
# Get search parameters from the query string.
|
# Get search parameters from the query string.
|
||||||
try:
|
try:
|
||||||
@ -351,7 +352,7 @@ class ChangeList(object):
|
|||||||
return '?' + '&'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')
|
return '?' + '&'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')
|
||||||
|
|
||||||
def get_results(self, request):
|
def get_results(self, request):
|
||||||
paginator = ObjectPaginator(self.query_set, self.lookup_opts.admin.list_per_page)
|
paginator = ObjectPaginator(self.query_set, self.list_per_page)
|
||||||
|
|
||||||
# Get the number of objects, with admin filters applied.
|
# Get the number of objects, with admin filters applied.
|
||||||
try:
|
try:
|
||||||
@ -373,7 +374,7 @@ class ChangeList(object):
|
|||||||
full_result_count = self.manager.count()
|
full_result_count = self.manager.count()
|
||||||
|
|
||||||
can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
|
can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
|
||||||
multi_page = result_count > self.lookup_opts.admin.list_per_page
|
multi_page = result_count > self.list_per_page
|
||||||
|
|
||||||
# Get the list of objects to display on this page.
|
# Get the list of objects to display on this page.
|
||||||
if (self.show_all and can_show_all) or not multi_page:
|
if (self.show_all and can_show_all) or not multi_page:
|
||||||
|
@ -137,7 +137,7 @@ class Model(object):
|
|||||||
# of ModelAdmin.
|
# of ModelAdmin.
|
||||||
cls._meta.ModelAdmin = type('ModelAdmin', (value, ModelAdmin), {})
|
cls._meta.ModelAdmin = type('ModelAdmin', (value, ModelAdmin), {})
|
||||||
# This AdminOptions stuff is legacy and will eventually be removed.
|
# This AdminOptions stuff is legacy and will eventually be removed.
|
||||||
value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_') and k not in ('list_display', 'list_display_links', 'list_filter', 'date_hierarchy', 'save_as', 'search_fields', 'list_select_related')]))
|
value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_') and k not in ('list_display', 'list_display_links', 'list_filter', 'date_hierarchy', 'save_as', 'search_fields', 'list_select_related', 'list_per_page')]))
|
||||||
value.contribute_to_class(cls, name)
|
value.contribute_to_class(cls, name)
|
||||||
elif hasattr(value, 'contribute_to_class'):
|
elif hasattr(value, 'contribute_to_class'):
|
||||||
value.contribute_to_class(cls, name)
|
value.contribute_to_class(cls, name)
|
||||||
|
@ -201,12 +201,11 @@ class Options(object):
|
|||||||
class AdminOptions(object):
|
class AdminOptions(object):
|
||||||
def __init__(self, fields=None, js=None,
|
def __init__(self, fields=None, js=None,
|
||||||
ordering=None,
|
ordering=None,
|
||||||
save_on_top=False, manager=None, list_per_page=100):
|
save_on_top=False, manager=None):
|
||||||
self.fields = fields
|
self.fields = fields
|
||||||
self.js = js or []
|
self.js = js or []
|
||||||
self.ordering = ordering
|
self.ordering = ordering
|
||||||
self.save_on_top = save_on_top
|
self.save_on_top = save_on_top
|
||||||
self.list_per_page = list_per_page
|
|
||||||
self.manager = manager or Manager()
|
self.manager = manager or Manager()
|
||||||
|
|
||||||
def get_field_sets(self, opts):
|
def get_field_sets(self, opts):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user