B
    gcV$                 @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ 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 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 e
dd Z e
dd Z!e
dd Z"e
dd Z#e
dd Z$e
dd Z%e
dd Z&e
dd Z'e
dd Z(e
d d! Z)e
d"d# Z*ed$e d%d&ed'e#d(d&ed)e$d*d&ed+e!d,d&ed-e"d.d&ed/e%d0d&ed1e&d2d&ed3e'd4d&ed5e(dd&ed6e)d!d&ed7ej+d8d&ed9ej,d:d&ed;ej-d<d&ed=ed>d?d@edAe*d#d&gZ.dS )B    N)settings)urlinclude)login_required)JsonResponse)TemplateResponse)EmployeeDocumentFrom)EmployeeCertificationEmployee)HttpResponse)AppList)views)get_current_company_id)gettext_lazyc             C   s   ddl m} t|| jddS )Nr   )get_tree_nodesF)safe)Z(mysite.personnel.models.model_departmentr   r   user)requestr    r   .G:\easytimepro\master/mysite/personnel\urls.pydepartment_tree_nodes   s    r   c             C   s   ddl m} t|| jddS )Nr   )r   F)r   )Z&mysite.personnel.models.model_positionr   r   r   )r   r   r   r   r   position_tree_nodes   s    r   c             C   s   ddl m} t|| jddS )Nr   )r   F)r   )Z&mysite.personnel.models.model_locationr   r   r   )r   r   r   r   r   location_tree_nodes"   s    r   c             C   s   ddl m} t|| jddS )Nr   )r   F)r   )"mysite.personnel.models.model_arear   r   r   )r   r   r   r   r   area_tree_nodes(   s    r   c             C   s   ddl m} t|| jddS )Nr   )get_tree_nodes_without_defaultF)r   )r   r   r   r   )r   r   r   r   r   area_tree_nodes_without_default.   s    r   c             C   s   ddl m} | jdd }|rtjj|d}tjj|j|j	d}|r~|d j
}|d|  |d|  |  tdd	iS tddiS ntdd
iS d S )Nr   )cacheemp)id)ZusernamecompanyZmobile_company_id_Zmobile_employee_id_code   )Zdjango.core.cacher   GETgetr
   objectsr   filteremp_coder    device_tokendeleter   )r   r   employee_idemployeeZapp_listr)   r   r   r   reset_client4   s     

r-   c          
   C   s  | j  dkr| jdd }| jdd }d }|rFtjj|d }t| j| j	|d}|
 rtj| jdd }|tj k rtdtd	d
S | jddkr| jdstdtdd
S |j}d|jkr|dd r|jdj }tjj|djddd}tj}	x^|D ]V}
|	|
 }tj|r t|d*}| }||krjtdtdd
S W d Q R X q W |d }||j_|d j}| sd t!tdd |}n|}d"|d j#||d j$|j%&ddd |j_'|d j(|j_(|)  tddd
S | jds.tdtdd
S | jdsNtd td!d
S | jdsntdtd"d
S | jdd d#krtdtd$d
S td%|j*+ d
S nl| j,d&d }|sd S | j,dd }d }|rtjj|d }t|d'}||j-d _.d(|i}t/| d)|S d S )*NZpost_idr,   )r   )filesinstanceZ	expire_onz%Y-%m-%dZgreater_than_today)r!   msgZemail_alertTrueZbeforeZalert_before_is_emptycertificate)r+   fileT)ZflatrbZtrying_to_add_same_fileZcertification c             S   s   |   S )N)isalnum)charr   r   r   <lambda>n       z!update_document.<locals>.<lambda>z{}_{}_{}.{}.r"   r   Zplease_select_docZ
valid_dateZalert_before-Zalert_before_negativer#   r   )r0   formz,personnel/employee/actions/add_document.html)0methodlowerZPOSTr%   r	   r&   r'   firstr   ZFILESZis_validdatetimestrptimedateZtodayr   _Zcleaned_dataZchanged_datar/   r6   readZvalues_listr   ADDITION_FILE_ROOTospathexistsopenr0   Z	cert_namer9   joinlistformat
first_namer   namersplit	file_namer(   ZsaveerrorsZas_jsonr$   Zfieldsinitialr   )r   r.   r   r0   r@   Zexpire_on_datedataZuploaded_fileZ	documents	file_pathr6   rT   fZexisting_docr5   Zcertificate_uploadZcertificate_namecontextr   r   r   update_documentO   sp    


"

 
r[   c             C   s2   | j dd }|r$tjj|d  tdddS )Nr.   )r   r   r8   )r!   r2   )r$   r%   r	   r&   r'   r*   r   )r   r.   r   r   r   remove_document   s    r\   c             C   s   i }t | d|S )Nz%personnel/employee/widgets/frame.html)r   )r   rZ   r   r   r   get_employee_frame   s    r]   c             C   s   i }t | d|S )Nz3personnel/employee/widgets/filter_by_dept_area.html)r   )r   rZ   r   r   r   filter_resign_employee   s    r^   c       
      C   s   | j jr| j j}n| j j}tj }tjj||j	|j
dd}g }x|D ]}i }|j|d< |j|d< |j|d< |jj|d< d}tt }d|jj|j}	tjtjtj|	rdj|	|d	}||d
< || qJW t|dd d}tt |S )N)
company_idZbirthday__monthZbirthday__dayr(   Zemp_idZemp_first_nameZemp_departmentr8   zphoto/{0}_{1}.jpgz/files/{file}?_={stamp})r6   stampphotoc             S   s   t | ddS )Nr(   $   )intr%   )xr   r   r   r;      r<   zbirthday_data.<locals>.<lambda>)key)!r   Zis_employeer_   Zcurrent_companyrD   Znowr
   r&   r'   ZmonthZdayZorder_byr   r(   rQ   Z
departmentZ	dept_namerc   timerP   r    rR   rJ   rK   rL   rN   r   rI   appendsortedr   jsondumps)
r   r_   ZTodayZbirthdaybirthday_datarW   Znew_birthday_datara   r`   Z_photor   r   r   rk      s*    





rk   z^department_tree/$Zpersonnel_department_tree_nodes)viewrR   z^area_tree/$Zpersonnel_area_tree_nodesz^area_tree_no_default/$Z)personnel_area_tree_nodes_without_defaultz^position_tree/$Zpersonnel_position_tree_nodesz^location_tree/$Zpersonnel_location_tree_nodesz^reset_client/$Zpersonnel_reset_clientz^update_document/$Zpersonnel_update_documentz^remove_document/$Zpersonnel_remove_documentz^employee_frame/$z^filter_resign_employee/$z^getDepartmentList/$get_department_listz^getAreaList/$get_area_listz^getPositionList/$get_position_listz^api/zmysite.personnel.api.urlsZbiotime_personnel_api)	namespacez^birthday_data/$)/ri   rD   rf   rJ   mysiter   Zdjango.conf.urlsr   r   Zdjango.contrib.auth.viewsr   Zdjango.httpr   Zdjango.template.responser   Z%mysite.personnel.forms.document_formsr   Zmysite.personnel.modelsr	   r
   Zdjango.http.responser   Zmysite.mobile.modelsr   Zmysite.personnelr   Zmysite.att.utilsr   Zdjango.confZdjango.utils.translationr   rG   r   r   r   r   r   r-   r[   r\   r]   r^   rk   rm   rn   ro   Zurlpatternsr   r   r   r   <module>   sV   ?