MCPcopy
hub / github.com/django/django / format_callback

Function format_callback

django/contrib/admin/utils.py:148–181  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

146 perms_needed = set()
147
148 def format_callback(obj):
149 model = obj.__class__
150 opts = obj._meta
151
152 no_edit_link = "%s: %s" % (capfirst(opts.verbose_name), obj)
153
154 if admin_site.is_registered(model):
155 if not admin_site.get_model_admin(model).has_delete_permission(
156 request, obj
157 ):
158 perms_needed.add(opts.verbose_name)
159 try:
160 admin_url = reverse(
161 "%s:%s_%s_change"
162 % (admin_site.name, opts.app_label, opts.model_name),
163 None,
164 (quote(obj.pk),),
165 )
166 except NoReverseMatch:
167 # Change url doesn't exist -- don't display link to edit
168 return no_edit_link
169
170 # Display a link to the admin page.
171 obj_display = display_for_value(str(obj), EMPTY_VALUE_STRING)
172 return format_html(
173 '{}: <a href="{}">{}</a>',
174 capfirst(opts.verbose_name),
175 admin_url,
176 obj_display,
177 )
178 else:
179 # Don't display link to edit, because it either has no
180 # admin or is edited inline.
181 return no_edit_link
182
183 to_delete = collector.nested(format_callback)
184

Callers 2

get_deleted_objectsFunction · 0.85
_nestedMethod · 0.85

Calls 9

capfirstFunction · 0.90
reverseFunction · 0.90
format_htmlFunction · 0.90
quoteFunction · 0.85
display_for_valueFunction · 0.85
is_registeredMethod · 0.80
get_model_adminMethod · 0.80
has_delete_permissionMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected