mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +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:
parent
8be7d7e544
commit
12dec8023d
@ -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
|
||||||
|
from django.contrib.admin.views.main import ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR, SEARCH_VAR
|
||||||
from django.contrib.admin.views.main import MAX_SHOW_ALL_ALLOWED, DEFAULT_RESULTS_PER_PAGE, ALL_VAR, \
|
from django.contrib.admin.views.main import IS_POPUP_VAR, EMPTY_CHANGELIST_VALUE, MONTHS
|
||||||
ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR , SEARCH_VAR , IS_POPUP_VAR, EMPTY_CHANGELIST_VALUE, \
|
from django.core import meta, template
|
||||||
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.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.conf.settings import ADMIN_MEDIA_PREFIX
|
from django.core.template.decorators import simple_tag, inclusion_tag
|
||||||
from django.core import template
|
|
||||||
from django.utils import dateformat
|
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 = '.'
|
DOT = '.'
|
||||||
|
|
||||||
#@simple_tag
|
#@simple_tag
|
||||||
@ -20,22 +17,22 @@ def paginator_number(cl,i):
|
|||||||
if i == DOT:
|
if i == DOT:
|
||||||
return '... '
|
return '... '
|
||||||
elif i == cl.page_num:
|
elif i == cl.page_num:
|
||||||
return '<span class="this-page">%d</span> ' % (i+1)
|
return '<span class="this-page">%d</span> ' % (i+1)
|
||||||
else:
|
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)
|
paginator_number = simple_tag(paginator_number)
|
||||||
|
|
||||||
#@inclusion_tag('admin/pagination')
|
#@inclusion_tag('admin/pagination')
|
||||||
def pagination(cl):
|
def pagination(cl):
|
||||||
paginator, page_num = cl.paginator, cl.page_num
|
paginator, page_num = cl.paginator, cl.page_num
|
||||||
|
|
||||||
pagination_required = (not cl.show_all or not cl.can_show_all) and cl.multi_page
|
pagination_required = (not cl.show_all or not cl.can_show_all) and cl.multi_page
|
||||||
if not pagination_required:
|
if not pagination_required:
|
||||||
page_range = []
|
page_range = []
|
||||||
else:
|
else:
|
||||||
ON_EACH_SIDE = 3
|
ON_EACH_SIDE = 3
|
||||||
ON_ENDS = 2
|
ON_ENDS = 2
|
||||||
|
|
||||||
# If there are 10 or fewer pages, display links to every page.
|
# If there are 10 or fewer pages, display links to every page.
|
||||||
# Otherwise, do some fancy
|
# Otherwise, do some fancy
|
||||||
if paginator.pages <= 10:
|
if paginator.pages <= 10:
|
||||||
@ -59,52 +56,51 @@ def pagination(cl):
|
|||||||
page_range.extend(range(page_num + 1, paginator.pages))
|
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
|
need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page
|
||||||
|
return {
|
||||||
return {'cl': cl,
|
'cl': cl,
|
||||||
'pagination_required': pagination_required,
|
'pagination_required': pagination_required,
|
||||||
'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR:''}),
|
'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR: ''}),
|
||||||
'page_range': page_range,
|
'page_range': page_range,
|
||||||
'ALL_VAR': ALL_VAR,
|
'ALL_VAR': ALL_VAR,
|
||||||
'1': 1
|
'1': 1,
|
||||||
}
|
}
|
||||||
pagination = inclusion_tag('admin/pagination')(pagination)
|
pagination = inclusion_tag('admin/pagination')(pagination)
|
||||||
|
|
||||||
|
|
||||||
def result_headers(cl):
|
def result_headers(cl):
|
||||||
lookup_opts = cl.lookup_opts
|
lookup_opts = cl.lookup_opts
|
||||||
|
|
||||||
for i, field_name in enumerate(lookup_opts.admin.list_display):
|
for i, field_name in enumerate(lookup_opts.admin.list_display):
|
||||||
try:
|
try:
|
||||||
f = lookup_opts.get_field(field_name)
|
f = lookup_opts.get_field(field_name)
|
||||||
except meta.FieldDoesNotExist:
|
except meta.FieldDoesNotExist:
|
||||||
# For non-field list_display values, check for the function
|
# For non-field list_display values, check for the function
|
||||||
# attribute "short_description". If that doesn't exist, fall
|
# attribute "short_description". If that doesn't exist, fall
|
||||||
# back to the method name. And __repr__ is a special-case.
|
# back to the method name. And __repr__ is a special-case.
|
||||||
if field_name == '__repr__':
|
if field_name == '__repr__':
|
||||||
header = lookup_opts.verbose_name
|
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}
|
|
||||||
else:
|
else:
|
||||||
if isinstance(f.rel, meta.ManyToOne) and f.null:
|
func = getattr(cl.mod.Klass, field_name) # Let AttributeErrors propogate.
|
||||||
yield {"text": f.verbose_name}
|
try:
|
||||||
else:
|
header = func.short_description
|
||||||
th_classes = []
|
except AttributeError:
|
||||||
new_order_type = 'asc'
|
header = func.__name__.replace('_', ' ')
|
||||||
if field_name == cl.order_field:
|
# Non-field list_display values don't get ordering capability.
|
||||||
th_classes.append('sorted %sending' % cl.order_type.lower())
|
yield {"text": header}
|
||||||
new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()]
|
else:
|
||||||
|
if isinstance(f.rel, meta.ManyToOne) and f.null:
|
||||||
yield {"text" : f.verbose_name,
|
yield {"text": f.verbose_name}
|
||||||
"sortable": True,
|
else:
|
||||||
"url" : cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}),
|
th_classes = []
|
||||||
"class_attrib" : (th_classes and ' class="%s"' % ' '.join(th_classes) or '') }
|
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 '')}
|
||||||
|
|
||||||
def items_for_result(cl, result):
|
def items_for_result(cl, result):
|
||||||
first = True
|
first = True
|
||||||
pk = cl.lookup_opts.pk.attname
|
pk = cl.lookup_opts.pk.attname
|
||||||
@ -121,13 +117,13 @@ def items_for_result(cl, result):
|
|||||||
except AttributeError, ObjectDoesNotExist:
|
except AttributeError, ObjectDoesNotExist:
|
||||||
result_repr = EMPTY_CHANGELIST_VALUE
|
result_repr = EMPTY_CHANGELIST_VALUE
|
||||||
else:
|
else:
|
||||||
# Strip HTML tags in the resulting text, except if the
|
# Strip HTML tags in the resulting text, except if the
|
||||||
# function has an "allow_tags" attribute set to True.
|
# function has an "allow_tags" attribute set to True.
|
||||||
if not getattr(func, 'allow_tags', False):
|
if not getattr(func, 'allow_tags', False):
|
||||||
result_repr = strip_tags(result_repr)
|
result_repr = strip_tags(result_repr)
|
||||||
else:
|
else:
|
||||||
field_val = getattr(result, f.attname)
|
field_val = getattr(result, f.attname)
|
||||||
|
|
||||||
if isinstance(f.rel, meta.ManyToOne):
|
if isinstance(f.rel, meta.ManyToOne):
|
||||||
if field_val is not None:
|
if field_val is not None:
|
||||||
result_repr = getattr(result, 'get_%s' % f.name)()
|
result_repr = getattr(result, 'get_%s' % f.name)()
|
||||||
@ -136,7 +132,7 @@ def items_for_result(cl, result):
|
|||||||
# Dates and times are special: They're formatted in a certain way.
|
# Dates and times are special: They're formatted in a certain way.
|
||||||
elif isinstance(f, meta.DateField) or isinstance(f, meta.TimeField):
|
elif isinstance(f, meta.DateField) or isinstance(f, meta.TimeField):
|
||||||
if field_val:
|
if field_val:
|
||||||
(date_format, datetime_format, time_format) = get_date_formats()
|
(date_format, datetime_format, time_format) = get_date_formats()
|
||||||
if isinstance(f, meta.DateTimeField):
|
if isinstance(f, meta.DateTimeField):
|
||||||
result_repr = capfirst(dateformat.format(field_val, datetime_format))
|
result_repr = capfirst(dateformat.format(field_val, datetime_format))
|
||||||
elif isinstance(f, meta.TimeField):
|
elif isinstance(f, meta.TimeField):
|
||||||
@ -176,7 +172,7 @@ def items_for_result(cl, result):
|
|||||||
(row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr))
|
(row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr))
|
||||||
else:
|
else:
|
||||||
yield ('<td%s>%s</td>' % (row_class, result_repr))
|
yield ('<td%s>%s</td>' % (row_class, result_repr))
|
||||||
|
|
||||||
def results(cl):
|
def results(cl):
|
||||||
for res in cl.result_list:
|
for res in cl.result_list:
|
||||||
yield list(items_for_result(cl,res))
|
yield list(items_for_result(cl,res))
|
||||||
@ -184,20 +180,19 @@ def results(cl):
|
|||||||
#@inclusion_tag("admin/change_list_results")
|
#@inclusion_tag("admin/change_list_results")
|
||||||
def result_list(cl):
|
def result_list(cl):
|
||||||
res = list(results(cl))
|
res = list(results(cl))
|
||||||
return {'cl': cl,
|
return {'cl': cl,
|
||||||
'result_headers': list(result_headers(cl)),
|
'result_headers': list(result_headers(cl)),
|
||||||
'results': list(results(cl)), }
|
'results': list(results(cl))}
|
||||||
result_list = inclusion_tag("admin/change_list_results")(result_list)
|
result_list = inclusion_tag("admin/change_list_results")(result_list)
|
||||||
|
|
||||||
|
|
||||||
#@inclusion_tag("admin/date_hierarchy")
|
#@inclusion_tag("admin/date_hierarchy")
|
||||||
def date_hierarchy(cl):
|
def date_hierarchy(cl):
|
||||||
lookup_opts, params, lookup_params, lookup_mod = \
|
lookup_opts, params, lookup_params, lookup_mod = \
|
||||||
cl.lookup_opts, cl.params, cl.lookup_params, cl.lookup_mod
|
cl.lookup_opts, cl.params, cl.lookup_params, cl.lookup_mod
|
||||||
|
|
||||||
if lookup_opts.admin.date_hierarchy:
|
if lookup_opts.admin.date_hierarchy:
|
||||||
field_name = lookup_opts.admin.date_hierarchy
|
field_name = lookup_opts.admin.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
|
||||||
@ -205,68 +200,76 @@ def date_hierarchy(cl):
|
|||||||
year_lookup = params.get(year_field)
|
year_lookup = params.get(year_field)
|
||||||
month_lookup = params.get(month_field)
|
month_lookup = params.get(month_field)
|
||||||
day_lookup = params.get(day_field)
|
day_lookup = params.get(day_field)
|
||||||
|
|
||||||
def link(d):
|
def link(d):
|
||||||
return cl.get_query_string(d, [field_generic])
|
return cl.get_query_string(d, [field_generic])
|
||||||
|
|
||||||
def get_dates(unit, params):
|
def get_dates(unit, params):
|
||||||
return getattr(lookup_mod, 'get_%s_list' % field_name)(unit, **params)
|
return getattr(lookup_mod, 'get_%s_list' % field_name)(unit, **params)
|
||||||
|
|
||||||
if year_lookup and month_lookup and day_lookup:
|
if year_lookup and month_lookup and day_lookup:
|
||||||
month_name = MONTHS[int(month_lookup)]
|
month_name = MONTHS[int(month_lookup)]
|
||||||
return { 'show': True,
|
return {
|
||||||
'back':
|
'show': True,
|
||||||
{ 'link' : link({year_field: year_lookup, month_field: month_lookup}),
|
'back': {
|
||||||
'title': "%s %s" % ( month_name, year_lookup),
|
'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)} ]
|
},
|
||||||
}
|
'choices': [{'title': "%s %s" % (month_name, day_lookup)}]
|
||||||
|
}
|
||||||
elif year_lookup and month_lookup:
|
elif year_lookup and month_lookup:
|
||||||
date_lookup_params = lookup_params.copy()
|
date_lookup_params = lookup_params.copy()
|
||||||
date_lookup_params.update({year_field: year_lookup, month_field: month_lookup})
|
date_lookup_params.update({year_field: year_lookup, month_field: month_lookup})
|
||||||
days = get_dates('day', date_lookup_params)
|
days = get_dates('day', date_lookup_params)
|
||||||
return { 'show': True,
|
return {
|
||||||
'back':
|
'show': True,
|
||||||
{ 'link' : link({year_field: year_lookup}),
|
'back': {
|
||||||
'title' : year_lookup
|
'link': link({year_field: year_lookup}),
|
||||||
},
|
'title': year_lookup
|
||||||
'choices':
|
},
|
||||||
[ { 'link' : link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
|
'choices': [{
|
||||||
'title': day.strftime('%B %d') } for day in days ]
|
'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:
|
elif year_lookup:
|
||||||
date_lookup_params = lookup_params.copy()
|
date_lookup_params = lookup_params.copy()
|
||||||
date_lookup_params.update({year_field: year_lookup})
|
date_lookup_params.update({year_field: year_lookup})
|
||||||
months = get_dates('month', date_lookup_params)
|
months = get_dates('month', date_lookup_params)
|
||||||
return { 'show' : True,
|
return {
|
||||||
'back':
|
'show' : True,
|
||||||
{ 'link' : link({}),
|
'back': {
|
||||||
'title': _('All dates')
|
'link' : link({}),
|
||||||
},
|
'title': _('All dates')
|
||||||
'choices':
|
},
|
||||||
[ { 'link': link( {year_field: year_lookup, month_field: month.month}),
|
'choices': [{
|
||||||
'title': "%s %s" % (month.strftime('%B') , month.year) } for month in months ]
|
'link': link( {year_field: year_lookup, month_field: month.month}),
|
||||||
}
|
'title': "%s %s" % (month.strftime('%B') , month.year)
|
||||||
|
} for month in months]
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
years = get_dates('year', lookup_params)
|
years = get_dates('year', lookup_params)
|
||||||
return { 'show': True,
|
return {
|
||||||
'choices':
|
'show': True,
|
||||||
[ { 'link': link( {year_field: year.year}),
|
'choices': [{
|
||||||
'title': year.year } for year in years ]
|
'link': link({year_field: year.year}),
|
||||||
}
|
'title': year.year
|
||||||
|
} for year in years ]
|
||||||
|
}
|
||||||
date_hierarchy = inclusion_tag('admin/date_hierarchy')(date_hierarchy)
|
date_hierarchy = inclusion_tag('admin/date_hierarchy')(date_hierarchy)
|
||||||
|
|
||||||
#@inclusion_tag('admin/search_form')
|
#@inclusion_tag('admin/search_form')
|
||||||
def search_form(cl):
|
def search_form(cl):
|
||||||
return { 'cl': cl,
|
return {
|
||||||
'show_result_count': cl.result_count != cl.full_result_count and not cl.opts.one_to_one_field,
|
'cl': cl,
|
||||||
'search_var': SEARCH_VAR }
|
'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)
|
search_form = inclusion_tag('admin/search_form')(search_form)
|
||||||
|
|
||||||
#@inclusion_tag('admin/filter')
|
#@inclusion_tag('admin/filter')
|
||||||
def filter(cl, spec):
|
def filter(cl, spec):
|
||||||
return {'title': spec.title(),
|
return {'title': spec.title(), 'choices' : list(spec.choices(cl))}
|
||||||
'choices' : list(spec.choices(cl))}
|
|
||||||
filter = inclusion_tag('admin/filter')(filter)
|
filter = inclusion_tag('admin/filter')(filter)
|
||||||
|
|
||||||
#@inclusion_tag('admin/filters')
|
#@inclusion_tag('admin/filters')
|
||||||
|
@ -45,7 +45,6 @@ def _get_mod_opts(app_label, module_name):
|
|||||||
raise Http404 # This object is valid but has no admin interface.
|
raise Http404 # This object is valid but has no admin interface.
|
||||||
return mod, opts
|
return mod, opts
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return render_to_response('admin/index', {'title': _('Site administration')}, context_instance=Context(request))
|
return render_to_response('admin/index', {'title': _('Site administration')}, context_instance=Context(request))
|
||||||
index = staff_member_required(index)
|
index = staff_member_required(index)
|
||||||
@ -61,15 +60,14 @@ class ChangeList(object):
|
|||||||
self.query = request.GET.get(SEARCH_VAR,'')
|
self.query = request.GET.get(SEARCH_VAR,'')
|
||||||
self.get_lookup_params()
|
self.get_lookup_params()
|
||||||
self.get_results(request)
|
self.get_results(request)
|
||||||
self.title = (self.is_popup
|
self.title = (self.is_popup
|
||||||
and _('Select %s') % self.opts.verbose_name
|
and _('Select %s') % self.opts.verbose_name
|
||||||
or _('Select %s to change') % self.opts.verbose_name)
|
or _('Select %s to change') % self.opts.verbose_name)
|
||||||
self.get_filters(request)
|
self.get_filters(request)
|
||||||
self.pk_attname = self.lookup_opts.pk.attname
|
self.pk_attname = self.lookup_opts.pk.attname
|
||||||
|
|
||||||
def get_filters(self, request):
|
def get_filters(self, request):
|
||||||
self.filter_specs = []
|
self.filter_specs = []
|
||||||
|
|
||||||
if self.lookup_opts.admin.list_filter and not self.opts.one_to_one_field:
|
if self.lookup_opts.admin.list_filter and not self.opts.one_to_one_field:
|
||||||
filter_fields = [self.lookup_opts.get_field(field_name) \
|
filter_fields = [self.lookup_opts.get_field(field_name) \
|
||||||
for field_name in self.lookup_opts.admin.list_filter]
|
for field_name in self.lookup_opts.admin.list_filter]
|
||||||
@ -77,9 +75,8 @@ class ChangeList(object):
|
|||||||
spec = FilterSpec.create(f, request, self.params)
|
spec = FilterSpec.create(f, request, self.params)
|
||||||
if spec.has_output():
|
if spec.has_output():
|
||||||
self.filter_specs.append(spec)
|
self.filter_specs.append(spec)
|
||||||
|
|
||||||
self.has_filters = bool(self.filter_specs)
|
self.has_filters = bool(self.filter_specs)
|
||||||
|
|
||||||
def get_query_string(self, new_params={}, remove=[]):
|
def get_query_string(self, new_params={}, remove=[]):
|
||||||
p = self.params.copy()
|
p = self.params.copy()
|
||||||
for r in remove:
|
for r in remove:
|
||||||
@ -92,13 +89,12 @@ class ChangeList(object):
|
|||||||
elif v is not None:
|
elif v is not None:
|
||||||
p[k] = v
|
p[k] = v
|
||||||
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_modules_and_options(self, app_label, module_name, request):
|
def get_modules_and_options(self, app_label, module_name, request):
|
||||||
self.mod, self.opts = _get_mod_opts(app_label, module_name)
|
self.mod, self.opts = _get_mod_opts(app_label, module_name)
|
||||||
if not request.user.has_perm(app_label + '.' + self.opts.get_change_permission()):
|
if not request.user.has_perm(app_label + '.' + self.opts.get_change_permission()):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
self.lookup_mod, self.lookup_opts = self.mod, self.opts
|
self.lookup_mod, self.lookup_opts = self.mod, self.opts
|
||||||
|
|
||||||
def get_search_parameters(self, request):
|
def get_search_parameters(self, request):
|
||||||
@ -113,7 +109,7 @@ class ChangeList(object):
|
|||||||
self.params = dict(request.GET.copy())
|
self.params = dict(request.GET.copy())
|
||||||
if self.params.has_key(PAGE_VAR):
|
if self.params.has_key(PAGE_VAR):
|
||||||
del self.params[PAGE_VAR]
|
del self.params[PAGE_VAR]
|
||||||
|
|
||||||
def get_results(self, request):
|
def get_results(self, request):
|
||||||
lookup_mod, lookup_params, show_all, page_num = \
|
lookup_mod, lookup_params, show_all, page_num = \
|
||||||
self.lookup_mod, self.lookup_params, self.show_all, self.page_num
|
self.lookup_mod, self.lookup_params, self.show_all, self.page_num
|
||||||
@ -126,7 +122,7 @@ class ChangeList(object):
|
|||||||
# error).
|
# error).
|
||||||
except:
|
except:
|
||||||
raise IncorrectLookupParameters()
|
raise IncorrectLookupParameters()
|
||||||
|
|
||||||
# Get the total number of objects, with no filters applied.
|
# Get the total number of objects, with no filters applied.
|
||||||
real_lookup_params = lookup_params.copy()
|
real_lookup_params = lookup_params.copy()
|
||||||
del real_lookup_params['order_by']
|
del real_lookup_params['order_by']
|
||||||
@ -138,7 +134,7 @@ class ChangeList(object):
|
|||||||
result_count = paginator.hits
|
result_count = paginator.hits
|
||||||
can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
|
can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED
|
||||||
multi_page = result_count > DEFAULT_RESULTS_PER_PAGE
|
multi_page = result_count > DEFAULT_RESULTS_PER_PAGE
|
||||||
|
|
||||||
# Get the list of objects to display on this page.
|
# Get the list of objects to display on this page.
|
||||||
if (show_all and can_show_all) or not multi_page:
|
if (show_all and can_show_all) or not multi_page:
|
||||||
result_list = lookup_mod.get_list(**lookup_params)
|
result_list = lookup_mod.get_list(**lookup_params)
|
||||||
@ -147,13 +143,13 @@ class ChangeList(object):
|
|||||||
result_list = paginator.get_page(page_num)
|
result_list = paginator.get_page(page_num)
|
||||||
except InvalidPage:
|
except InvalidPage:
|
||||||
result_list = []
|
result_list = []
|
||||||
(self.result_count, self.full_result_count, self.result_list,
|
(self.result_count, self.full_result_count, self.result_list,
|
||||||
self.can_show_all, self.multi_page, self.paginator) = (result_count,
|
self.can_show_all, self.multi_page, self.paginator) = (result_count,
|
||||||
full_result_count, result_list, can_show_all, multi_page, paginator )
|
full_result_count, result_list, can_show_all, multi_page, paginator )
|
||||||
|
|
||||||
def url_for_result(self, result):
|
def url_for_result(self, result):
|
||||||
return "%s/" % getattr(result, self.pk_attname)
|
return "%s/" % getattr(result, self.pk_attname)
|
||||||
|
|
||||||
def get_ordering(self):
|
def get_ordering(self):
|
||||||
lookup_opts, params = self.lookup_opts, self.params
|
lookup_opts, params = self.lookup_opts, self.params
|
||||||
# For ordering, first check the "ordering" parameter in the admin options,
|
# For ordering, first check the "ordering" parameter in the admin options,
|
||||||
@ -161,10 +157,10 @@ class ChangeList(object):
|
|||||||
# order descending by ID by default. Finally, look for manually-specified
|
# order descending by ID by default. Finally, look for manually-specified
|
||||||
# ordering from the query string.
|
# ordering from the query string.
|
||||||
ordering = lookup_opts.admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name]
|
ordering = lookup_opts.admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name]
|
||||||
|
|
||||||
# Normalize it to new-style ordering.
|
# Normalize it to new-style ordering.
|
||||||
ordering = meta.handle_legacy_orderlist(ordering)
|
ordering = meta.handle_legacy_orderlist(ordering)
|
||||||
|
|
||||||
if ordering[0].startswith('-'):
|
if ordering[0].startswith('-'):
|
||||||
order_field, order_type = ordering[0][1:], 'desc'
|
order_field, order_type = ordering[0][1:], 'desc'
|
||||||
else:
|
else:
|
||||||
@ -183,12 +179,12 @@ class ChangeList(object):
|
|||||||
if params.has_key(ORDER_TYPE_VAR) and params[ORDER_TYPE_VAR] in ('asc', 'desc'):
|
if params.has_key(ORDER_TYPE_VAR) and params[ORDER_TYPE_VAR] in ('asc', 'desc'):
|
||||||
order_type = params[ORDER_TYPE_VAR]
|
order_type = params[ORDER_TYPE_VAR]
|
||||||
self.order_field, self.order_type = order_field, order_type
|
self.order_field, self.order_type = order_field, order_type
|
||||||
|
|
||||||
def get_lookup_params(self):
|
def get_lookup_params(self):
|
||||||
# Prepare the lookup parameters for the API lookup.
|
# Prepare the lookup parameters for the API lookup.
|
||||||
(params, order_field, lookup_opts, order_type, opts, query) = \
|
(params, order_field, lookup_opts, order_type, opts, query) = \
|
||||||
(self.params, self.order_field, self.lookup_opts, self.order_type, self.opts, self.query)
|
(self.params, self.order_field, self.lookup_opts, self.order_type, self.opts, self.query)
|
||||||
|
|
||||||
lookup_params = params.copy()
|
lookup_params = params.copy()
|
||||||
for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR):
|
for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR):
|
||||||
if lookup_params.has_key(i):
|
if lookup_params.has_key(i):
|
||||||
@ -196,7 +192,7 @@ class ChangeList(object):
|
|||||||
# If the order-by field is a field with a relationship, order by the value
|
# If the order-by field is a field with a relationship, order by the value
|
||||||
# in the related table.
|
# in the related table.
|
||||||
lookup_order_field = order_field
|
lookup_order_field = order_field
|
||||||
try:
|
try:
|
||||||
f = lookup_opts.get_field(order_field)
|
f = lookup_opts.get_field(order_field)
|
||||||
except meta.FieldDoesNotExist:
|
except meta.FieldDoesNotExist:
|
||||||
pass
|
pass
|
||||||
@ -228,25 +224,25 @@ class ChangeList(object):
|
|||||||
or_query.append(('%s__icontains' % field_name, bit))
|
or_query.append(('%s__icontains' % field_name, bit))
|
||||||
or_queries.append(or_query)
|
or_queries.append(or_query)
|
||||||
lookup_params['_or'] = or_queries
|
lookup_params['_or'] = or_queries
|
||||||
|
|
||||||
if opts.one_to_one_field:
|
if opts.one_to_one_field:
|
||||||
lookup_params.update(opts.one_to_one_field.rel.limit_choices_to)
|
lookup_params.update(opts.one_to_one_field.rel.limit_choices_to)
|
||||||
self.lookup_params = lookup_params
|
self.lookup_params = lookup_params
|
||||||
|
|
||||||
|
|
||||||
def change_list(request, app_label, module_name):
|
def change_list(request, app_label, module_name):
|
||||||
try:
|
try:
|
||||||
cl = ChangeList(request, app_label, module_name)
|
cl = ChangeList(request, app_label, module_name)
|
||||||
except IncorrectLookupParameters:
|
except IncorrectLookupParameters:
|
||||||
return HttpResponseRedirect(request.path)
|
return HttpResponseRedirect(request.path)
|
||||||
|
|
||||||
c = Context(request, {
|
c = Context(request, {
|
||||||
'title': cl.title,
|
'title': cl.title,
|
||||||
'is_popup': cl.is_popup,
|
'is_popup': cl.is_popup,
|
||||||
'cl' : cl
|
'cl' : cl
|
||||||
})
|
})
|
||||||
c.update( { 'has_add_permission': c['perms'][app_label][cl.opts.get_add_permission()]}),
|
c.update( { 'has_add_permission': c['perms'][app_label][cl.opts.get_add_permission()]}),
|
||||||
return render_to_response('admin/change_list',
|
return render_to_response('admin/change_list',
|
||||||
context_instance = c)
|
context_instance = c)
|
||||||
change_list = staff_member_required(change_list)
|
change_list = staff_member_required(change_list)
|
||||||
|
|
||||||
@ -270,7 +266,7 @@ def get_javascript_imports(opts,auto_populated_fields, ordered_objects, field_se
|
|||||||
if not seen_collapse and 'collapse' in field_set.classes:
|
if not seen_collapse and 'collapse' in field_set.classes:
|
||||||
seen_collapse = True
|
seen_collapse = True
|
||||||
js.append('js/admin/CollapsedFieldsets.js' )
|
js.append('js/admin/CollapsedFieldsets.js' )
|
||||||
|
|
||||||
for field_line in field_set:
|
for field_line in field_set:
|
||||||
try:
|
try:
|
||||||
for f in field_line:
|
for f in field_line:
|
||||||
@ -284,9 +280,9 @@ def get_javascript_imports(opts,auto_populated_fields, ordered_objects, field_se
|
|||||||
|
|
||||||
class AdminBoundField(BoundField):
|
class AdminBoundField(BoundField):
|
||||||
def __init__(self, field, field_mapping, original):
|
def __init__(self, field, field_mapping, original):
|
||||||
super(AdminBoundField, self).__init__(field,field_mapping,original)
|
super(AdminBoundField, self).__init__(field,field_mapping,original)
|
||||||
|
|
||||||
self.element_id = self.form_fields[0].get_id()
|
self.element_id = self.form_fields[0].get_id()
|
||||||
self.has_label_first = not isinstance(self.field, meta.BooleanField)
|
self.has_label_first = not isinstance(self.field, meta.BooleanField)
|
||||||
self.raw_id_admin = use_raw_id_admin(field)
|
self.raw_id_admin = use_raw_id_admin(field)
|
||||||
self.is_date_time = isinstance(field, meta.DateTimeField)
|
self.is_date_time = isinstance(field, meta.DateTimeField)
|
||||||
@ -294,33 +290,33 @@ class AdminBoundField(BoundField):
|
|||||||
self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToMany) and field.rel.to.admin
|
self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToMany) and field.rel.to.admin
|
||||||
self.hidden = isinstance(self.field, meta.AutoField)
|
self.hidden = isinstance(self.field, meta.AutoField)
|
||||||
self.first = False
|
self.first = False
|
||||||
|
|
||||||
classes = []
|
classes = []
|
||||||
if(self.raw_id_admin):
|
if(self.raw_id_admin):
|
||||||
classes.append('nowrap')
|
classes.append('nowrap')
|
||||||
if max([bool(f.errors()) for f in self.form_fields]):
|
if max([bool(f.errors()) for f in self.form_fields]):
|
||||||
classes.append('error')
|
classes.append('error')
|
||||||
if classes:
|
if classes:
|
||||||
self.cell_class_attribute = ' class="%s" ' % ' '.join(classes)
|
self.cell_class_attribute = ' class="%s" ' % ' '.join(classes)
|
||||||
self._repr_filled = False
|
self._repr_filled = False
|
||||||
|
|
||||||
def _fetch_existing_display(self, func_name):
|
def _fetch_existing_display(self, func_name):
|
||||||
class_dict = self.original.__class__.__dict__
|
class_dict = self.original.__class__.__dict__
|
||||||
func = class_dict.get(func_name)
|
func = class_dict.get(func_name)
|
||||||
return func(self.original)
|
return func(self.original)
|
||||||
|
|
||||||
def _fill_existing_display(self):
|
def _fill_existing_display(self):
|
||||||
if self._display_filled:
|
if self._display_filled:
|
||||||
return
|
return
|
||||||
#HACK
|
#HACK
|
||||||
if isinstance(self.field.rel, meta.ManyToOne):
|
if isinstance(self.field.rel, meta.ManyToOne):
|
||||||
func_name = 'get_%s' % self.field.name
|
func_name = 'get_%s' % self.field.name
|
||||||
self._display = self._fetch_existing_display(func_name)
|
self._display = self._fetch_existing_display(func_name)
|
||||||
elif isinstance(self.field.rel, meta.ManyToMany):
|
elif isinstance(self.field.rel, meta.ManyToMany):
|
||||||
func_name = 'get_%s_list' % self.field.name
|
func_name = 'get_%s_list' % self.field.name
|
||||||
self._display = ",".join(self._fetch_existing_display(func_name))
|
self._display = ",".join(self._fetch_existing_display(func_name))
|
||||||
self._display_filled = True
|
self._display_filled = True
|
||||||
|
|
||||||
def existing_display(self):
|
def existing_display(self):
|
||||||
self._fill_existing_display()
|
self._fill_existing_display()
|
||||||
return self._display
|
return self._display
|
||||||
@ -329,8 +325,7 @@ class AdminBoundField(BoundField):
|
|||||||
return repr(self.__dict__)
|
return repr(self.__dict__)
|
||||||
|
|
||||||
def html_error_list(self):
|
def html_error_list(self):
|
||||||
return " ".join([form_field.html_error_list() for form_field in self.form_fields if form_field.errors])
|
return " ".join([form_field.html_error_list() for form_field in self.form_fields if form_field.errors])
|
||||||
|
|
||||||
|
|
||||||
class AdminBoundFieldLine(BoundFieldLine):
|
class AdminBoundFieldLine(BoundFieldLine):
|
||||||
def __init__(self, field_line, field_mapping, original):
|
def __init__(self, field_line, field_mapping, original):
|
||||||
@ -342,12 +337,12 @@ class AdminBoundFieldLine(BoundFieldLine):
|
|||||||
class AdminBoundFieldSet(BoundFieldSet):
|
class AdminBoundFieldSet(BoundFieldSet):
|
||||||
def __init__(self, field_set, field_mapping, original):
|
def __init__(self, field_set, field_mapping, original):
|
||||||
super(AdminBoundFieldSet, self).__init__(field_set, field_mapping, original, AdminBoundFieldLine)
|
super(AdminBoundFieldSet, self).__init__(field_set, field_mapping, original, AdminBoundFieldLine)
|
||||||
|
|
||||||
class BoundManipulator(object):
|
class BoundManipulator(object):
|
||||||
def __init__(self, opts, manipulator, field_mapping):
|
def __init__(self, opts, manipulator, field_mapping):
|
||||||
self.inline_related_objects = opts.get_followed_related_objects(manipulator.follow)
|
self.inline_related_objects = opts.get_followed_related_objects(manipulator.follow)
|
||||||
self.original = hasattr(manipulator, 'original_object') and manipulator.original_object or None
|
self.original = hasattr(manipulator, 'original_object') and manipulator.original_object or None
|
||||||
self.bound_field_sets = [field_set.bind(field_mapping, self.original, AdminBoundFieldSet)
|
self.bound_field_sets = [field_set.bind(field_mapping, self.original, AdminBoundFieldSet)
|
||||||
for field_set in opts.admin.get_field_sets(opts)]
|
for field_set in opts.admin.get_field_sets(opts)]
|
||||||
self.ordered_objects = opts.get_ordered_objects()[:]
|
self.ordered_objects = opts.get_ordered_objects()[:]
|
||||||
|
|
||||||
@ -355,34 +350,33 @@ class AdminBoundManipulator(BoundManipulator):
|
|||||||
def __init__(self, opts, manipulator, field_mapping):
|
def __init__(self, opts, manipulator, field_mapping):
|
||||||
super(AdminBoundManipulator, self).__init__(opts, manipulator, field_mapping)
|
super(AdminBoundManipulator, self).__init__(opts, manipulator, field_mapping)
|
||||||
field_sets = opts.admin.get_field_sets(opts)
|
field_sets = opts.admin.get_field_sets(opts)
|
||||||
|
|
||||||
self.auto_populated_fields = [f for f in opts.fields if f.prepopulate_from]
|
self.auto_populated_fields = [f for f in opts.fields if f.prepopulate_from]
|
||||||
self.javascript_imports = get_javascript_imports(opts, self.auto_populated_fields, self.ordered_objects, field_sets);
|
self.javascript_imports = get_javascript_imports(opts, self.auto_populated_fields, self.ordered_objects, field_sets);
|
||||||
|
|
||||||
self.coltype = self.ordered_objects and 'colMS' or 'colM'
|
self.coltype = self.ordered_objects and 'colMS' or 'colM'
|
||||||
self.has_absolute_url = hasattr(opts.get_model_module().Klass, 'get_absolute_url')
|
self.has_absolute_url = hasattr(opts.get_model_module().Klass, 'get_absolute_url')
|
||||||
self.form_enc_attrib = opts.has_field_type(meta.FileField) and \
|
self.form_enc_attrib = opts.has_field_type(meta.FileField) and \
|
||||||
'enctype="multipart/form-data" ' or ''
|
'enctype="multipart/form-data" ' or ''
|
||||||
|
|
||||||
self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id();
|
self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id();
|
||||||
self.ordered_object_pk_names = [o.pk.name for o in self.ordered_objects]
|
self.ordered_object_pk_names = [o.pk.name for o in self.ordered_objects]
|
||||||
|
|
||||||
self.save_on_top = opts.admin.save_on_top
|
self.save_on_top = opts.admin.save_on_top
|
||||||
self.save_as = opts.admin.save_as
|
self.save_as = opts.admin.save_as
|
||||||
|
|
||||||
self.content_type_id = opts.get_content_type_id()
|
self.content_type_id = opts.get_content_type_id()
|
||||||
self.verbose_name_plural = opts.verbose_name_plural
|
self.verbose_name_plural = opts.verbose_name_plural
|
||||||
self.verbose_name = opts.verbose_name
|
self.verbose_name = opts.verbose_name
|
||||||
self.object_name = opts.object_name
|
self.object_name = opts.object_name
|
||||||
|
|
||||||
def get_ordered_object_pk(self, ordered_obj):
|
def get_ordered_object_pk(self, ordered_obj):
|
||||||
for name in self.ordered_object_pk_names:
|
for name in self.ordered_object_pk_names:
|
||||||
if hasattr(ordered_obj, name):
|
if hasattr(ordered_obj, name):
|
||||||
return str(getattr(ordered_obj, name))
|
return str(getattr(ordered_obj, name))
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def render_change_form(opts, manipulator, app_label, context, add=False, change=False, show_delete=False, form_url=''):
|
def render_change_form(opts, manipulator, app_label, context, add=False, change=False, show_delete=False, form_url=''):
|
||||||
|
|
||||||
extra_context = {
|
extra_context = {
|
||||||
'add': add,
|
'add': add,
|
||||||
'change': change,
|
'change': change,
|
||||||
@ -391,14 +385,11 @@ def render_change_form(opts, manipulator, app_label, context, add=False, change=
|
|||||||
'form_url' : form_url,
|
'form_url' : form_url,
|
||||||
'app_label': app_label,
|
'app_label': app_label,
|
||||||
}
|
}
|
||||||
|
|
||||||
context.update(extra_context)
|
context.update(extra_context)
|
||||||
|
return render_to_response(["admin/%s/%s/change_form" % (app_label, opts.object_name.lower() ),
|
||||||
return render_to_response(["admin/%s/%s/change_form" % (app_label, opts.object_name.lower() ),
|
"admin/%s/change_form" % app_label ,
|
||||||
"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):
|
def log_add_message(user, opts,manipulator,new_object):
|
||||||
pk_value = getattr(new_object, opts.pk.attname)
|
pk_value = getattr(new_object, opts.pk.attname)
|
||||||
log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.ADDITION)
|
log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.ADDITION)
|
||||||
@ -414,7 +405,7 @@ def add_stage(request, app_label, module_name, show_delete=False, form_url='', p
|
|||||||
new_data.update(request.FILES)
|
new_data.update(request.FILES)
|
||||||
errors = manipulator.get_validation_errors(new_data)
|
errors = manipulator.get_validation_errors(new_data)
|
||||||
manipulator.do_html2python(new_data)
|
manipulator.do_html2python(new_data)
|
||||||
|
|
||||||
if not errors and not request.POST.has_key("_preview"):
|
if not errors and not request.POST.has_key("_preview"):
|
||||||
new_object = manipulator.save(new_data)
|
new_object = manipulator.save(new_data)
|
||||||
log_add_message(request.user, opts,manipulator,new_object)
|
log_add_message(request.user, opts,manipulator,new_object)
|
||||||
@ -439,14 +430,14 @@ def add_stage(request, app_label, module_name, show_delete=False, form_url='', p
|
|||||||
else:
|
else:
|
||||||
# Add default data.
|
# Add default data.
|
||||||
new_data = manipulator.flatten_data()
|
new_data = manipulator.flatten_data()
|
||||||
|
|
||||||
# Override the defaults with request.GET, if it exists.
|
# Override the defaults with request.GET, if it exists.
|
||||||
new_data.update(request.GET)
|
new_data.update(request.GET)
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
# Populate the FormWrapper.
|
# Populate the FormWrapper.
|
||||||
form = formfields.FormWrapper(manipulator, new_data, errors, edit_inline=True)
|
form = formfields.FormWrapper(manipulator, new_data, errors, edit_inline=True)
|
||||||
|
|
||||||
c = Context(request, {
|
c = Context(request, {
|
||||||
'title': _('Add %s') % opts.verbose_name,
|
'title': _('Add %s') % opts.verbose_name,
|
||||||
'form': form,
|
'form': form,
|
||||||
@ -455,7 +446,7 @@ def add_stage(request, app_label, module_name, show_delete=False, form_url='', p
|
|||||||
})
|
})
|
||||||
if object_id_override is not None:
|
if object_id_override is not None:
|
||||||
c['object_id'] = object_id_override
|
c['object_id'] = object_id_override
|
||||||
|
|
||||||
return render_change_form(opts, manipulator, app_label, c, add=True)
|
return render_change_form(opts, manipulator, app_label, c, add=True)
|
||||||
add_stage = staff_member_required(add_stage)
|
add_stage = staff_member_required(add_stage)
|
||||||
|
|
||||||
@ -473,7 +464,7 @@ def log_change_message(user, opts,manipulator,new_object):
|
|||||||
if not change_message:
|
if not change_message:
|
||||||
change_message = _('No fields changed.')
|
change_message = _('No fields changed.')
|
||||||
log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.CHANGE, change_message)
|
log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.CHANGE, change_message)
|
||||||
|
|
||||||
def change_stage(request, app_label, module_name, object_id):
|
def change_stage(request, app_label, module_name, object_id):
|
||||||
mod, opts = _get_mod_opts(app_label, module_name)
|
mod, opts = _get_mod_opts(app_label, module_name)
|
||||||
if not request.user.has_perm(app_label + '.' + opts.get_change_permission()):
|
if not request.user.has_perm(app_label + '.' + opts.get_change_permission()):
|
||||||
@ -491,7 +482,7 @@ def change_stage(request, app_label, module_name, object_id):
|
|||||||
new_data.update(request.FILES)
|
new_data.update(request.FILES)
|
||||||
|
|
||||||
errors = manipulator.get_validation_errors(new_data)
|
errors = manipulator.get_validation_errors(new_data)
|
||||||
|
|
||||||
manipulator.do_html2python(new_data)
|
manipulator.do_html2python(new_data)
|
||||||
if not errors and not request.POST.has_key("_preview"):
|
if not errors and not request.POST.has_key("_preview"):
|
||||||
new_object = manipulator.save(new_data)
|
new_object = manipulator.save(new_data)
|
||||||
@ -516,11 +507,11 @@ def change_stage(request, app_label, module_name, object_id):
|
|||||||
else:
|
else:
|
||||||
# Populate new_data with a "flattened" version of the current data.
|
# Populate new_data with a "flattened" version of the current data.
|
||||||
new_data = manipulator.flatten_data()
|
new_data = manipulator.flatten_data()
|
||||||
|
|
||||||
# TODO: do this in flatten_data...
|
# TODO: do this in flatten_data...
|
||||||
# If the object has ordered objects on its admin page, get the existing
|
# If the object has ordered objects on its admin page, get the existing
|
||||||
# order and flatten it into a comma-separated list of IDs.
|
# order and flatten it into a comma-separated list of IDs.
|
||||||
|
|
||||||
id_order_list = []
|
id_order_list = []
|
||||||
for rel_obj in opts.get_ordered_objects():
|
for rel_obj in opts.get_ordered_objects():
|
||||||
id_order_list.extend(getattr(manipulator.original_object, 'get_%s_order' % rel_obj.object_name.lower())())
|
id_order_list.extend(getattr(manipulator.original_object, 'get_%s_order' % rel_obj.object_name.lower())())
|
||||||
@ -532,16 +523,16 @@ def change_stage(request, app_label, module_name, object_id):
|
|||||||
form = formfields.FormWrapper(manipulator, new_data, errors, edit_inline = True)
|
form = formfields.FormWrapper(manipulator, new_data, errors, edit_inline = True)
|
||||||
form.original = manipulator.original_object
|
form.original = manipulator.original_object
|
||||||
form.order_objects = []
|
form.order_objects = []
|
||||||
|
|
||||||
#TODO Should be done in flatten_data / FormWrapper construction
|
#TODO Should be done in flatten_data / FormWrapper construction
|
||||||
for related in opts.get_followed_related_objects():
|
for related in opts.get_followed_related_objects():
|
||||||
wrt = related.opts.order_with_respect_to
|
wrt = related.opts.order_with_respect_to
|
||||||
if wrt and wrt.rel and wrt.rel.to == opts:
|
if wrt and wrt.rel and wrt.rel.to == opts:
|
||||||
func = getattr(manipulator.original_object, 'get_%s_list' %
|
func = getattr(manipulator.original_object, 'get_%s_list' %
|
||||||
related.get_method_name_part())
|
related.get_method_name_part())
|
||||||
orig_list = func()
|
orig_list = func()
|
||||||
form.order_objects.extend(orig_list)
|
form.order_objects.extend(orig_list)
|
||||||
|
|
||||||
c = Context(request, {
|
c = Context(request, {
|
||||||
'title': _('Change %s') % opts.verbose_name,
|
'title': _('Change %s') % opts.verbose_name,
|
||||||
'form': form,
|
'form': form,
|
||||||
@ -551,8 +542,6 @@ def change_stage(request, app_label, module_name, object_id):
|
|||||||
})
|
})
|
||||||
|
|
||||||
return render_change_form(opts,manipulator, app_label, c, change=True)
|
return render_change_form(opts,manipulator, app_label, c, change=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _nest_help(obj, depth, val):
|
def _nest_help(obj, depth, val):
|
||||||
current = obj
|
current = obj
|
||||||
|
Loading…
x
Reference in New Issue
Block a user