1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

new-admin: Negligible formatting changes to admin.templatetags.admin_list and admin.views.main -- and removed multi-line import in templatetags/admin_list, for Python 2.3 compatibility

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1430 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-11-25 04:37:46 +00:00
parent 8be7d7e544
commit 12dec8023d
2 changed files with 173 additions and 181 deletions

View File

@ -1,18 +1,15 @@
from django.core.template.decorators import simple_tag, inclusion_tag
from django.contrib.admin.views.main import MAX_SHOW_ALL_ALLOWED, DEFAULT_RESULTS_PER_PAGE, ALL_VAR, \
ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR , SEARCH_VAR , IS_POPUP_VAR, EMPTY_CHANGELIST_VALUE, \
MONTHS
from django.utils.translation import get_date_formats
from django.core import meta
from django.utils.text import capfirst
from django.utils.html import strip_tags, escape
from django.contrib.admin.views.main import MAX_SHOW_ALL_ALLOWED, DEFAULT_RESULTS_PER_PAGE, ALL_VAR
from django.contrib.admin.views.main import ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR, SEARCH_VAR
from django.contrib.admin.views.main import IS_POPUP_VAR, EMPTY_CHANGELIST_VALUE, MONTHS
from django.core import meta, template
from django.core.exceptions import ObjectDoesNotExist
from django.conf.settings import ADMIN_MEDIA_PREFIX
from django.core import template
from django.core.template.decorators import simple_tag, inclusion_tag
from django.utils import dateformat
from django.utils.html import strip_tags, escape
from django.utils.text import capfirst
from django.utils.translation import get_date_formats
from django.conf.settings import ADMIN_MEDIA_PREFIX
DOT = '.'
#@simple_tag
@ -22,7 +19,7 @@ def paginator_number(cl,i):
elif i == cl.page_num:
return '<span class="this-page">%d</span> ' % (i+1)
else:
return '<a href="%s"%s>%d</a> ' % (cl.get_query_string( {PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1)
return '<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1)
paginator_number = simple_tag(paginator_number)
#@inclusion_tag('admin/pagination')
@ -59,51 +56,50 @@ def pagination(cl):
page_range.extend(range(page_num + 1, paginator.pages))
need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page
return {'cl': cl,
'pagination_required': pagination_required,
'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR:''}),
'page_range': page_range,
'ALL_VAR': ALL_VAR,
'1': 1
}
return {
'cl': cl,
'pagination_required': pagination_required,
'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR: ''}),
'page_range': page_range,
'ALL_VAR': ALL_VAR,
'1': 1,
}
pagination = inclusion_tag('admin/pagination')(pagination)
def result_headers(cl):
lookup_opts = cl.lookup_opts
for i, field_name in enumerate(lookup_opts.admin.list_display):
try:
f = lookup_opts.get_field(field_name)
except meta.FieldDoesNotExist:
# For non-field list_display values, check for the function
# attribute "short_description". If that doesn't exist, fall
# back to the method name. And __repr__ is a special-case.
if field_name == '__repr__':
header = lookup_opts.verbose_name
else:
func = getattr(cl.mod.Klass, field_name) # Let AttributeErrors propogate.
try:
header = func.short_description
except AttributeError:
header = func.__name__.replace('_', ' ')
# Non-field list_display values don't get ordering capability.
yield {"text": header}
try:
f = lookup_opts.get_field(field_name)
except meta.FieldDoesNotExist:
# For non-field list_display values, check for the function
# attribute "short_description". If that doesn't exist, fall
# back to the method name. And __repr__ is a special-case.
if field_name == '__repr__':
header = lookup_opts.verbose_name
else:
if isinstance(f.rel, meta.ManyToOne) and f.null:
yield {"text": f.verbose_name}
else:
th_classes = []
new_order_type = 'asc'
if field_name == cl.order_field:
th_classes.append('sorted %sending' % cl.order_type.lower())
new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()]
func = getattr(cl.mod.Klass, field_name) # Let AttributeErrors propogate.
try:
header = func.short_description
except AttributeError:
header = func.__name__.replace('_', ' ')
# Non-field list_display values don't get ordering capability.
yield {"text": header}
else:
if isinstance(f.rel, meta.ManyToOne) and f.null:
yield {"text": f.verbose_name}
else:
th_classes = []
new_order_type = 'asc'
if field_name == cl.order_field:
th_classes.append('sorted %sending' % cl.order_type.lower())
new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()]
yield {"text" : f.verbose_name,
"sortable": True,
"url" : cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}),
"class_attrib" : (th_classes and ' class="%s"' % ' '.join(th_classes) or '') }
yield {"text": f.verbose_name,
"sortable": True,
"url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}),
"class_attrib": (th_classes and ' class="%s"' % ' '.join(th_classes) or '')}
def items_for_result(cl, result):
first = True
@ -185,11 +181,10 @@ def results(cl):
def result_list(cl):
res = list(results(cl))
return {'cl': cl,
'result_headers': list(result_headers(cl)),
'results': list(results(cl)), }
'result_headers': list(result_headers(cl)),
'results': list(results(cl))}
result_list = inclusion_tag("admin/change_list_results")(result_list)
#@inclusion_tag("admin/date_hierarchy")
def date_hierarchy(cl):
lookup_opts, params, lookup_params, lookup_mod = \
@ -214,59 +209,67 @@ def date_hierarchy(cl):
if year_lookup and month_lookup and day_lookup:
month_name = MONTHS[int(month_lookup)]
return { 'show': True,
'back':
{ 'link' : link({year_field: year_lookup, month_field: month_lookup}),
'title': "%s %s" % ( month_name, year_lookup),
},
'choices': [ {'title': "%s %s" % ( month_name, day_lookup)} ]
}
return {
'show': True,
'back': {
'link': link({year_field: year_lookup, month_field: month_lookup}),
'title': "%s %s" % (month_name, year_lookup)
},
'choices': [{'title': "%s %s" % (month_name, day_lookup)}]
}
elif year_lookup and month_lookup:
date_lookup_params = lookup_params.copy()
date_lookup_params.update({year_field: year_lookup, month_field: month_lookup})
days = get_dates('day', date_lookup_params)
return { 'show': True,
'back':
{ 'link' : link({year_field: year_lookup}),
'title' : year_lookup
},
'choices':
[ { 'link' : link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
'title': day.strftime('%B %d') } for day in days ]
}
return {
'show': True,
'back': {
'link': link({year_field: year_lookup}),
'title': year_lookup
},
'choices': [{
'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
'title': day.strftime('%B %d')
} for day in days]
}
elif year_lookup:
date_lookup_params = lookup_params.copy()
date_lookup_params.update({year_field: year_lookup})
months = get_dates('month', date_lookup_params)
return { 'show' : True,
'back':
{ 'link' : link({}),
'title': _('All dates')
},
'choices':
[ { 'link': link( {year_field: year_lookup, month_field: month.month}),
'title': "%s %s" % (month.strftime('%B') , month.year) } for month in months ]
}
return {
'show' : True,
'back': {
'link' : link({}),
'title': _('All dates')
},
'choices': [{
'link': link( {year_field: year_lookup, month_field: month.month}),
'title': "%s %s" % (month.strftime('%B') , month.year)
} for month in months]
}
else:
years = get_dates('year', lookup_params)
return { 'show': True,
'choices':
[ { 'link': link( {year_field: year.year}),
'title': year.year } for year in years ]
}
return {
'show': True,
'choices': [{
'link': link({year_field: year.year}),
'title': year.year
} for year in years ]
}
date_hierarchy = inclusion_tag('admin/date_hierarchy')(date_hierarchy)
#@inclusion_tag('admin/search_form')
def search_form(cl):
return { 'cl': cl,
'show_result_count': cl.result_count != cl.full_result_count and not cl.opts.one_to_one_field,
'search_var': SEARCH_VAR }
return {
'cl': cl,
'show_result_count': cl.result_count != cl.full_result_count and not cl.opts.one_to_one_field,
'search_var': SEARCH_VAR
}
search_form = inclusion_tag('admin/search_form')(search_form)
#@inclusion_tag('admin/filter')
def filter(cl, spec):
return {'title': spec.title(),
'choices' : list(spec.choices(cl))}
return {'title': spec.title(), 'choices' : list(spec.choices(cl))}
filter = inclusion_tag('admin/filter')(filter)
#@inclusion_tag('admin/filters')

View File

@ -45,7 +45,6 @@ def _get_mod_opts(app_label, module_name):
raise Http404 # This object is valid but has no admin interface.
return mod, opts
def index(request):
return render_to_response('admin/index', {'title': _('Site administration')}, context_instance=Context(request))
index = staff_member_required(index)
@ -69,7 +68,6 @@ class ChangeList(object):
def get_filters(self, request):
self.filter_specs = []
if self.lookup_opts.admin.list_filter and not self.opts.one_to_one_field:
filter_fields = [self.lookup_opts.get_field(field_name) \
for field_name in self.lookup_opts.admin.list_filter]
@ -77,7 +75,6 @@ class ChangeList(object):
spec = FilterSpec.create(f, request, self.params)
if spec.has_output():
self.filter_specs.append(spec)
self.has_filters = bool(self.filter_specs)
def get_query_string(self, new_params={}, remove=[]):
@ -93,7 +90,6 @@ class ChangeList(object):
p[k] = v
return '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')
def get_modules_and_options(self, app_label, module_name, request):
self.mod, self.opts = _get_mod_opts(app_label, module_name)
if not request.user.has_perm(app_label + '.' + self.opts.get_change_permission()):
@ -331,7 +327,6 @@ class AdminBoundField(BoundField):
def html_error_list(self):
return " ".join([form_field.html_error_list() for form_field in self.form_fields if form_field.errors])
class AdminBoundFieldLine(BoundFieldLine):
def __init__(self, field_line, field_mapping, original):
super(AdminBoundFieldLine, self).__init__(field_line, field_mapping, original, AdminBoundField)
@ -382,7 +377,6 @@ class AdminBoundManipulator(BoundManipulator):
return ""
def render_change_form(opts, manipulator, app_label, context, add=False, change=False, show_delete=False, form_url=''):
extra_context = {
'add': add,
'change': change,
@ -391,13 +385,10 @@ def render_change_form(opts, manipulator, app_label, context, add=False, change=
'form_url' : form_url,
'app_label': app_label,
}
context.update(extra_context)
return render_to_response(["admin/%s/%s/change_form" % (app_label, opts.object_name.lower() ),
"admin/%s/change_form" % app_label ,
"admin/change_form"],
context_instance=context)
"admin/change_form"], context_instance=context)
def log_add_message(user, opts,manipulator,new_object):
pk_value = getattr(new_object, opts.pk.attname)
@ -552,8 +543,6 @@ def change_stage(request, app_label, module_name, object_id):
return render_change_form(opts,manipulator, app_label, c, change=True)
def _nest_help(obj, depth, val):
current = obj
for i in range(depth):