B
    b                 @   s   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
mZ d dlmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ G dd deZG dd deZeeG dd deZdS )    )admin)ZKModelAdmin)actions)Location)gettext_lazyactivate)db_constwidgets)	ModelFormModelChoiceField)forms)AdminRuntimeWarning)get_current_company_idc                   sn   e Zd ZejedejdZejedej	dZ
eej eddejdZ fddZG d	d
 d
Z  ZS )LocationCreationFormlocation_field_code)label
max_lengthlocation_field_namelocation_field_parentLocationF)querysetr   requiredwidgetc                s   t t| j|| t }tjj|d| jd _ddl	m
} | }tjj|jdd }|ry8t|j}tjj|d |jd s|d | jd _W n tk
r   Y nX d S )	N)
company_idparent_locationr   )threadlocalsid   )location_coder   r   )superr   __init__r   r   objectsfilterfieldsr   Zmysite.baser   Zget_current_usercurrent_companyZorder_byZlastintr   existsinitial	Exception)selfargskwargsr   r   userobjcode)	__class__ >G:\easytimepro\master/mysite/personnel\admin\location_admin.pyr      s    
zLocationCreationForm.__init__c               @   s   e Zd ZeZdZdS )zLocationCreationForm.Meta)r   location_namer   N)__name__
__module____qualname__r   modelr"   r/   r/   r/   r0   Meta"   s   r6   )r2   r3   r4   r   	CharField_r   MAX_LOCATION_CODEr   MAX_LOCATION_NAMEr1   r   r   r    allr	   LocationRadioSelectr   r   r6   __classcell__r/   r/   )r.   r0   r      s   r   c                   sp   e Zd ZejedejddZejedej	dZ
eej eddejdZG d	d
 d
Z fddZ  ZS )LocationChangeFormr   T)r   r   r   r   )r   r   r   F)r   r   r   r   c               @   s   e Zd ZeZdZdS )zLocationChangeForm.Meta)r   r1   r   N)r2   r3   r4   r   r5   r"   r/   r/   r/   r0   r6   .   s   r6   c                sZ   t t| j|| t }tjj|d| jd _t	| dd }|rV|j
rVd| jd jjd< d S )N)r   r   instanceTr   readonly)r   r>   r   r   r   r    r!   r"   r   getattrZpkr   Zattrs)r(   r)   r*   r   r?   )r.   r/   r0   r   2   s    
zLocationChangeForm.__init__)r2   r3   r4   r   r7   r8   r   r9   r   r:   r1   r   r   r    r;   r	   r<   r   r6   r   r=   r/   r/   )r.   r0   r>   '   s   r>   c                   sz   e Zd ZdZddiddiddiddiddidZdZdZejgZe	Z
eZd fd	d
	Z fddZdd Zdd Z  ZS )LocationAdmin)r   r   r1   r   employee_countresign_employee_countwidth      )r   r1   r   rC   rD   )r   r1   )r   r1   r   Nc                s6   i }|dkr| j |d< || tt| j||f|S )z7
        Use special form during user creation
        Nform)add_formupdater   rB   get_form)r(   requestr,   r*   defaults)r.   r/   r0   rK   V   s
    

zLocationAdmin.get_formc                s$   t t| |}|j|jjd}|S )N)r   )r   rB   get_querysetr!   r+   r#   )r(   rL   Zqs)r.   r/   r0   rN   `   s    zLocationAdmin.get_querysetc             C   s   t d ttdS )NZenZemployee_field_location)r   strr8   )r(   r/   r/   r0   get_file_titlee   s    zLocationAdmin.get_file_titlec             C   sD   |j d}tjj||jjdj|jjd}|	 r@t
tdd S )Nr   )r   r   )r   Zduplicate_location_code)Zcleaned_datagetr   r    r!   r?   r   Zexcluder   r%   r   r8   )r(   Z
model_formr   Zcheck_duplicater/   r/   r0   check_domain_rulesi   s
    z LocationAdmin.check_domain_rules)N)r2   r3   r4   Zlist_displayZlist_display_paramsZsort_fieldsZlist_filterr   ZSetLocationr   rI   r>   rH   rK   rN   rP   rR   r=   r/   r/   )r.   r0   rB   ;   s   
rB   N)mysiter   Zmysite.admin.kernelr   Zmysite.personnelr   Zmysite.personnel.modelsr   Zdjango.utils.translationr   r8   r   r   r	   Zdjango.formsr
   r   Zmysite.adminr   Zmysite.admin.exceptionsr   Zmysite.att.utilsr   r   r>   registerrB   r/   r/   r/   r0   <module>   s   