
    si5!                        d Z ddl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 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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 Z%e# e$d      d               Z&e# e$d      d               Z'e# e$d      dd              Z(e# e$d      dd              Z)e#d        Z*e#d        Z+e# e$d      d               Z,y) zX
employee/context_processors.py

This module is used to write context processor methods
    N)date)template)apps)messages)EmailMessage)	Paginator)HttpResponseJsonResponse)render)ConfiguredEmailBackend)MailTemplateForm)export_datagenerate_pdf)HorillaMailTemplate)EmployeeFilter)Employee)settings)login_requiredmanager_can_enterc                 @    t        | d      }|j                  |      } | S )z3
    This method is used to paginate query set
       )r   get_page)qrysetpage_number	paginators      A/var/www/python-projects/worksol/employee/not_in_out_dashboard.pypaginator_qryr      s%     &"%I,FM    zemployee.view_employeec                 2   | j                   j                  d      }| j                   j                         }t        dt	        j
                         i      j                  j                  d      j                  d      }t        | dt        ||      |d      S )l
    This context processor wil return the employees, if they not marked the attendance
    for the day
    page
not_in_yetTemployee_work_info__isnull	is_activezdashboard/not_in_yet.html)	employeespd)GETget	urlencoder   r   todayqsexcludefilterr   r   )requestr   previous_dataempss       r   r"   r"   %   s     ++//&)KKK))+Mdjjl34	GGtG4	$	 	 #&t[9	
 r   c                     t        dt        j                         i      j                  j	                  d      j                  d      }t        | dd|i      S )r    not_out_yetTr#   r%   zdashboard/not_out_yet.htmlr'   )r   r   r,   r-   r.   r/   r   )r0   r2   s     r   r4   r4   >   sO     	tzz|45	GGtG4	$	 	
 '7+t9LMMr   zemployee.change_employeec           	         d}|r t         j                  j                  |      }t         j                  j                         }t        j                  j                         }t        | d|||t               j                         d      S )5
    This method used send mail to the employees
    Nidzemployee/send_mail.html)employee	templatesr'   searchWords)r   objectsr*   allr   r   r   get_employee_template_language)r0   emp_idr9   r'   r:   s        r   	send_mailr@   M   s}     H##''6'2  $$&I#++//1I! ""+-LLN		
	 	r   c                    | j                   }|r=|j                  r0|j                  dk(  r d}|r t        j                  j	                  |      }d|i}t        j                  d      r8ddlm} ddl	m
}  |       } |       }|j                  ||j                  d	       t        j                  d
      r>ddlm}	 ddlm}
 ddlm}  |
       } |	       }|j                  ||j                  d       t        j                  d      r5ddlm} ddlm} |j                   |        || j.                        d       t1        | d|      S t3        | 	
d      S )r6   zexport-data-employeeNr7   r9   leaver   )LeaveRequestFilter)LeaveRequestExportForm)leave_excel_columnleave_export_filter
attendance)AttendanceFilters)AttendanceExportForm)
Attendance)attendance_excel_columnattendance_export_filterpayroll)PayslipFilter)PayslipExportColumnForm)payroll_export_columnpayroll_export_filterz"employee/export_data_employee.html)contextAttendance_export)r0   modelfilter_class
form_class	file_name)resolver_matchurl_namer   r<   r*   r   is_installedleave.filtersrC   leave.formsrD   updateformattendance.filtersrH   attendance.formsrI   attendance.modelsrJ   payroll.filtersrN   payroll.forms.component_formsrO   r)   r   r   )r0   r?   rX   r9   rR   rC   rD   excel_columnexport_filterrH   rI   rJ   rN   rO   s                 r   employee_data_exportrf   d   sE    ++N####'==''++v+6Hx( W%8:13L.0MNN*6+8+=+= \*<=4/1L-/MNN/;0=0B0B Y'5MNN-D-F-:7;;-G gCWUU&'% r   c                 p    t         j                  j                  |      j                  }t	        d|i      S )9
    This method is used to return the mail template
    r7   body)r   r<   r*   ri   r
   )r0   r?   ri   s      r   get_templaterj      s2    
 &&**f*5::D''r   c                 z   | j                   j                  d      }t        j                  |      }| j                   j                  d      }|rbt        j
                  j                  |      }t        j                  || j                  j                  | d      }|j                  |      xs d}t        d|i      S )rh   ri   r?   r7   )instanceselfr0    )r)   r*   r   Templater   r<   Contextuseremployee_getr   r
   )r0   ri   template_bdyr?   r9   rR   s         r   get_mail_previewrt      s    
 ;;??6"D$$T*L[[__X&F##''6'2""$11"
 ""7+2s''r   zrecruitment.change_employee)permc                    | j                   d   }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        j                  j                  |      }| j                  j                  d      }|r!t        j                  j                  |      }nt        j                  j                         }||z  j                         }| j                   j                  d      }|D ]*  }	t        t        j                  j                  |      j                  dd	
            }
|D cg c])  }|j                  |j                         |j                  f+ }}|
D ]  }t        j                   |      }t        j"                  |	| j$                  j&                  d      }|j)                  |      }|j+                  dt-        |i dd      j.                  df        t        j                   |      }t        j"                  |	| j$                  j&                  d      }|j)                  |      }|	j0                  r,|	j0                  j2                  r|	j0                  j2                  n|	j2                  }t5        |||g      }d|_        ||_        	 |j;                          |	j0                  j2                  s|	j2                  r(t=        j>                  | d|	jA                                 n't=        jB                  | d|	jA                                 - tI        d      S c c}w # tD        $ r!}t=        jF                  | d       Y d}~cd}~ww xY w)zK
    This method is used to send acknowledgement mail to the candidate
    r8   subjectri   r'   )id__inother_attachmentsr7   template_attachmentsT)flat)rl   rm   DocumentF)pathtitlezapplication/pdf)rw   ri   tohtmlzMail sent to zEmail not set for zSomething went wrongNz)<script>window.location.reload()</script>)%POSTr*   getlistr   r<   r/   FILESnonedistinctlistr   values_listnamereadcontent_typer   ro   rp   rq   rr   r   appendr   contentemployee_work_infoemailr   content_subtypeattachmentssendr   successget_full_nameinfo	Exceptionerrorr	   )r0   employee_idrw   bdyemployee_idsr'   ry   employee_objtemplate_attachment_idsr9   bodysfiler   r   rs   rR   
render_bdysend_to_mailr   es                       r   send_mail_to_employeer      s    ,,t$Klly)G
,,

6
"C<<''4L  ''|'<I--.AB''..+.>'',,.\)335I%ll223IJ 2<''... / k&tk,
 EV
<@TYY		T%6%67
 
  	D#,,T2L&&%w||/H/HIG &,,W5J Re:NVV%	  ((-""!7<<+D+DE
 "((1
 **x/J/J/P/P ''-- 	 ~

 !''	<JJL**00HNN  M(:P:P:R9S*TUg);H<R<R<T;U'VWa2<f CDD[
V  	<NN7$:;;	<s   .M7BM	M5M00M5)N)-__doc__jsondatetimer   djangor   django.appsr   django.contribr   django.core.mailr   django.core.paginatorr   django.httpr	   r
   django.shortcutsr   base.backendsr   
base.formsr   base.methodsr   r   base.modelsr   employee.filtersr   employee.modelsr   horillar   horilla.decoratorsr   r   r   r"   r4   r@   rf   rj   rt   r    r   r   <module>r      s       # ) + 2 # 0 ' 2 + + $  @ +, - . +,
N - 
N -. / * -.A / AH ( ( ( (( 56GE 7 GEr   