B
    bC                 @   sR   d dl mZ d dlmZ G dd dejZG dd dejZG dd dejZd	S )
    )serializers)gettext_lazyc               @   s6   e Zd ZdZejeeedZejddZ	dd Z
dS )ImportSerializer))
not_importr   )	overwriter   )choices	help_textF)Zallow_empty_filec             C   s0   |j dd dkr,tdtd|j  i|S )N.)ZcsvZxlsimport_file%att_serializer_import_file_validation)namesplitr   ValidationError_)selfr    r   IG:\easytimepro\master/mysite/workflow\api\serializers\util_serializers.pyvalidate_import_file   s    z%ImportSerializer.validate_import_fileN)__name__
__module____qualname__Zduplicate_record_choicesr   ChoiceFieldstrZduplicate_recordZ	FileFieldr   r   r   r   r   r   r      s   r   c                   sB   e Zd Zeje dZ fddZdd ZG dd dZ	  Z
S )ObjectActionSerializer)Zchildc                sj   t t| j|| | jjs&ttd| jjs:ttdtj	| jjd
dd | jjD d| jd< dS )	z6
        Add the ObjectAction to self.fields.
        Zatt_serializer_invalid_metaZatt_serializer_invalid_action;c             S   s   g | ]}t |qS r   )r   ).0Zchoicer   r   r   
<listcomp>+   s    z3ObjectActionSerializer.__init__.<locals>.<listcomp>)r   r   Zaction_typeN)superr   __init__Metamodel	Exceptionr   action_type_choicesr   r   joinZfields)r   argskwargs)	__class__r   r   r      s    zObjectActionSerializer.__init__c             C   sJ   t t|}x8|D ]0}| jjjj|d stdt	d| iqW |S )N)id
object_idsr   )
listsetr    r!   Zobjectsfilterexistsr   r   r   )r   r)   Z	object_idr   r   r   validate_object_ids.   s    
z*ObjectActionSerializer.validate_object_idsc               @   s   e Zd ZdZdZdS )zObjectActionSerializer.MetaNr   )r   r   r   r!   r#   r   r   r   r   r    7   s   r    )r   r   r   r   Z	ListFieldZIntegerFieldr)   r   r.   r    __classcell__r   r   )r'   r   r      s
   	r   c               @   s   e Zd ZdS )NoneSerializerN)r   r   r   r   r   r   r   r0   <   s   r0   N)	Zrest_frameworkr   Zdjango.utils.translationr   r   Z
Serializerr   r   r0   r   r   r   r   <module>   s   #