Ticket #615: admin.patch
File admin.patch, 5.0 KB (added by , 19 years ago) |
---|
-
django/views/admin/main.py
5 5 from django.core.extensions import DjangoContext as Context 6 6 from django.core.extensions import get_object_or_404, render_to_response 7 7 from django.models.auth import log 8 from django.utils.html import strip_tags8 from django.utils.html import escape 9 9 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect 10 10 from django.utils.text import capfirst, get_text_list 11 11 from django.conf.settings import ADMIN_MEDIA_PREFIX … … 383 383 # For non-field list_display values, the value is a method 384 384 # name. Execute the method. 385 385 try: 386 result_repr = strip_tags(str(getattr(result, field_name)()))386 result_repr = escape(str(getattr(result, field_name)())) 387 387 except ObjectDoesNotExist: 388 388 result_repr = EMPTY_CHANGELIST_VALUE 389 389 else: … … 392 392 # related object. 393 393 if isinstance(f.rel, meta.ManyToOne): 394 394 if field_val is not None: 395 result_repr = getattr(result, 'get_%s' % f.name)()395 result_repr = escape(getattr(result, 'get_%s' % f.name)()) 396 396 else: 397 397 result_repr = EMPTY_CHANGELIST_VALUE 398 398 # Dates are special: They're formatted in a certain way. … … 422 422 # Fields with choices are special: Use the representation 423 423 # of the choice. 424 424 elif f.choices: 425 result_repr = dict(f.choices).get(field_val, EMPTY_CHANGELIST_VALUE)425 result_repr = escape(dict(f.choices).get(field_val, EMPTY_CHANGELIST_VALUE)) 426 426 else: 427 result_repr = strip_tags(str(field_val))427 result_repr = escape(str(field_val)) 428 428 # Some browsers don't like empty "<td></td>"s. 429 429 if result_repr == '': 430 430 result_repr = ' ' … … 1024 1024 if rel_field.rel.edit_inline or not rel_opts.admin: 1025 1025 # Don't display link to edit, because it either has no 1026 1026 # admin or is edited inline. 1027 nh(deleted_objects, current_depth, ['%s: %s' % (capfirst(rel_opts.verbose_name), strip_tags(repr(sub_obj))), []])1027 nh(deleted_objects, current_depth, ['%s: %s' % (capfirst(rel_opts.verbose_name), escape(repr(sub_obj))), []]) 1028 1028 else: 1029 1029 # Display a link to the admin page. 1030 1030 nh(deleted_objects, current_depth, ['%s: <a href="../../../../%s/%s/%s/">%s</a>' % \ 1031 (capfirst(rel_opts.verbose_name), rel_opts.app_label, rel_opts.module_name, sub_obj.id, strip_tags(repr(sub_obj))), []])1031 (capfirst(rel_opts.verbose_name), rel_opts.app_label, rel_opts.module_name, sub_obj.id, escape(repr(sub_obj))), []]) 1032 1032 _get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, rel_opts, current_depth+2) 1033 1033 # If there were related objects, and the user doesn't have 1034 1034 # permission to delete them, add the missing perm to perms_needed. … … 1048 1048 # Don't display link to edit, because it either has no 1049 1049 # admin or is edited inline. 1050 1050 nh(deleted_objects, current_depth, ['One or more %s in %s: %s' % \ 1051 (rel_field.name, rel_opts.verbose_name, strip_tags(repr(sub_obj))), []])1051 (rel_field.name, rel_opts.verbose_name, escape(repr(sub_obj))), []]) 1052 1052 else: 1053 1053 # Display a link to the admin page. 1054 1054 nh(deleted_objects, current_depth, ['One or more %s in %s: <a href="../../../../%s/%s/%s/">%s</a>' % \ 1055 (rel_field.name, rel_opts.verbose_name, rel_opts.app_label, rel_opts.module_name, sub_obj.id, strip_tags(repr(sub_obj))), []])1055 (rel_field.name, rel_opts.verbose_name, rel_opts.app_label, rel_opts.module_name, sub_obj.id, escape(repr(sub_obj))), []]) 1056 1056 # If there were related objects, and the user doesn't have 1057 1057 # permission to change them, add the missing perm to perms_needed. 1058 1058 if rel_opts.admin and has_related_objs: … … 1069 1069 1070 1070 # Populate deleted_objects, a data structure of all related objects that 1071 1071 # will also be deleted. 1072 deleted_objects = ['%s: <a href="../../%s/">%s</a>' % (capfirst(opts.verbose_name), object_id, strip_tags(repr(obj))), []]1072 deleted_objects = ['%s: <a href="../../%s/">%s</a>' % (capfirst(opts.verbose_name), object_id, escape(repr(obj))), []] 1073 1073 perms_needed = sets.Set() 1074 1074 _get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1) 1075 1075