
    >Tf                         d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d
Zd Zd ZdS )    N)settings)messages)ProtectedErrorRestrictedError)JsonResponse)escape)	mark_safe)gettext_lazystatus)handle_protectederrorhandle_rest_api_exceptionc           	         t          |          t          u rt          |j                  }n-t          |          t          u rt          |j                  }n|t          d                              d                    d | D                       t          |          dk    rt          |          nt          d                    }g }|dd         D ]}}t          |d          r<|                    d	|                                 d
t          |           d           N|                    t          t          |                               ~|d                    |          z  }t          j        |t#          |                     dS )zn
    Generate a user-friendly error message in response to a ProtectedError or RestrictedError exception.
    zSUnable to delete <strong>{objects}</strong>. {count} dependent objects were found: z, c              3   4   K   | ]}t          |          V  d S )N)str).0objs     =/var/www/html/netbox-4.1.3/netbox/utilities/error_handlers.py	<genexpr>z(handle_protectederror.<locals>.<genexpr>    s(      77s#c((777777    2   zMore than 50)objectscountNget_absolute_urlz	<a href="z">z</a>)typer   listprotected_objectsr   restricted_objects_formatjoinlenhasattrappendr   r   r   r   errorr	   )obj_listrequester   err_messagedependent_objects	dependents          r   r   r      s    Aww.   !455	aO	#	# !566 ijjqq		77h77777(+,=(>(>"(D(Dc#$$$!NJ[J[ r  K &ss+ = =	9011 	=$$%h1K1K1M1M%h%hQWXaQbQb%h%h%hiiii$$VC	NN%;%;<<<<499.///KN7Ik2233333r   c                     t          j                    \  }}}t          |          |j        t          j        j        t          j                    d}t          |t          j                  S )zT
    Handle exceptions and return a useful error message for REST API requests.
    )r%   	exceptionnetbox_versionpython_versionr   )sysexc_infor   __name__r   RELEASEfull_versionplatformr/   r   r   HTTP_500_INTERNAL_SERVER_ERROR)r'   argskwargstype_r%   	tracebackdatas          r   r   r   0   s]     "lnnE5)U^"*7"133	 D V%JKKKKr   )r5   r0   django.confr   django.contribr   django.db.modelsr   r   django.httpr   django.utils.htmlr   django.utils.safestringr	   django.utils.translationr
   r   rest_frameworkr   __all__r   r    r   r   <module>rF      s     



             # # # # # # < < < < < < < < $ $ $ $ $ $ $ $ $ $ $ $ - - - - - - 6 6 6 6 6 6 ! ! ! ! ! !4 4 4:L L L L Lr   