
    >Tf                     F    d dl Z d dlmZ d dlmZ d dlmZ dZd	dZd
dZ	dS )    N)ContentType)serializers)is_taggable)deserialize_objectserialize_objectTc                     t          j        d| g          }t          j        |          d         d         }|pg }t	          | d          r|                    d          |d<   |rUt          |           rFt          | dd          p| j        	                                }t          d |D                       |d	<   t          |                                          D ]}||v r|                    |           ||                    |           |S )
a  
    Return a generic JSON representation of an object using Django's built-in serializer. (This is used for things like
    change logging, not the REST API.) Optionally include a dictionary to supplement the object data. A list of keys
    can be provided to exclude them from the returned dictionary.

    Args:
        obj: The object to serialize
        resolve_tags: If true, any assigned tags will be represented by their names
        extra: Any additional data to include in the serialized output. Keys provided in this mapping will
            override object attributes.
        exclude: An iterable of attributes to exclude from the serialized output
    jsonr   fieldscustom_field_datacustom_fields_tagsNc                     g | ]	}|j         
S  )name).0tags     </var/www/html/netbox-4.1.3/netbox/utilities/serialization.py
<listcomp>z$serialize_object.<locals>.<listcomp>'   s    888Csx888    tags)r   	serializer	   loadshasattrpopr   getattrr   allsortedlistkeysupdate)objresolve_tagsextraexcludejson_strdatar   keys           r   r   r      s    $VcU33H:h"8,DmG s'(( > $)< = =_  :C(( :sGT**<chllnn88488899V DIIKK    '>>HHSMMM EKr   c                 $   t           j                            |           }d|v r|                    d          |d<   d                    |                                          ||d}t          t          j        d|g                    d         }|S )z{
    Instantiate an object from the given model and field data. Functions as
    the complement to serialize_object().
    r   r   .)modelpkr
   pythonr   )	r   objectsget_for_modelr   joinnatural_keyr   r   deserialize)r*   r
   r+   content_typer&   instances         r   r   r   5   s    
 &44U;;L&  &,jj&A&A"#,224455 D
 K+Htf==>>qAHOr   )TNN)N)
r	   "django.contrib.contenttypes.modelsr   django.corer   extras.utilsr   __all__r   r   r   r   r   <module>r8      s~     : : : : : : # # # # # # $ $ $ $ $ $$ $ $ $N     r   