
    g$                     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/horilla/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                    | j                   j                  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  rDt        j                  ||      r-t        |      }t        j
                  j                  |      j                         }t        j
                  j                  |      j                         r|j                  j                  |k7  rd	}|| j                   j"                  j                  j                  k(  rd
}|dk(  rd}|j$                  |j&                  j(                  ||j*                  d}t-        j.                  | t1        d             || j                  d<   t3        dt5        d       d      S d	}|| j                   j"                  j                  j                  k(  rd
}|dk(  rd}|j$                  |j&                  j(                  ||j*                  d}|| j                  d<   t3        d      S )zK
    This method is used to update the selected company on the session
    
company_idr6   r5   )r(   nextr*   z^/employee/employee-view/\d+/$)employee_idzOther Companyz
My Companyr#   )r%   r&   r'   r(   z0Employee is not working in the selected company.selected_company_instancez5
                    <script>window.location.href = `zemployee-viewz`</script>
                z*<script>window.location.reload();</script>)GETr=   r<   r   r	   r;   filterfirstrematchr0   r   r   existsemployee_work_inforC   useremployee_getr%   r&   r   r(   r   error_r   r   )r?   rC   r%   previous_pathpatternrE   employeer'   s           r    update_selected_companyrU   P   sJ    .J*4GOO&'  	 %%%4::< OO""j"1779  KKOOFC0M/GU88G]+*=9K''..+.>DDFH ,33:: + ; &( ..99WD&||00CCNNO (D&*D&#LL,, !**	 QQR @G ;<#55<_5M4N O  DW\\..AALLL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Home)white_label_company_namewhite_label_company)
getattrr   r	   r;   rH   lastrN   rO   get_companyr%   )r?   white_labellingrY   r%   s       r    white_labelling_companyra      s    l,=uEO__##t#,113	 <<,,88: ))557  <C#*
 	
HN#*
 	
 )/#'
 	
	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;   rI   resignation_request)r?   ri   rI   OffboardingGeneralSettings       r    resignation_request_enabledrm      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 )rc   NT
attendanceattendancegeneralsettingrf   enabled_timerunner)r   rj   r   r;   rI   time_runner)r?   rI   rq   AttendanceGeneralSettings       r    timerunner_enabledrt      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 )rc      Npayrollpayrollgeneralsettingrf   get_initial_notice_period)r   rj   r   r;   rI   notice_period)r?   initialrI   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recruitmentgeneralsettingrf   Ncheck_candidate_self_tracking)r   rj   r   r;   rI   candidate_self_tracking)r?   r   RecruitmentGeneralSettingrI   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   rf   N$check_candidate_self_tracking_rating)r   rj   r   r;   rI   show_overall_rating)r?   rating_optionr   rI   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;   rI   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;   rI   	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;   rH   rI   
is_enabledanyappendrQ   )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$   rJ   django.appsr   django.contribr   django.httpr   django.urlsr   r   django.utils.translationr   rQ   base.modelsr	   r
   	base.urlsr   employee.modelsr   r   r   r   horillar   horilla.decoratorsr   r   r   horilla.methodsr   r   r0   rA   rU   r   ra   rm   rt   r}   r   r   r   r   r   r   r   r   r    <module>r      s    
  # $ % 6 6 !  ! W W 3 N: *+BF ,  BFJ   !&
0H 6 2 F$C"
M:H	,r   