def handle_protectederror(obj, request, e):
 dependent_objects = e[1]
 try:
  dep_class = dependent_objects[0]._meta.verbose_name_plural
 except IndexError:
  raise e
 if (type(obj) in (list, tuple)):
  err_message = 'Unable to delete the requested {}. The following dependent {} were found: '.format(obj[0]._meta.verbose_name_plural, dep_class)
 else:
  err_message = 'Unable to delete {} {}. The following dependent {} were found: '.format(obj._meta.verbose_name, obj, dep_class)
 dependent_objects = []
 for o in e[1]:
  if hasattr(o, 'get_absolute_url'):
   dependent_objects.append('<a href="{}">{}</a>'.format(o.get_absolute_url(), str(o)))
  else:
   dependent_objects.append(str(o))
 err_message += ', '.join(dependent_objects)
 messages.error(request, err_message)

def handle_protectederror ( obj , request , e ) : dependent_objects = e [ 1 ] try : dep_class = dependent_objects [ 0 ] . _meta . verbose_name_plural except IndexError : raise e if ( type ( obj ) in ( list , tuple ) ) : err_message = 'Unable to delete the requested {}. The following dependent {} were found: ' . format ( obj [ 0 ] . _meta . verbose_name_plural , dep_class ) else : err_message = 'Unable to delete {} {}. The following dependent {} were found: ' . format ( obj . _meta . verbose_name , obj , dep_class ) dependent_objects = [ ] for o in e [ 1 ] : if hasattr ( o , 'get_absolute_url' ) : dependent_objects . append ( '<a href="{}">{}</a>' . format ( o . get_absolute_url ( ) , str ( o ) ) ) else : dependent_objects . append ( str ( o ) ) err_message += ', ' . join ( dependent_objects ) messages . error ( request , err_message )
generate a user-friendly error message in response to a protectederror exception .