o
     e                     @   sN   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	 G dd dZ
d	S )
    )ObjectDoesNotExist)NOT_PROVIDED)Manager   )widgets)
FieldErrorc                   @   sf   e Zd ZdZddgZdddeddddfddZdd	 Zd
d Zdd Z	dddZ
dd ZdddZdS )Fieldaw  
    Field represent mapping between `object` field and representation of
    this field.

    :param attribute: A string of either an instance attribute or callable off
        the object.

    :param column_name: Lets you provide a name for the column that represents
        this field in the export.

    :param widget: Defines a widget that will be used to represent this
        field's data in the export, or transform the value during import.

    :param readonly: A Boolean which defines if this field will be ignored
        during import.

    :param default: This value will be returned by
        :meth:`~import_export.fields.Field.clean` if this field's widget did
        not return an adequate value.

    :param saves_null_values: Controls whether null values are saved on the object
    :param dehydrate_method: Lets you choose your own method for dehydration rather
        than using `dehydrate_{field_name}` syntax.
    :param m2m_add: changes save of this field to add the values, if they do not exist,
        to a ManyToMany field instead of setting all values.  Only useful if field is
        a ManyToMany field.
    N FTc	           	      C   s@   || _ || _|| _|st }|| _|| _|| _|| _|| _	d S N)
	attributedefaultcolumn_namer   Widgetwidgetreadonlysaves_null_valuesdehydrate_methodm2m_add)	selfr   r   r   r   r   r   r   r    r   G/var/www/html/venv/lib/python3.10/site-packages/import_export/fields.py__init__(   s   
zField.__init__c                 C   s<   d| j j| j jf }t| dd}|durd||f S d| S )zC
        Displays the module, class and name of the field.
        z%s.%sr   Nz<%s: %s>z<%s>)	__class__
__module____name__getattr)r   pathr   r   r   r   __repr__>   s
   zField.__repr__c                 K   s|   z|| j  }W n ty   td| j t|f w | jj|fd|i|}|| jv r<| jtkr<t| jr9|  S | jS |S )z
        Translates the value stored in the imported datasource to an
        appropriate Python object and returns it.
        z;Column '%s' not found in dataset. Available columns are: %srow)	r   KeyErrorlistr   cleanempty_valuesr   r   callable)r   datakwargsvaluer   r   r   r!   H   s   
zField.cleanc              
   C   s~   | j du rdS | j d}|}|D ]}zt||d}W n ttfy(   Y  dS w |du r0 dS qt|r=t|ts=| }|S )z>
        Returns the value of the object's attribute.
        N__)r   splitr   
ValueErrorr   r#   
isinstancer   )r   objattrsr&   attrr   r   r   	get_value_   s    
zField.get_valuec                 K   s   | j sO| jd}|dd D ]}t||d}q| j|fi |}|dus(| jrQ|s4t||d | dS | jrCt||d j|  dS t||d 	| dS dS dS )z
        If this field is not declared readonly, the object's attribute will
        be set to the value returned by :meth:`~import_export.fields.Field.clean`.
        r'   N)
r   r   r(   r   r!   r   setattrr   addset)r   r+   r$   is_m2mr%   r,   r-   cleanedr   r   r   savey   s   z
Field.savec                 C   s$   |  |}|du rdS | j||S )zd
        Returns value from the provided object converted to export
        representation.
        Nr	   )r.   r   render)r   r+   r&   r   r   r   export   s   
zField.exportc                 C   s$   d}| j s|std| j p|| S )z{
        Returns method name to be used for dehydration of the field.
        Defaults to `dehydrate_{field_name}`
        
dehydrate_z6Both dehydrate_method and field_name are not supplied.)r   r   )r   
field_nameDEFAULT_DEHYDRATE_METHOD_PREFIXr   r   r   get_dehydrate_method   s   
zField.get_dehydrate_method)Fr
   )r   r   __qualname____doc__r"   r   r   r   r!   r.   r5   r7   r;   r   r   r   r   r   	   s$    



r   N)django.core.exceptionsr   django.db.models.fieldsr   django.db.models.managerr   r	   r   
exceptionsr   r   r   r   r   r   <module>   s    