mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
newforms-admin: Moved date_hierarchy from AdminOptions to ModelAdmin.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4332 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b460910413
commit
dcbfd3fa83
@ -36,6 +36,7 @@ class ModelAdmin(object):
|
|||||||
list_display = ('__str__',)
|
list_display = ('__str__',)
|
||||||
list_display_links = ()
|
list_display_links = ()
|
||||||
list_filter = ()
|
list_filter = ()
|
||||||
|
date_hierarchy = None
|
||||||
|
|
||||||
def __init__(self, model):
|
def __init__(self, model):
|
||||||
self.model = model
|
self.model = model
|
||||||
@ -271,7 +272,8 @@ class ModelAdmin(object):
|
|||||||
if not self.has_change_permission(request, None):
|
if not self.has_change_permission(request, None):
|
||||||
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)
|
||||||
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'
|
||||||
|
@ -193,8 +193,8 @@ def result_list(cl):
|
|||||||
result_list = register.inclusion_tag("admin/change_list_results.html")(result_list)
|
result_list = register.inclusion_tag("admin/change_list_results.html")(result_list)
|
||||||
|
|
||||||
def date_hierarchy(cl):
|
def date_hierarchy(cl):
|
||||||
if cl.lookup_opts.admin.date_hierarchy:
|
if cl.date_hierarchy:
|
||||||
field_name = cl.lookup_opts.admin.date_hierarchy
|
field_name = cl.date_hierarchy
|
||||||
year_field = '%s__year' % field_name
|
year_field = '%s__year' % field_name
|
||||||
month_field = '%s__month' % field_name
|
month_field = '%s__month' % field_name
|
||||||
day_field = '%s__day' % field_name
|
day_field = '%s__day' % field_name
|
||||||
|
@ -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):
|
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.opts = model._meta
|
self.opts = model._meta
|
||||||
self.lookup_opts = self.opts
|
self.lookup_opts = self.opts
|
||||||
@ -300,6 +300,7 @@ class ChangeList(object):
|
|||||||
self.list_display = list_display
|
self.list_display = list_display
|
||||||
self.list_display_links = list_display_links
|
self.list_display_links = list_display_links
|
||||||
self.list_filter = list_filter
|
self.list_filter = list_filter
|
||||||
|
self.date_hierarchy = date_hierarchy
|
||||||
|
|
||||||
# Get search parameters from the query string.
|
# Get search parameters from the query string.
|
||||||
try:
|
try:
|
||||||
|
@ -1019,11 +1019,11 @@ def get_validation_errors(outfile, app=None):
|
|||||||
except models.FieldDoesNotExist:
|
except models.FieldDoesNotExist:
|
||||||
e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn)
|
e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn)
|
||||||
# date_hierarchy
|
# date_hierarchy
|
||||||
if opts.admin.date_hierarchy:
|
if opts.ModelAdmin.date_hierarchy:
|
||||||
try:
|
try:
|
||||||
f = opts.get_field(opts.admin.date_hierarchy)
|
f = opts.get_field(opts.ModelAdmin.date_hierarchy)
|
||||||
except models.FieldDoesNotExist:
|
except models.FieldDoesNotExist:
|
||||||
e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % opts.admin.date_hierarchy)
|
e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % opts.ModelAdmin.date_hierarchy)
|
||||||
|
|
||||||
# Check ordering attribute.
|
# Check ordering attribute.
|
||||||
if opts.ordering:
|
if opts.ordering:
|
||||||
|
@ -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')]))
|
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')]))
|
||||||
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)
|
||||||
|
@ -200,11 +200,10 @@ class Options(object):
|
|||||||
|
|
||||||
class AdminOptions(object):
|
class AdminOptions(object):
|
||||||
def __init__(self, fields=None, js=None,
|
def __init__(self, fields=None, js=None,
|
||||||
date_hierarchy=None, save_as=False, ordering=None, search_fields=None,
|
save_as=False, ordering=None, search_fields=None,
|
||||||
save_on_top=False, list_select_related=False, manager=None, list_per_page=100):
|
save_on_top=False, list_select_related=False, manager=None, list_per_page=100):
|
||||||
self.fields = fields
|
self.fields = fields
|
||||||
self.js = js or []
|
self.js = js or []
|
||||||
self.date_hierarchy = date_hierarchy
|
|
||||||
self.save_as, self.ordering = save_as, ordering
|
self.save_as, self.ordering = save_as, ordering
|
||||||
self.search_fields = search_fields or []
|
self.search_fields = search_fields or []
|
||||||
self.save_on_top = save_on_top
|
self.save_on_top = save_on_top
|
||||||
|
Loading…
x
Reference in New Issue
Block a user