
    sik$                     r   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	m
Z
 ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZ ddlmZ ddlmZmZmZ ddlmZ  G d d      Z d Z!d Z"ee ed      d                      Z# ejH                   e	de#d             d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.y) zJ
context_processor.py

This module is used to register context processor`
    N)apps)messages)HttpResponse)pathreverse)gettext_lazy)CompanyTrackLateComeEarlyOut)urlpatterns)EmployeeEmployeeGeneralSettingEmployeeWorkInformationProfileEditFeature)horilla_apps)hx_request_requiredlogin_requiredpermission_required)get_horilla_model_classc                   >    e Zd ZdZ G d d      ZdZ e       ZdZdZy)
AllCompanyz
    Dummy class
    c                       e Zd ZdZy)AllCompany.Urls>https://ui-avatars.com/api/?name=All+Company&background=randomN)__name__
__module____qualname__url     ;/var/www/python-projects/worksol/base/context_processors.pyUrlsr   !   s    Nr   r!   All CompanyAll companiesN)	r   r   r   __doc__r!   companyicontextidr   r   r    r   r      s+    O O G6DD	Br   r   c                 ^     | j                   d      j                  d      }|r|d   }|S d }|S )N/)stripsplit)r   segmentslast_sections      r    get_last_sectionr0   *   s<    tzz#$$S)H $,8B<L 26Lr   c                    t        d t        j                  j                         D              }g dg|z   }| j                  j                  d      }d}|r|dk(  rd|d   d<   d}n |D ]  }t        |d         |k(  sd|d<   d} ||d	S )
zC
    This method will return the history additional field form
    c              3   x   K   | ]2  }|j                   |j                  |j                  j                  d g 4 yw)FN)r(   r%   r&   r   ).0r%   s     r    	<genexpr>z get_companies.<locals>.<genexpr>7   s3       
W__gll&6&6>s   8:)allr"   r   Fselected_companyFr5   Tr      )all_companiescompany_selected)listr	   objectsr5   sessiongetstr)request	companiesr6   r9   r%   s        r    get_companiesrA   3   s      **, I
	
 	I **+=>,5	!Q  	(G71:"22!
#' 	( '<LMMr   zbase.change_companyc                 l   | j                   j                  d      }| j                  j                  }t	        t	        |dd      dd      }|| j
                  d<   |dk(  r
t               net        j                  j                  |      j                         r.t        j                  j                  |      j                         n	t               }| j                   j                  dd      }d	}|dk7  rt        j                  ||      rt        |      }t        j                  j                  |      j                         }t	        t	        |dd      dd      }	|	|k7  r~d
}
||k(  rd}
|j                  |j                   j"                  |
|j$                  d}t'        j(                  | t+        d             || j
                  d<   t-        dt/        d       d      S |dk(  rd}
n
||k(  rd}
nd
}
|j                  |j                   j"                  |
|j$                  d}|| j
                  d<   t-        d      S )zK
    This method is used to update the selected company on the session
    
company_idemployee_work_infoNr6   r5   )r(   nextr*   z^/employee/employee-view/\d+/$zOther Companyz
My Company)r%   r&   r'   r(   z0Employee is not working in the selected company.selected_company_instancez5
                    <script>window.location.href = `zemployee-viewz`</script>
                r#   z*<script>window.location.reload();</script>)GETr=   useremployee_getgetattrr<   r   r	   r;   filterfirstrematchr0   r   r%   r&   r   r(   r   error_r   r   )r?   rC   rH   user_companyr%   previous_pathpatternemployee_idemployeeemp_companyr'   s              r    update_selected_companyrW   P   s    .J<<$$D*D1<L +5GOO&'  	 %%%4::< OO""j"1779  KKOOFC0M/GU88G]+*=9K''..+.>DDFH!"6=|TK g%&-'D&#LL,, !**	 QQR @G ;<#55<_5M4N O  U	|	# ??  jj	G 4;GOO/0DEEr   zupdate-selected-company)namec                 b   t        t        dd      }|rt        j                  j	                  d      j                         }	 | j                  j                  j                         r$| j                  j                  j                         n|}|r|j                  |dS d|dS dd dS #  |}Y !xY w)NWHITE_LABELLINGFT)hqWorksol)white_label_company_namewhite_label_company)
rJ   r   r	   r;   rK   lastrH   rI   get_companyr%   )r?   white_labellingr[   r%   s       r    white_labelling_companyrb      s    l,=uEO__##t#,113	 <<,,88: ))557  <C#*
 	
HQ#*
 	
 )2#'
 	
	Gs   A
B( (B.c                     d}d}t        j                  d      r't        dd      }|j                  j	                         }|r|j
                  }d|iS )I
    Check weather resignation_request enabled of not in offboarding
    FNoffboardingoffboardinggeneralsetting	app_labelmodelenabled_resignation_request)r   is_installedr   r;   rL   resignation_request)r?   rj   rL   OffboardingGeneralSettings       r    resignation_request_enabledrn      s_     #(E'$;#+F%
! *11779&+&?&?#)+FGGr   c                     d}d}t        j                  d      r't        dd      }|j                  j	                         }|r|j
                  }d|iS )rd   NT
attendanceattendancegeneralsettingrg   enabled_timerunner)r   rk   r   r;   rL   time_runner)r?   rL   rr   AttendanceGeneralSettings       r    timerunner_enabledru      s_     E&#:"*D$
  )00668".. "455r   c                     d}d}t        j                  d      r't        dd      }|j                  j	                         }|r|j
                  }d|iS )rd      Npayrollpayrollgeneralsettingrg   get_initial_notice_period)r   rk   r   r;   rL   notice_period)r?   initialrL   PayrollGeneralSettings       r    intial_notice_periodr~      s\     GE# 7'>!
 &--335%%'11r   c                     d}t        j                  d      r(t        dd      }|j                  j	                         }nd}|r|j
                  }d|iS )zR
    This method is used to get the candidate self tracking is enabled or not
    Frecruitmentrecruitmentgeneralsettingrg   Ncheck_candidate_self_tracking)r   rk   r   r;   rL   candidate_self_tracking)r?   r   RecruitmentGeneralSettingrL   s       r    r   r      s_    
 $'$;#+F%
! *11779"'"?"?+-DEEr   c                     d}t        j                  d      r(t        dd      }|j                  j	                         }nd}|r|j
                  }d|iS )zH
    This method is used to check enabled/disabled of rating option
    Fr   r   rg   N$check_candidate_self_tracking_rating)r   rk   r   r;   rL   show_overall_rating)r?   rating_optionr   rL   s       r    r   r      s\     M'$;#+F%
! *11779112MBBr   c                     t         j                  j                         }d}d}|r|j                  }|j                  }||dS )z7
    This method is used to get the initial prefix
    NPEP)get_initial_prefixprefix_instance_id)r   r;   rL   r(   badge_id_prefix)r?   settingsinstance_idprefixs       r    r   r   
  sD     &--335HKFkk))"(LLr   c                 2    ddl m} d|j                  v }d|iS )Nr   )r   	biometricbiometric_app_exists)django.confr   INSTALLED_APPS)r?   r   r   s      r    r   r     s"    $&(*A*AA"$899r   c                 h    t         j                  j                         }|r|j                  nd}||dS )NT)trackinglate_come_early_out_tracking)r
   r;   rL   	is_enable)r?   r   enables      r    #enable_late_come_early_out_trackingr     s0    $,,224H#+XFGGr   c                     ddl m} t        j                  j	                         j                         }|r|j                  rdnd}|r.t        d |D              s|j                  dt        d      f       d|iS )	Nr   )ACCESSBILITY_FEATURETFc              3   ,   K   | ]  }|d    dk(    yw)r   profile_editNr   )r3   items     r    r4   z&enable_profile_edit.<locals>.<genexpr>*  s     N47n,Ns   r   zProfile Edit Accessprofile_edit_enabled)
accessibility.accessibilityr   r   r;   rK   rL   
is_enabledanyappendrP   )r?   r   r   r   s       r    enable_profile_editr   $  si    @%--446<<>L!l&=&=T5FN9MNN '';P9Q(RS"F++r   )/r$   rM   django.appsr   django.contribr   django.httpr   django.urlsr   r   django.utils.translationr   rP   base.modelsr	   r
   	base.urlsr   employee.modelsr   r   r   r   horillar   horilla.decoratorsr   r   r   horilla.methodsr   r   r0   rA   rW   r   rb   rn   ru   r~   r   r   r   r   r   r   r   r   r    <module>r      s    
  # $ % 6 6 !  ! W W 3 N: *+@F ,  @FF   !&
0H 6 2 F$C"
M:H	,r   