o
    ChF                     @   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 )Fielda  
    ``Field`` represents a mapping between an ``instance`` field and a representation of
    the field's data.

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

    :param column_name: An optional column 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 returned
        a value defined in :attr:`~import_export.fields.empty_values`.

    :param saves_null_values: Controls whether null values are saved on the instance.
      This can be used if the widget returns null, but there is a default instance
      value which should not be overwritten.

    :param dehydrate_method: You can provide a `dehydrate_method` as a string to use
        instead of the default `dehydrate_{field_name}` syntax, or you can provide
        a callable that will be executed with the instance as its argument.

    :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   f/var/www/html/myvaluetrips/my_value_trip_new/venv/lib/python3.10/site-packages/import_export/fields.py__init__-   s   
zField.__init__c                 C   s<   | j j d| j j }| jdurd| d| j dS d| S )zC
        Displays the module, class and name of the field.
        .N<z: >z<%s>)	__class__
__module____name__r   )r   pathr   r   r   __repr__C   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   r    kwargsvaluer   r   r   r#   L   s   
zField.cleanc              
   C   s   t |tr| j|vrdS || j S | jdu rdS | jd}|}|D ]}zt||d}W n ttfy9   Y  dS w |du rA dS q"t|rNt |tsN| }|S )z@
        Returns the value of the instance's attribute.
        N__)	
isinstancedictr   splitgetattr
ValueErrorr   r%   r   )r   instanceattrsr'   attrr   r   r   	get_valueb   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 instance'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/   r0   cleanedr   r   r   save   s   z
Field.savec                 K   s   |  |}| jj|fi |S )zf
        Returns value from the provided instance converted to export
        representation.
        )r1   r   render)r   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#   r1   r8   r:   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    