
    si                       d Z ddlZddlZddlZddlZddlmZ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mZ dd
lmZ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$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/m0Z0 ddl1m2Z3 ddl1m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZX ddlYmZZZ ddl[m\Z\ ddl]m^Z^ ddl_m`Z`maZa ddlbmcZc ddldmeZe dd lfmgZg dd!lhmiZi dd"ljmkZk dd#llmmZm d$ Znd% e3d&      fd' e3d(      fd) e3d*      fgZod+ Zpd, Zq G d- d.ej                        Zr G d/ d0ej                        Zs G d1 d2er      Zt G d3 d4es      Zu G d5 d6es      Zv G d7 d8es      Zw G d9 d:er      Zx G d; d<er      Zy G d= d>er      Zz G d? d@er      Z{ G dA dBer      Z| G dC dDer      Z} G dE dFer      Z~ G dG dHer      Z G dI dJej                        Z G dK dLer      Z G dM dNer      Z G dO dPer      Z G dQ dRer      Z G dS dTer      Z G dU dVej                        Z G dW dXer      Z G dY dZer      Z G d[ d\er      Z G d] d^er      Z G d_ d`ej                        Z G da dbej                        Z G dc dde      Zg deZ G df dgej                        Z G dh diej                        Z G dj dkej                        Z G dl dmej                        Z G dn doer      Z G dp dqer      Z G dr dser      Z G dt duer      Z G dv dwer      Z G dx dyer      Z G dz d{ej                        Z G d| d}er      Z G d~ der      Z G d der      Z G d dej:                        Z G d dej>                        Z^ G d der      Z G d der      Z G d der      Z G d dej                        Z e       Z G d dej                        Zd Z G d dej                        Z G d der      Z G d der      Z G d der      Z G d dej                        Z G d der      Z G d der      Zy)zA
forms.py

This module is used to register forms for base module
    N)datedatetime	timedelta)Any)forms)apps)messages)get_user_model)SetPasswordForm_unicode_ci_compare)Group
PermissionUser)default_token_generator)get_current_site)ValidationError)EmailMultiAlternatives)validate_ipv46_address)	DateInputHiddenInput	TextInput)loaderrender_to_string)force_bytes)
strip_tags)urlsafe_base64_encode)gettext)gettext_lazy)reload_queryset)!AnnouncementAnnouncementCommentAnnouncementExpire
AttachmentAttendanceAllowedIPBaserequestFileCompanyCompanyLeaves
DepartmentDriverViewedDynamicEmailConfigurationDynamicPaginationEmployeeShiftEmployeeShiftDayEmployeeShiftScheduleEmployeeTypeHolidaysHorillaMailTemplateJobPositionJobRoleMultipleApprovalConditionPenaltyAccountsRotatingShiftRotatingShiftAssignRotatingWorkTypeRotatingWorkTypeAssignShiftRequestShiftRequestCommentTagsTrackLateComeEarlyOutWorkTypeWorkTypeRequestWorkTypeRequestComment)CustomModelChoiceWidget)EmployeeFilter)MultipleFileField)EmployeeEmployeeTag)horilla_middlewares)_thread_locals)get_horilla_model_class)AuditTag)HorillaMultiSelectField)HorillaMultiSelectWidgetc                 Z   t        |       dkD  rt        t        d            	 | j                  d      \  }}t	        |      }t	        |      }t        t        |            dkD  s|t        d      vrt        t        d            y# t        $ r}t        t        d            |d}~ww xY w)zM
    this method is used to validate the format of duration like fields.
       z)Invalid format, it should be HH:MM format:   <   N)lenr   _splitintstrrange
ValueError)valuehourminuteerrors       ./var/www/python-projects/worksol/base/forms.pyvalidate_time_formatr^   T   s     5zA~a KLMMY{{3'f4yVs4y>AuRy!8!!$O"PQQ "9 Ya KLMSXXYs   A"B 	B*B%%B*afterAfterweeklyWeekendmonthlyMonthlyc                     |j                         | k(  r|S | |j                         z
  dz  }|dk(  rd}|t        |      z   S )a^  
    Calculates the date of the next occurrence of the target day within the next week.

    Parameters:
        target_day (int): The target day of the week (0-6, where Monday is 0 and Sunday is 6).
        start_date (date): The starting date.

    Returns:
        date: The date of the next occurrence of the target day within the next week.
       r   days)weekdayr   )
target_day
start_datedays_until_target_days      r]   get_next_week_daterm   k   sS     z)'**<*<*>>!C! !	'<===    c                    |dk(  r8t        j                  | j                  | j                        d   }t	        |      }t        |      }| j                  |k  s|dk(  r$	 t        | j                  | j                  |      }|S t        j                  | j                  | j                        d   }| j                  |      t        d      z   }	 |j                  |      }|S # t        $ rI t        | j                  | j                  dz   d      }t        |j                  |j                  |      }Y |S w xY w# t        $ r@ |j                  |j                  dz         t        d      z   j                  |      }Y |S w xY w)a`  
    Given a start date and a rotation day (specified as an integer between 1 and 31, or
    the string 'last'),calculates the next rotation date for a monthly rotation schedule.

    If the rotation day has not yet occurred in the current month, the next rotation date
    will be on the rotation day of the current month. If the rotation day has already
    occurred in the current month, the next rotation date will be on the rotation day of
    the next month.

    If 'last' is specified as the rotation day, the next rotation date will be on the
    last day of the current month.

    Parameters:
    - start_date: The start date of the rotation schedule, as a date object.
    - rotate_every: The rotation day, specified as an integer between 1 and 31, or the
      string 'last'.

    Returns:
    - A date object representing the next rotation date.
    last   r   dayrg   )month)calendar
monthrangeyearrt   rV   rU   rs   r   rX   replacer   )rk   rotate_everylast_daynext_changenext_month_starts        r]   get_next_monthly_dater}   ~   s   , v&&z
8H8HI!L8}|$L ~~%):	Rz
0@0@,OK(  &&z
8H8HI!L%--(-;iQ>OO	(*22|2DK '  	R!1!1A!5qK {//1B1BLQK '	R  	( ((/?/E/E/I(J#$g,g' 
 	(s&   !C" D7 "AD43D47AF ?F c                   (     e Zd ZdZ fdZd Z xZS )	ModelFormzK
    Override of Django ModelForm to add initial styling and defaults.
    c           	         t        |   |i | t        | j                         t	        t
        j                  dd       }t        j                         }t        j                         }d}d}d}| j                  j                         D ]4  \  }	}
|
j                  }|
j                  rt        |
j                        nd}t        |t         j"                        r[||
_        d|_        d|_        dg|
_        |j,                  j/                  d|      }|j,                  j1                  | d	|d
       t        |t         j2                        r\||
_        d|_        d|_        dg|
_        |j,                  j/                  d|      }|j,                  j1                  | d	|d
       !t        |t         j4                  t         j6                  t         j8                  t         j:                  t         j<                  f      rn|j,                  j/                  d|      }|j,                  j1                  | d	|
j                  r#t        |
j                  j?                               ndd
       t        |t         j@                        rut        |
t         jB                        s t        d      j)                  |      |
_"        |j,                  j/                  d|      }|j,                  j1                  d|i       ut        |t         jF                        rA|j,                  j/                  d|      }|j,                  j1                  | d	|ddd       t        |t         jH                  t         jJ                  f      s|j,                  j/                  d|      }|j,                  j1                  d|i       7 |rt	        |jL                  dd       }|rxd| j                  v r|| j                  d   _        d| j                  v rG| j                  d   }t	        |dd       }|r(|jN                  }||v r|n|jQ                         |_        y y y y y )Nrequestoh-input w-100/oh-select oh-select-2 select2-hidden-accessibleoh-switch__checkbox r   z%Y-%m-%dclassz form-controlr   placeholdertime%H:%M---Choose {label}---label   (   r   r   rowscolsemployee_getemployee_id
company_idget_company))super__init__r    fieldsgetattrrG   rH   r   todayr   nowitemswidgetr   rS   
isinstancer   r   initial
input_typeformatinput_formatsattrsgetupdate	TimeInputNumberInput
EmailInputr   	FileInputURLInputtitleSelectModelMultipleChoiceFieldempty_labelTextareaCheckboxInputCheckboxSelectMultipleuserquerysetfirst)selfargskwargsr   r   r   default_input_classselect_classcheckbox_class
field_namefieldr   r   existing_classemployeecompany_fieldcompanyr   	__class__s                     r]   r   zModelForm.__init__   s   $)&)$-<<iN

lln.H.!%!2!2!4 M	?J\\F&+kkAekkNrE &%//2 %$*! *'1l#!'!1!1';N!O##$2#3=!A', FEOO4 #$*! ''.i#!'!1!1';N!O##$2#3=!A', %%$$OOOONN	 "(!1!1';N!O##$2#3=!AAFq):):)<'=RT FELL1!%)G)GH()*@(A(H(Hu(H(UE%!'!1!1'<!H##Wn$=> FENN3!'!1!1';N!O##$2#3=!A', ! "	 ,,e.J.JK "(!1!1'>!J##Wn$=>[M	?` w||^TBH DKK/9ADKK.64;;.$(KK$=M%htDG#0#9#9'.(':G@P &-  /	  rn   c                    t        | d      rzt        | j                  d      rd| j                  j                  }t        |j                  d      r,|j                  j                  r|j                  j                  S |j                  S y)z
        Returns the verbose name of the model associated with the form.
        Provides fallback values if no model or verbose name is defined.
        _metamodelverbose_namer   )hasattrr   r   r   __name__)r   r   s     r]   r   zModelForm.verbose_name(  sa    
 4!gdjj'&BJJ$$Eu{{N38P8P{{///>>!rn   )r   
__module____qualname____doc__r   r   __classcell__r   s   @r]   r   r      s    kZ
rn   r   c                   "     e Zd ZdZ fdZ xZS )FormzF
    Overrides to add initial styling to the django Form instance
    c                    t        |   |i | | j                  j                         D ]  \  }}|j                  }t        |t        j                  t        j                  t        j                  f      rK|j                  Yt        |j                        }|j                  j                  j                  d|d       t        |t        j                  f      rsd}|j                  |j                  j                  dd      }t        d      j!                  |      |_        |j                  j                  j                  dd	i       %t        |t        j$                        rAt        |j                        }|j                  j                  j                  d|d
dd       t        |t        j&                  t        j(                  f      s|j                  j                  j                  ddi        y )Nr   r   r   id r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   rS   r   r   r   rx   r   r   r   r   r   )r   r   r   r   r   r   r   r   s          r]   r   zForm.__init__:  s   $)&)!%!2!2!4 #	LJ\\F**E,<,<eooN ;;*ekkNELL&&--"25I FU\\O4;;*!KK//c:E$%&<$=$D$D5$D$Q!""))OP FU^^5%++""))!1', ! "	 ''00 ""))74I*JKG#	Lrn   )r   r   r   r   r   r   r   s   @r]   r   r   5  s    %L %Lrn   r   c                       e Zd ZdZ	  ej
                  ej                  j                         D  cg c]  }|j                  |j                  f c}} dddi      Z G d d      Zd	fd	ZxZS c c}} w #  Y xY w)
UserGroupFormz!
    Django user groups form
    FrequiredPlease choose a permission.)choicesr   error_messagesc                       e Zd ZdZeZddgZy)UserGroupForm.Meta3
        Meta class for additional options
        namepermissionsN)r   r   r   r   r   r   r    rn   r]   Metar   r  s    	 -(rn   r   c                 0   t         |   d      }| j                  r| j                  }|j                          | j                  d   }t        j
                  j                  |      }|j                  j                  |       |r|j                          |S )z)
        ModelForm save override
        Fcommitr   codename__in)	r   saveinstancecleaned_datar   objectsfilterr   set)r   r   grouppermissions_codenamesr   r   s        r]   r   zUserGroupForm.savez  s     E*==MME

 !% 1 1- @ ((//=R/S 	k*JJLrn   T)r   r   r   r   r   MultipleChoiceFieldr   r   allcodenamer   r   r   r   r   .0permr   s   00@r]   r   r   b  s{    	/e//<F<N<N<R<R<TUDdmmTYY/U9
) ) # Vs   )A8 A2
A8 2A8 8A<r   c                        e Zd ZdZ ej
                  ej                  j                         d      Z	 ej                  ej                  j                               Z fdZd Z xZS )AssignUserGroupz
    Form to assign groups
    Fr   r   r   c                 N    t        |   |i | t        | j                         y Nr   r   r    r   r   r   r   r   s      r]   r   zAssignUserGroup.__init__  !    $)&)$rn   c                    | j                   d   }| j                   d   }|D cg c]  }|j                  s|j                   }}t        j                  j	                  |j
                  j                               }|D cg c]  }|j                  s|j                   }}|D ]  }|j                  j                  |        |D ]  }|j                  j                  |        |S c c}w c c}w )z
        Save method to assign group to selected employees only.
        It removes the group from previously assigned employees
        and assigns it to the new ones.
        r   r   )employee_user_id__in)
r   employee_user_idrE   r   r   user_setr   groupsremoveadd)r   r   assigning_employeeseassigning_usersexisting_employeesexisting_usersr   s           r]   r   zAssignUserGroup.save  s     !!'*"//
;(;
#$q?Q?QA
 

 &--44!&!3!3!5 5 
 );
#$a>P>PA
 
 # 	&DKKu%	& $ 	#DKKOOE"	# %

s   C)C)C.C.)r   r   r   r   r   r   rE   r   r   r   ModelChoiceFieldr   r   r   r   r   r   s   @r]   r   r     s[     .u--!!%%'%H #E""EMM,=,=,?@E%rn   r   c                        e Zd ZdZ ej
                  ej                  j                         d      Z	 ej                  ej                  j                               Z fdZd Z xZS )AddToUserGroupFormz,
    Form to add employee in to  groups
    Fr   r   c                 N    t        |   |i | t        | j                         y r   r   r   s      r]   r   zAddToUserGroupForm.__init__  r   rn   c                     | j                   d   }| j                   d   }|j                  j                  j                          |D ]'  }|j                  j                  j	                  |       ) |S )zK
        Save method to assign the selected groups to the employee
        r   r   )r   r   r  clearr  )r   r   r  r   s       r]   r   zAddToUserGroupForm.save  sj     $$Z0""7+!!((..0 	8E%%,,007	8rn   )r   r   r   r   r   r   r   r   r   r   r	  rE   r   r   r   r   r   s   @r]   r  r    sW     +E**EMM4E4E4GRWXE%u%%x/?/?/C/C/EFH%	rn   r  c            
       R   e Zd ZdZ eej                  j                          ede	ddd      d      Z
	  ej                  ej                  j                         D  cg c]  }|j                  |j                  f c}} d	d
i      ZfdZfdZd ZxZS c c}} w #  Y xY w)AssignPermissionz(
    Forms to assign user permision
    employee-widget-filterfemployee_filters.htmlT)filter_route_namefilter_classfilter_instance_contex_namefilter_template_pathr   rE   r   r   r   r   r   )r   r   c                 N    t        |   |i | t        | j                         y r   r   r   s      r]   r   zAssignPermission.__init__  r   rn   c                     | j                   j                  d      }|r| j                  j                  dd        t        |           y )Nr   )datagetlisterrorspopr   clean)r   empsr   s     r]   r  zAssignPermission.clean  s8    yy  ,KKOOJ-rn   c                 |   t         j                  j                  | j                  j	                  d            j                  dd      }| j                  d   }t        j                  j                  |      }t        j                  j                  |      }|D ]  }|j                  j                  |        | S )z>
        Save method to assign permission to employee
        r   id__inr   Tflatr   r   )rE   r   r   r  r  values_listr   r   r   user_permissionsr   )r   user_idsr   usersr   s        r]   r   zAssignPermission.save  s     ##**99$$Z0 + 

+(t+
4 	 ''6 ((//[/I##8#4 	3D!!%%k2	3 rn   )r   r   r   r   rK   rE   r   r   rL   rC   r   r   r   r   r   r   r   r   r  r   r   r   s   00@r]   r  r    s     '!!%%''6'(+!8
 
H/e//<F<N<N<R<R<TUDdmmTYY/U9
%' V
s   )B"  B
?B" B" "B&r  c                   B    e Zd ZdZdddddddZ G d d      Zd Zd Zy)	CompanyFormz
    Company model's form
       )r   addresscountrystatecityzipc                        e Zd ZdZeZdZg dZy)CompanyForm.Metar   __all__)date_formattime_format	is_activeN)r   r   r   r   r'   r   r   excluder   rn   r]   r   r3    s    	 =rn   r   c                     d}|j                   |kD  rt        d      g d}t        j                  j	                  |j
                        d   j                         }||vrt        d      y )Ni  P z"File size should be less than 5MB.)z.jpgz.jpegz.pngz.webpz.svgrq   zUnsupported file extension.)sizer   ospathsplitextr   lower)r   filemax_sizevalid_extensionsexts        r]   validate_imagezCompanyForm.validate_image  sh    "99x!"FGG Fggtyy)!,224&&!"?@@ 'rn   c                 b    | j                   j                  d      }|r| j                  |       |S )Nicon)r   r   rC  )r   rE  s     r]   
clean_iconzCompanyForm.clean_icon+  s.      $$V,%rn   N)r   r   r   r   r   r   rC  rF  r   rn   r]   r+  r+    s7    
 D> >
Arn   r+  c                   .    e Zd ZdZdddZ G d d      Zy)DepartmentFormz!
    Department model's form
    r,  )
departmentr   c                   L    e Zd ZdZeZdZdgZd ej                  ddi      iZ
y)	DepartmentForm.Metar   r4  r7  r   r   oh-select oh-select-2r   N)r   r   r   r   r)   r   r   r8  r   SelectMultiplewidgetsr   rn   r]   r   rK  9  s:    	 -.%..g?V5WX
rn   r   Nr   r   r   r   r   r   r   rn   r]   rH  rH  2  s     B/D

 

rn   rH  c            	            e Zd ZdZ ej
                  ej                  j                         d ej                  ddd            Z
ddd	Z G d
 d      Z fdZ fdZdef fdZ xZS )JobPositionForm"
    JobPosition model's form
    r)   zoh-select oh-select-2 w-100height:45px;r   stylerM  r   r   r   r,  )job_positiondepartment_idc                        e Zd ZdZeZdZg dZy)JobPositionForm.Metar   r4  )r7  rY  r   N)r   r   r   r   r3   r   r   r8  r   rn   r]   r   r[  U  s    	 >rn   r   c           	          t        |   |i | | j                  j                  rTt	        j
                  | j                  d   j                  dt	        j                  ddd            | j                  d<   y y )NrY  r)   oh-select oh-select2 w-100rT  rU  rM  rW  )	r   r   r   pkr   r	  r   r   r   r   s      r]   r   zJobPositionForm.__init__^  sl    $)&)==+0+A+A_5>>"||!=!/	,DKK( rn   c           	         t         |          }|j                  d      }|j                  d      }|rt        |d      s|g}| j                  j
                  rx|rv|rt|D ]o  }t        j                  j                  ||      j                  | j                  j
                        j                         sWt        t        d| d|              |S )z,
        Perform custom validation.
        rX  rY  __iter__rY  rX  r^  zJob position 'z"' already exists under department )r   r  r   r   r   r^  r3   r   r   r8  existsr   rS   )r   r   rX  department_idsrY  r   s        r]   r  zJobPositionForm.cleanl  s     w}#''7%))/:'.*"E,-N==!/ ''..&3, /  W 0 0W1VX	 *,\N:\]j\kl  rn   returnc                    | j                   j                  s9t        t        d      }t        j
                  j                  | j                  j                  d            }g }|D ]  }t               }||_
        | j                  d   |_        | j                  d   }	t        j
                  j                  ||	      j                         rt        j                  |d|        n/t        j                  |t!        d             |j#                          |j%                  |j                          t        j
                  j                  |      S t'        
| D  |g|i | y )Nr   rY  r"  rX  ra  "Job position already exists under z+Job position has been created successfully!)r   r^  r   rH   r)   r   r   r  r  r3   rY  rX  rc  r	   r\   successrS   r   appendr   )r   r   r   r   r   rI  	positionsdepposition	form_datar   s             r]   r   zJobPositionForm.save  s9   }}ni8G#++22yy((9 3 J I! .&=),&(,		.(A% IIn5	&&--"%I . &( NN7.PQTPU,VW$$#P!Q MMO  -. &&--Y-??V-d-f-rn   )r   r   r   r   r   r   r)   r   r   rN  rY  r   r   r   r  r   r   r   r   s   @r]   rR  rR  F  sz     3E22##'')#u##9NS
M 4D? ?8.s . .rn   rR  c            	            e Zd ZdZ eej                  j                         ej                  j                  d      j                   ej                  ddd            Z G d d	      Z fd
Z fdZ xZS )JobPositionMultiFormrS  rY  r]  rT  rU  rM  rW  c                       e Zd ZeZdZddgZy)JobPositionMultiForm.Metar4  rY  r7  N)r   r   r   r3   r   r   r8  r   rn   r]   r   rq    s    "K0rn   r   c                    t         |          }| j                  j                  d      }| j                  j	                  d      }t
        j                  j                  ||      }|j                         rx|j                  dd      }t        j                  j                  |      j                  dd      }t        dt        d      j                  d	j                  |            i      |S )
zd
        Validate that the job position does not already exist in the selected departments.
        rY  rX  )department_id__inrX  Tr$  r"  rI  z$Job position already exists under {}, )r   r  r  r  r   r3   r   r   rc  r&  r)   r   rS   r   join)r   r   rd  rX  existing_positionsexisting_deps	dep_namesr   s          r]   r  zJobPositionMultiForm.clean  s     w}**?;yy}}^4(0077,< 8 
 $$&.::?QU:VM"**111GSS4 T I "#Q'M%N%U%U		),&  rn   c                 p   | j                   j                  st        t        d      }| j                  j                  d      }| j                  j                  d      }g }|D ]  }t        j                  j                  |      }t        j                  j                  ||      j                         rt        j                  |d|        lt        ||      }	|	j                          |j                  |	j                          t        j                  j                  |      S t!        
| 8  |i |S )zF
        Save the job positions for each selected department.
        r   rY  rX  r   ra  rg  r"  )r   r^  r   rH   r  r  r   r)   r   r3   r   rc  r	   r\   r   ri  r   )r   r   r   r   rd  rX  rj  dep_idrk  rl  r   s             r]   r   zJobPositionMultiForm.save  s    }}ni8G!YY..?N99==8LI( 	2 ((,,,7&&--"%L . &( NN7.PQTPU,VW*<XHMMO$$X[[1	2 &&--Y-??w|T,V,,rn   )r   r   r   r   rK   r)   r   r   r3   r   	get_fieldr   r   rN  rY  r   r  r   r   r   s   @r]   ro  ro    st     ,##'')))/:GG#u##5'
	M1 1
4- -rn   ro  c            	            e Zd ZdZdddZ ej                  ej                  j                         d ej                  ddd      	      Z fd
Z G d d      Z fdZdef fdZ xZS )JobRoleFormz
    JobRole model's form
    r,  )job_position_idjob_rolezJob Positionw-100rT  rU  rM  rW  c                    t        |   |i | | j                  j                  st	        j
                  | j                  d   j                  t        j                  j                  d      j                        | j                  d<   	 t        | j                  d      r@| j                  j                  r)| j                  j                  | j                  d   _        y y y y # t        $ r Y y w xY w)Nr  )r   r   )r   r   r   r^  r   r   r   r   r4   r   r|  r   r   r  r   	Exceptionr   s      r]   r   zJobRoleForm.__init__  s    $)&)}}-2-K-K%67@@mm--.?@MM.DKK)*
4==*;<A^A^=A]]=Z=ZDKK 12: B_<    s   
AC" "	C.-C.c                        e Zd ZdZeZdZg dZy)JobRoleForm.Metar   r4  )r7  r  r   N)r   r   r   r   r4   r   r   r8  r   rn   r]   r   r    s    	 @rn   r   c                    t         |          }|j                  d      }|j                  d      }|rt        |d      s|g}| j                  j
                  rg|re|rct        j                  j                  ||      j                  | j                  j
                        }|j                         rt        | d      |S )Nr  r  r`  )job_position_id__inr  rb  z' already exists under this job position)r   r  r   r   r   r^  r4   r   r   r8  rc  r   )r   r   r  r  existing_rolesr   s        r]   r  zJobRoleForm.clean  s    w}&**+<=##J/7?J#G./O==H$__33$3h 4 g))g*  $$&%j GH  rn   re  c                 \   | j                   j                  st        t        d      }t        j
                  j                  | j                  j                  d            }g }|D ]r  }t               }||_
        | j                  d   |_        	 |j                          t        j                  |t        d             |j#                  |j                         t t        j
                  j                  |      S t%        	| 0  |g|i | y #  t        j                   |d|        Y nxY w)Nr   r  r"  r  z'Job role has been created successfully!zRole already exists under )r   r^  r   rH   r3   r   r   r  r  r4   r  r  r   r	   rh  rS   infori  r   )
r   r   r   r   r   job_positionsrolesrl  roler   s
            r]   r   zJobRoleForm.save'  s   }}ni8G'//66yy(():; 7 M E) &y'/$ $		* 5TIIK$$#L!M
 TWW%& ??)))77V-d-f-	TMM'-Gz+RSs   /DD+)r   r   r   r   r   r   r   r3   r   r   rN  r  r   r   r  r   r   r   r   s   @r]   r~  r~    s}      "r2D4e44$$((*#u## '
	OA A&.s . .rn   r~  c                   .    e Zd ZdZdddZ G d d      Zy)WorkTypeFormz
    WorkType model's form
    r,  )	work_typer   c                       e Zd ZdZeZdZdgZy)WorkTypeForm.Metar   r4  r7  N)r   r   r   r   r?   r   r   r8  r   rn   r]   r   r  E  s    	 -rn   r   NrP  r   rn   r]   r  r  >  s     2.D   rn   r  c                   ^     e Zd ZdZddddZ G d d      Z fdZd Z fdZd
 fd		Z	 xZ
S )RotatingWorkTypeFormz'
    RotatingWorkType model's form
    r,  )r   
work_type1
work_type2c                   Z    e Zd ZdZeZdZddgZ eddi       e	j                         dZy	)
RotatingWorkTypeForm.Metar   r4  r   r7  typer   rM  )rk   additional_dataN)r   r   r   r   r9   r   r   r8  r   r   r   rO  r   rn   r]   r   r  Z  s?    	 ! +.#66*:;0u002
rn   r   c                 j    t        	   |i | d}d
 fd	} j                  j                         D ]%  }|j	                  d      s|dz  } |||dk         '  j
                  j                  d      }|r|j                  d      nd }|rd}|D ]  } |d| |dk  |	       |dz  } | _        y )Nr   c           
          t        j                  t        j                  j	                         t        dd| d|  d      |t        d      |d      j                  | <   y )	Nz/add-remove-work-type-fieldszoh-select oh-select-2 mb-3 id_r   r   r   
delete_urlr   z---Choose Work Type---r   )r   r   r   r   r   r   )r   r	  r?   r   r   rB   rS   r   )work_type_keyr   r   r   s      r]   create_work_type_fieldz=RotatingWorkTypeForm.__init__.<locals>.create_work_type_fieldk  sb    ).)?)?!))--/.=!> - #M?3 "67*DKK&rn   r  rq   r   r  additional_work_typesrP   r   r   )r   r   r  keys
startswithr   r   work_type_counts)
r   r   r   r  r  keyr  r  work_type_idr   s
   `        r]   r   zRotatingWorkTypeForm.__init__g  s    $)&)	$ 99>># 	CC~~k* A% &s,<,AB	C
 ,,**+<=<KO 78QU 	 !  5 && 012$)(
 !A% & !1rn   c                 "    d| i}t        d|      S )Nformz9base/rotating_work_type/htmx/rotating_work_type_as_p.htmlr   r   r   r   contexts       r]   as_pzRotatingWorkTypeForm.as_p  s    4.G
 	
rn   c                 R   t         |          }g }t        | j                  j                  j                               }| j                  j                         D ]3  \  }}| d|vs|j                  d      s |s#|j                  |       5 |rd|vs|d   i |d<   ||d   d<   |S )N_idr  r  r  
r   r  listr   __dict__r  r  r   r  ri  )r   r   r  model_fieldsr  rY   r   s         r]   r  zRotatingWorkTypeForm.clean  s    w} "DMM22779:))//+ 	4JC%s</NN;/%,,U3	4 !!5 12:24./ & *+' rn   c                 .   t         |   d      }| j                  j                  d      r?|j                  i |_        | j                  d   j                  d      |j                  d<   nd |_        |r |j                          | j                          |S )NFr   r  r  r   r   r   r   r  save_m2mr   r   r   r   s      r]   r   zRotatingWorkTypeForm.save  s    7<u<-  !23''/+-(@D@Q@Q!Ac)* $$%<= (,H$MMOMMOrn   r   r   r   r   r   r   r   r   r  r  r   r   r   s   @r]   r  r  O  s>    
 D
 
)1V
2 rn   r  c                   .    e Zd ZdZddddddddZ ej                  ed ed            Z	 ej                  d ed      	      Z ej                  ej                  ej                   ed
            Z G d d      Z fdZd Z fdZd fd	Z xZS )RotatingWorkTypeAssignForm-
    RotatingWorkTypeAssign model's form
    r,  )r   rotating_work_type_idrk   based_onrotate_after_dayrotate_every_weekendry   dailyBased onr   r   r      Rotate after dayr   r   
Start dater   r   r   c                   v    e Zd ZdZeZdZg dZ eddi       e	       dZ
 ed       ed	       ed
      dZy)RotatingWorkTypeAssignForm.Metar   r4  next_change_datecurrent_work_typenext_work_typer7  r  r  r   rM  )rk   r7  	Is ActiveRotate every weekendRotate every)r7  r  ry   N)r   r   r   r   r:   r   r   r8  r   r   rO  rS   labelsr   rn   r]   r   r    sV    	 '
 $66*:;$

 ;$%&<$=n-
rn   r   c           	      ^   t        |   |i | t        | j                         | j                  j	                         D ]  \  }}|j
                  rd| j                  |   _        | j                  d   j                  j                  j                  dddd       | j                  d   j                  j                  j                  dddd       | j                  d	   j                  j                  j                  d
dd       | j                  d   j                  j                  j                  ddd       t        j                  d
ddd      | j                  d   _        | j                  d   j                  j                  j                  ddi       | j                  d   j                  j                  j                  ddi        t        |   |i | t        | j                         t        t        j                  dd       }|j                  j!                  d      | j                  d   _        | j$                  j&                  sn|j                  j!                  d      sSt)        t*        j,                  j/                  d      t1        dt2        dd      t5        d             | j                  d<   | j                  d   j                  j                  j                  dddd       | j                  d   j                  j                  j                  dddd       | j                  d	   j                  j                  j                  d
dd       | j                  d   j                  j                  j                  dd!d       t        j                  d
ddd      | j                  d   _        | j                  d   j                  j                  j                  ddi       | j                  d   j                  j                  j                  ddi       y )"N *r  r  zgdisplay:none; height:50px; border-radius:0;border:1px                        solid hsl(213deg,22%,84%);Tr   rV  zdata-hiddenry   hdisplay:none; height:50px; border-radius:0;border:1px                         solid hsl(213deg,22%,84%);r  w-100 oh-input height:50px; border-radius:0;rU  r  z\ height:50px; border-radius:0; border:1px solid                         hsl(213deg,22%,84%);r   r   r  rV  rM  rk   r  r   rL  r   r   emp_idF)employee_work_info__isnullr  r  r  r  r  r  r  	Employeesr  C height:50px; border-radius:0;border:1px solid hsl(213deg,22%,84%);)r   r   r    r   r   r   label_suffixr   r   r   r   r   r   rG   rH   GETr   r   r   r^  rK   rE   r   r   rL   rC   rS   )r   r   r   r   r   r   r   s         r]   r   z#RotatingWorkTypeAssignForm.__init__  s   $)&)$!%!2!2!4 p	J~~7;J'4KK./66<<CC$4#'	 KK'..44;;$4#'	 KK*+2288??-= KK
#**0077$. 05-"=0DKK%, KK/077==DD4
 KK&--33::4[p	f Gd-f-DKK(1@@)TRG181JDKK&.==##GKKOOH,E-D%--44PU4V3*B%347-D	 K.	.M* KK./66<<CC$4#'	 KK'..44;;$4#'	 KK*+2288??-= KK
#**0077$b 05-"=0DKK%, KK/077==DD4
 KK&--33::4rn   c                     | j                   j                  r| j                  j                  d      S | j                  j                  d      }t	        |t
              r|S |r|d   S t        t        d            S )Nr   r   This field is requiredr   r^  r   r   r   rE   r   rS   r   employee_idss     r]   clean_employee_idz,RotatingWorkTypeAssignForm.clean_employee_idn  sj    ==$$((77,,00?L,1##'?**1-E+FGGrn   c                    | j                   j                  rt        |          S t        |           t        j
                  j                  | j                  j                  d            j                         | j                   _
        | j                  j                  dd        | j                   j                  t        dt        d      i      t        |           t        |          }d| j                  v r| j                  d= |S Nr   rz  r  r  r   r^  r   r  rE   r   r   r  r   r   r   r  r  r   rS   r   r   r   s     r]   r  z RotatingWorkTypeAssignForm.clean{  s    ==7=?"$,$4$4$;$;yy}}]+ %< %

%' 	! 	t,==$$,!=!4L2M"NOOw},./rn   c           	         | j                   j                  rt        j                  j	                  | j                   j                        }t               }t        j                  j	                  | j                  d         }| j                  d   }g d}|j                  |j                               }| j                  d   |_        |j                  j                  |_        |j                  |_        d|j"                  d<   | j                  d   }	| j                   j$                  }
|	d	k(  rt'        ||
      }|| j                   _        n|	d
k(  rJ| j                   j(                  }| j                   j$                  }
t+        |
|      }|| j                   _        nY|	dk(  rT| j                   j$                  t-        t/        | j                  j	                  d                  z   | j                   _        t0        | e         S | j                  j5                  d      }t        j                  j	                  | j                  d         }| j                  d   }g d}|j                  |j                               }|D ]  }t        j                  j7                  |      j9                         }t               }||_        ||_        | j                  d   |_        | j                  d   |_        | j                  d   |_        | j                  j	                  d      |_         | j                  d   |_        | j                  d   |_!        | j                  d   |_        |j                  j                  |_        |jD                  |_        d|j"                  d<   | j                  d   }	| j                  d   }
|	d	k(  rt'        ||
      }||_        n||	d
k(  r2| j                  d   }| j                  d   }
t+        |
|      }||_        nE|	dk(  r@|j$                  t-        t/        | j                  j	                  d                  z   |_        |j3                           y )Nrz  r  r  mondaytuesday	wednesdaythursdayfridaysaturdaysundayrk   rq   next_work_type_indexr  ra   rc   r_   r  rg   r   ry   next_shift_index)#r   r^  rE   r   r   r:   r9   r  r   indexr>  r  employee_work_infor  r  r  r  r  rk   rm   ry   r}   r   rU   r   r   r  r   r   r  r   r  r  r  r  )r   r   managerr   rotating_work_type_assignrotating_work_typeday_name	day_namesrj   r  rk   	next_datery   r  r   r   s                  r]   r   zRotatingWorkTypeAssignForm.save  s   ==''++t}}/?/?+@H(>(@%!1!9!9!=!=9945 "> " (()?@HI #)9:J9=9J9J<9X%6++88 &7 8J7T7T%4PQ%556LM((4H11J8#.z:F	1:.Y&#}}99!]]55
1*lK	1:.W$151I1IITYY]]+=>?M 2. 7<>!  99,,];L!1!9!9!=!=9945 "> " (()?@HI #)9:J+ ,1#++22k2BHHJ,B,D)BT)?8@)5595F5Fz5R)27;7H7H7V)4=A=N=N >): >BYY]]&>): :>9J9J":)6 BFARAR*B)> >B=N=N >): //<< *; <N;X;X)8PQ)99:LM,,Z8!..|<
x' 2:z JIAJ->*#'#4#4^#DL!%!2!2<!@J 5j, OIAJ->(1<<#TYY]];M-N)OPQ .>
 *..0Y,1rn   )FNr   r   r   r   r   r   ChoiceFieldBASED_ONrS   r  IntegerFieldr  	DateFieldr   r   r   rk   r   r   r  r  r   r   r   s   @r]   r  r    s    
 !# "D( !u  7!J-XH)u))!1=O;PQ 

5??!L/J
 
0sjH$g1 g1rn   r  c                   v     e Zd ZdZ ej
                  ed ed            Z G d d      Z	 fdZ
 fdZ xZS )	 RotatingWorkTypeAssignUpdateFormr  r  r  r  c                       e Zd ZdZeZdZg dZd eddi      iZ	 e
d       e
d	       e
d
       e
d       e
d       e
d      dZy)%RotatingWorkTypeAssignUpdateForm.Metar   r4  r  rk   r  r   rM  r  r  r  r  r  r  rk   r  r  ry   r  r7  N)r   r   r   r   r:   r   r   r8  r   rO  rS   r  r   rn   r]   r   r    sj    	 '
 )66*:;
 L/ !"4 5$%&<$=n-*;
rn   r   c                    t        |   |i | t        | j                         | j                  j	                         D ]&  \  }}|j
                  sd| j                  |   _        ( | j                  d   j                  j                  j                  dddd       | j                  d   j                  j                  j                  dddd       | j                  d	   j                  j                  j                  d
dd       | j                  d   j                  j                  j                  ddd       t        j                  d
ddd      | j                  d   _        | j                  d   j                  j                  j                  ddi       | j                  d   j                  j                  j                  ddi       y )Nr  r  r  zcdisplay:none; height:50px; border-radius:0;border:1px                    solid hsl(213deg,22%,84%);Tr  ry   ddisplay:none; height:50px; border-radius:0;border:1px                     solid hsl(213deg,22%,84%);r  r  r  rU  r  zX height:50px; border-radius:0; border:1px solid                     hsl(213deg,22%,84%);r   r  rM  rk   r  r   rL  r   r   r   r    r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   s        r]   r   z)RotatingWorkTypeAssignUpdateForm.__init__  s   $)&)$!%!2!2!4 	<J~~7;J'4	< 	*+2288?? 0#		
 	N#**0077 0#		
 	&'..44;;)9	
 	J&&,,33 *	
 ,1??)9,
L!( 	+,3399@@0	

 	M"))//660	
rn   c                 d   | j                   d   }g d}|j                  |j                               }| j                   d   }| j                  j                  }|dk(  rt        ||      }|| j                  _        n|dk(  rJ| j                  j                  }	| j                  j                  }t        ||	      }|| j                  _        nY|dk(  rT| j                  j                  t        t        | j                  j                  d                  z   | j                  _        t        
| 9         S 	Nr  r  r  ra   rc   r_   r  rg   r   r  r>  r   rk   rm   r  ry   r}   r   rU   r  r   r   r   r   r   r   r  r  rj   r  rk   r  ry   r   s             r]   r   z%RotatingWorkTypeAssignUpdateForm.saveN      $$%;<
	 __X^^%56
$$Z0]]--
x*:zBI-6DMM*"==55L11J-j,GI-6DMM* -1]]-E-E	'9:;I .DMM* w|~rn   r   r   r   r   r   r  r   rS   r  r   r   r   r   r   s   @r]   r  r    s>     !u  7!J-XH
 
44
l rn   r  c                   .    e Zd ZdZdddZ G d d      Zy)EmployeeTypeFormz
    EmployeeType form
    r,  )employee_typer   c                       e Zd ZdZeZdZdgZy)EmployeeTypeForm.Metar   r4  r7  N)r   r   r   r   r0   r   r   r8  r   rn   r]   r   r  s  s    	 -rn   r   NrP  r   rn   r]   r  r  l  s      r2D   rn   r  c                   F     e Zd ZdZddddddZ G d d      Z fdZ xZS )EmployeeShiftFormz
    EmployeeShift Form
    r,  )employee_shiftweekly_full_time	full_timer   grace_time_idc                        e Zd ZdZeZdZddgZy)EmployeeShiftForm.Metar   r4  rh   r7  N)r   r   r   r   r-   r   r   r8  r   rn   r]   r   r    s    	 ;'rn   r   c                     | j                   d   }t        |       | j                   d   }t        |       t        |          S )Nr  r  )r  r^   r   r  )r   r  r   s     r]   r  zEmployeeShiftForm.clean  s<    IIk*	Y'II01	Y'w}rn   )r   r   r   r   r   r   r  r   r   s   @r]   r  r  }  s4    
 D( ( rn   r  c                   F     e Zd ZdZ G d d      Z fdZd Z fdZ xZS )EmployeeShiftScheduleUpdateForm,
    EmployeeShiftSchedule model's form
    c                   v    e Zd ZdZeZdZddgZ ej                  ddi       ej                  ddi      dZ
y	)
$EmployeeShiftScheduleUpdateForm.Metar   r4  r7  is_night_shiftr  r   rM  
start_timeend_timeN)r   r   r   r   r/   r   r   r8  r   r   rO  r   rn   r]   r   r$    sK    	 & 01)%//0@A'vv.>?
rn   r   c                 0   t        |   |i | |j                  d      }|r|j                  r|j                  j	                  d      nd | j
                  d   _        |j                  r|j                  j	                  d      nd | j
                  d   _        t        j                  d      r;|j                  r|j                  j	                  d      nd | j
                  d   _        t        j                  d      s9| j
                  j                  dd        | j
                  j                  dd        y t        j                  dd	d
      | j
                  d   _        | j
                  d   j                  j                  j!                  ddi       y )Nr   r   r'  r(  
attendanceauto_punch_out_timeis_auto_punch_out_enabledr   oh-input w-100 form-controlr  r   rM  onchangetoggleDivVisibility(this))r   r   r   r'  strftimer   r   r(  r   is_installedr+  r  r   r   r   r   r   )r   r   r   r   r   s       r]   r   z(EmployeeShiftScheduleUpdateForm.__init__  sW   $)&)::j)9A9L9L##,,W5RV KK%- 8@7H7H!!**73d KK
#+   .  33 0099'B 12:   .KKOO148KKOO7>8=%0MN9DKK-.5 KK34;;AAHH89rn   c                 &    d| i}t        d|      }|S zS
        Render the form fields as HTML table rows with Bootstrap styling.
        r  zhorilla_form.htmlr   r   r  
table_htmls      r]   r  z$EmployeeShiftScheduleUpdateForm.as_p       
 4.%&97C
rn   c                    t         |          }t        j                  d      rh|j	                  d      }|j	                  d      }|j	                  d      }|r3|st        dt        d      i      ||k  rt        dt        d      i      |S )Nr*  r,  r+  r(  IAutomatic punch out time is required when automatic punch out is enabled.=Automatic punch out time cannot be earlier than the end time.)r   r  r   r2  r   r   rS   )r   r   auto_punch_out_enabledr+  r(  r   s        r]   r  z%EmployeeShiftScheduleUpdateForm.clean  s    w}\*%1%5%56Q%R""."2"23H"I#''
3H%*)11 k4  )83)11 _4  rn   )	r   r   r   r   r   r   r  r  r   r   s   @r]   r!  r!    s&    
 
: rn   r!  c                        e Zd ZdZdddZ ej                  ej                  j                               Z
 G d d      Z fdZd Z fd	Zd fd
	Zd Z xZS )EmployeeShiftScheduleFormr"  r,  )rs   r   r   c                   R    e Zd ZdZeZg dZg dZ eddi       eddi      dZ	y)	EmployeeShiftScheduleForm.Metar   )shift_idminimum_working_hourr'  r(  r,  r+  r   rs   )r7  rs   r%  r  r   rM  r&  N)
r   r   r   r   r/   r   r   r8  r   rO  r   rn   r]   r   r?    s=    	 &	
 9#66*:;!(89
rn   r   c                    |j                  d      x}r}|j                  j                  d      |j                  j                  d      d}t	        j
                  d      r,|j                  r|j                  j                  d      nd |d<   ||d<   t        |    |i | | j                  j                  rWt        j                  t        j                  j                         t        j                   ddd	
            | j"                  d<   | j"                  d   j$                  j&                  j)                  dt+        t-        j.                               i       | j"                  d   j$                  j&                  j)                  dt+        t-        j.                               i       t	        j
                  d      s9| j"                  j1                  dd        | j"                  j1                  dd        y t        j2                  ddd
      | j"                  d   _        | j"                  d   j$                  j&                  j)                  ddi       y )Nr   r   r&  r*  r+  r   r]  rT  rU  rM  )r   r   rs   r   r@  r,  r   r-  r.  r/  r0  )r   r'  r1  r(  r   r2  r+  r   r   r   r^  r   r	  r.   r   r   r   r   r   r   r   rV   uuiduuid4r  r   )r   r   r   r   r   r   s        r]   r   z"EmployeeShiftScheduleForm.__init__  s   zz*--8- '11::7C$--66w?G   .  33 0099'B -.
 !(F9$)&)==!&!7!7)11557||!=!/"DKK 	E!!''..c$**,6G/HIJ&&,,33T3tzz|;L4MN  .KKOO148KKOO7>8=%0MN9DKK-.5 KK34;;AAHH89rn   c                 &    d| i}t        d|      }|S r4  r   r5  s      r]   r  zEmployeeShiftScheduleForm.as_pC  r7  rn   c           	         t         	|          }t        j                  d      rh| j                  d   }| j                  d   }| j                  d   }|r|st        dt        d      i      |r|r|r||k  rt        dt        d      i      | j                  j                  r|j                  d      }| d   j                         }|rt        |d	      s|g}| j                  j                  r|r|rt        j                  j                  ||
      }|j                         }|j!                  | j                  j                        j#                         r%t        t        d|j$                   d| d            |S )Nr*  r,  r+  r(  r9  r:  r@  rs   r`  rs   r@  rb  z#Shift schedule already exists for 'z' on 'z' )r   r  r   r2  r   r   rS   r   r^  r   rY   r   r/   r   r   r   r8  rc  rs   )
r   r   r;  r+  r(  r@  	day_fieldshiftshiftsr   s
            r]   r  zEmployeeShiftScheduleForm.cleanL  s   w}\*%)%6%67R%S""&"3"34I"J((4H%*)11 k4  &*=(&1)11 _4  ==#''
3HU))+IJ!?&K	}}H-55<<!H =  ==DMM$4$4=5<<>)A&**VT\S]]_` 
 rn   c                 V   t         |   d      }| j                  j                  s| j                  j                  d      D ]c  }| j                  j                         }|j                  dt        |      i       t        |      j                  d      }|j                          e |S )NFr   rs   )
r   r   r   r^  r  r  copyr   rV   r!  )r   r   r   rs   	data_copyshift_scheduler   s         r]   r   zEmployeeShiftScheduleForm.savew  s    7<u<-}}yy((/ & IINN,	  %S!23!@!K!P!P  "Q " ##%& rn   c                    | j                   j                  s| j                  d   }|D ]w  }t        j                  j                  || j                  d         j                         }|Bt        t        d      j                  t        |j                                     |j                         t        t        d            |j                         S y)z)
        Validation to day field
        rs   r@  rG  Nz)Shift schedule is already exist for {day}rr   zEmployee not chosen)r   r^  r   r/   r   r   r  r   r   rS   r   rs   )r   rh   rs   r*  s       r]   	clean_dayz#EmployeeShiftScheduleForm.clean_day  s     }}$$U+D 	2::AAdii
&; B %'  ))EFMM !#''
 N  	 zz|#%a(=&>??::<  rn   r   )r   r   r   r   r   r   r   r.   r   r   rs   r   r   r  r  r   rP  r   r   s   @r]   r=  r=    s]     R(D
(%
(
(!))--/C
 
,)V)V rn   r=  c                   ^     e Zd ZdZddddZ G d d      Z fdZd Z fdZd
 fd		Z	 xZ
S )RotatingShiftFormz$
    RotatingShift model's form
    r,  )r   shift1shift2c                   F    e Zd ZdZeZdZddgZd ej                         iZ
y)RotatingShiftForm.Metar   r4  r   r7  r  N)r   r   r   r   r7   r   r   r8  r   r   rO  r   rn   r]   r   rV    s3    	  +.$&7e&7&7&9:rn   r   c                     t        
   |i | d}d
 fd	} j                  D ]%  }|j                  d      s|dz  } |||dk         '  j                  j                         D ]5  }|j                  d      s j                  |   s%|dz  } |||dk         7  j                  j                  d      }|r|j                  d      nd }|r"d}|D ]  }	|	s |d| |dk  |		       |dz  } | _        y )Nr   c           
          t        j                  t        j                  j	                         t        dd| d|  d      |t        d      |      j                  | <   y )Nz/add-remove-shift-fieldszoh-select oh-select-2 mb-3r  r  r  z---Choose Shift---)r   r   r   r   r   )r   r	  r-   r   r   rB   rS   r   )	shift_keyr   r   r   s      r]   create_shift_fieldz6RotatingShiftForm.__init__.<locals>.create_shift_field  s_    %*%;%;&..224.9!= ) #I;/ "23&DKK	"rn   rI  rq   r   r  additional_shiftsrP   r  r   )	r   r   r   r  r  r  r   r   shift_counts)r   r   r   r\  rZ  r   r  r  r[  r@  r   s   `         r]   r   zRotatingShiftForm.__init__  s"   $)&)	  [[ 	=E(!"5,!*;<	=
 99>># 	;C~~g&499S>!"3(9:	;
 ,,**+<=8GO 34T 	 L- &&~.0A8 !A%L& )rn   c                 "    d| i}t        d|      S )Nr  z1base/rotating_shift/htmx/rotating_shift_as_p.htmlr   r  s       r]   r  zRotatingShiftForm.as_p  s    4.?
 	
rn   c                 R   t         |          }g }t        | j                  j                  j                               }| j                  j                         D ]3  \  }}| d|vs|j                  d      s |s#|j                  |       5 |rd|vs|d   i |d<   ||d   d<   |S )Nr  rI  r  r[  r  )r   r   r[  r  r  rY   r   s         r]   r  zRotatingShiftForm.clean  s    w}DMM22779:))//+ 	0JCc{,.3>>'3Ju!((/	0 !5 12:24./CTL*+,?@rn   c                 .   t         |   d      }| j                  j                  d      r?|j                  i |_        | j                  d   j                  d      |j                  d<   nd |_        |r |j                          | j                          |S )NFr   r  r[  r  r  s      r]   r   zRotatingShiftForm.save  s    7<u<-  !23''/+-(<@<M<M!=c%& $$%89 (,H$MMOMMOrn   r   r  r   s   @r]   rR  rR    s:     "3D; ;,)\
& rn   rR  c                   .    e Zd ZdZddddddddZ ej                  ed ed            Z	 ej                  d ed      	      Z ej                  ej                  ej                   ed
            Z G d d      Z fdZd Z fdZd fd	Z xZS )RotatingShiftAssignForm*
    RotatingShiftAssign model's form
    r,  )r   rotating_shift_idrk   r  r  r  ry   r  r  r  r  r  r  r  r  c                       e Zd ZdZeZdZg dZd eddi      iZ	 e
d       e
d	       e
d
       e
d       e
d      dZy)RotatingShiftAssignForm.Metar   r4  r  current_shift
next_shiftr7  r  rk   r  r   rM  zRotating Shiftr  r  r  r  )rc  rk   r7  r  ry   Nr   r   r   r   r8   r   r   r8  r   rO  rS   r  r   rn   r]   r   re  !  sc    	 $
 )66*:;
 "##3!4L/;$%&<$=n-
rn   r   c           	      L   t        |   |i | t        | j                         t	        t
        dd       }| j                  j                         D ]  \  }}|j                  rd| j                  |   _        | j                  d   j                  j                  j                  dddd       | j                  d   j                  j                  j                  dd	dd       | j                  d
   j                  j                  j                  ddd       | j                  d   j                  j                  j                  ddd       t        j                  dddd      | j                  d   _	        | j                  d   j                  j                  j                  ddi       | j                  d   j                  j                  j                  ddi        t        |   |i | t        | j                         |j                  j                  d      | j                  d   _        | j"                  j$                  so|j                  j                  d      sTt'        t(        j*                  j-                  dd      t/        dt0        dd      t3        d       !      | j                  d<   | j                  d   j                  j                  j                  dd	dd       | j                  d   j                  j                  j                  dd	dd       | j                  d
   j                  j                  j                  ddd       | j                  d   j                  j                  j                  ddd       t        j                  dddd      | j                  d   _	        | j                  d   j                  j                  j                  ddi       | j                  d   j                  j                  j                  ddi       y )"Nr   r  r  w-100 r	  Tr  ry   r  r  r  r  rU  r  r  r  r   r  rM  rk   rc  r   rL  r   r  F)r  r7  r  r  r  r  r  r  )r   r   r    r   r   rH   r   r   r  r   r   r   r   r   r  r   r   r   r^  rK   rE   r   r   rL   rC   rS   )r   r   r   r   r   r   r   s         r]   r   z RotatingShiftAssignForm.__init__:  s   $)&)$.)T:!%!2!2!4 o	J~~7;J'4KK./66<<CC%0#'	 KK'..44;;%4#'	 KK*+2288??-= KK
#**0077$b 05-"=0DKK%, KK+,3399@@4
 KK&--33::4Yo	d Gd-f-DKK(181JDKK&.==##GKKOOH,E-D%--4438D 5  4*B%347-D	 K..M* KK./66<<CC%4#'	 KK'..44;;%4#'	 KK*+2288??-= KK
#**0077$b 05-"=0DKK%, KK+,3399@@4
 KK&--33::4rn   c                     | j                   j                  r| j                  j                  d      S | j                  j                  d      }t	        |t
              r|S |r|d   S t        t        d            S )z1
        Validation to employee_id field
        r   r   r  r  r  s     r]   r  z)RotatingShiftAssignForm.clean_employee_id  sl     ==$$((77,,00?L,1##'?**1-E+FGGrn   c                    | j                   j                  rt        |          S t        |           t        j
                  j                  | j                  j                  d            j                         | j                   _
        | j                  j                  dd        | j                   j                  t        dt        d      i      t        |           t        |          }d| j                  v r| j                  d= |S r  r  r  s     r]   r  zRotatingShiftAssignForm.clean  s    ==7=?"$,$4$4$;$;yy}}]+ %< %

%' 	! 	t,==$$,!=!4L2M"NOOw},./rn   c           	      R   | j                   j                  r0| j                  d   }g d}|j                  |j	                               }| j                  d   }| j                   j
                  }|dk(  rt        ||      }|| j                   _        n|dk(  rJ| j                   j                  }| j                   j
                  }t        ||      }|| j                   _        nY|dk(  rT| j                   j
                  t        t        | j                  j                  d                  z   | j                   _        t        | =         S | j                  j!                  d	      }	t"        j$                  j                  | j                  d
         }
| j                  d   }g d}|j                  |j	                               }|	D ]  }t&        j$                  j)                  |      j+                         }t-               }|
|_        ||_        | j                  d   |_        | j                  d   |_        | j                  d   |_        | j                  j                  d      |_        | j                  d   |_        | j                  d   |_        | j                  d   |_        |j8                  j:                  |_        |
j>                  |_         d|jB                  d<   | j                  d   }| j                  d   }|dk(  rt        ||      }||_        n||dk(  r2| j                  d   }| j                  d   }t        ||      }||_        nE|dk(  r@|j
                  t        t        | j                  j                  d                  z   |_        |j                           y )Nr  r  r  ra   rc   r_   r  rg   r   rc  rz  rk   ry   rq   r  )"r   r^  r   r  r>  rk   rm   r  ry   r}   r   rU   r  r   r   r   r  r7   r   rE   r   r   r8   rc  r   r  r  r  r  r@  rg  rS  rh  r  )r   r   r  r  rj   r  rk   r  ry   r  rotating_shiftr   r   rotating_shift_assignr   s                 r]   r   zRotatingShiftAssignForm.save  sZ   ==(()?@HI #)9:J((4H11J8#.z:F	1:.Y&#}}99!]]55
1*lK	1:.W$151I1IITYY]]+=>?M 2. 7<>!99,,];L*22669901 7 N (()?@HI #)9:J+ %-#++22k2BHHJ(;(=%:H%74<%1151B1B:1N%.373D3D\3R%09=9J9J<9X%69=&:%6 6:5F5F~5V%2=A=N=N*>%: :>9J9J<9X%6//88 &3 4B3H3H%0LM%556HI,,Z8!..|<
x' 2:z JI=F):*#'#4#4^#DL!%!2!2<!@J 5j, OI=F):(-88#TYY]];M-N)OPQ *: &**,K%-rn   )Fr  r   s   @r]   ra  ra    s    
  "D( !u  7!J-XH)u))!1=O;PQ 

5??!L/J
 
2sjH "R- R-rn   ra  c                   v     e Zd ZdZ ej
                  ed ed            Z G d d      Z	 fdZ
 fdZ xZS )	RotatingShiftAssignUpdateFormrb  r  r  r  c                       e Zd ZdZeZdZg dZd eddi      iZ	 e
d       e
d	       e
d
       e
d       e
d       e
d      dZy)"RotatingShiftAssignUpdateForm.Metar   r4  rf  rk   r  r   rM  r  r  r  r  r  r  r  Nri  r   rn   r]   r   rt  ,  sj    	 $
 )66*:;
 L/ !"4 5$%&<$=n-*;
rn   r   c                    t        |   |i | t        | j                         | j                  j	                         D ]&  \  }}|j
                  sd| j                  |   _        ( | j                  d   j                  j                  j                  dddd       | j                  d   j                  j                  j                  dddd       | j                  d   j                  j                  j                  d	d
d       | j                  d   j                  j                  j                  ddd       t        j                  d	dd
d      | j                  d   _        | j                  d   j                  j                  j                  ddi       | j                  d   j                  j                  j                  ddi       y )Nr  r  rk  zedisplay:none; height:50px; border-radius:0; border:1px                     solid hsl(213deg,22%,84%);Tr  ry   r  r  r  rU  r  r  zD height:50px; border-radius:0; border:1px solid hsl(213deg,22%,84%);r   r  rM  rk   rc  r   rL  r   r
  r  s        r]   r   z&RotatingShiftAssignUpdateForm.__init__F  s   $)&)$!%!2!2!4 	<J~~7;J'4	< 	*+2288??!0#		
 	N#**0077!0#		
 	&'..44;;)9	
 	J&&,,33 _	
 ,1??)9,
L!( 	'(//55<<0	

 	M"))//660	
rn   c                 d   | j                   d   }g d}|j                  |j                               }| j                   d   }| j                  j                  }|dk(  rt        ||      }|| j                  _        n|dk(  rJ| j                  j                  }	| j                  j                  }t        ||	      }|| j                  _        nY|dk(  rT| j                  j                  t        t        | j                  j                  d                  z   | j                  _        t        
| 9         S r  r  r  s             r]   r   z"RotatingShiftAssignUpdateForm.save{  r  rn   r  r   s   @r]   rr  rr  %  s>     !u  7!J-XH
 
43
j rn   rr  c                   L     e Zd ZdZddiZ G d d      Zd Zd	def fdZ xZ	S )
ShiftRequestForm#
    ShiftRequest model's form
    descriptionr,  c                   ~    e Zd ZdZeZdZg dZ eddi       eddi      dZ	 e
d       e
d	       e
d
      dZy)ShiftRequestForm.Metar   r4  )reallocate_toapprovedcanceledreallocate_approvedreallocate_canceledprevious_shift_idr7  shift_changedr  r   rM  requested_daterequested_tillDescriptionRequested DateRequested Tillrz  r  r  Nr   r   r   r   r;   r   r   r8  r   rO  rS   r  r   rn   r]   r   r|    s`    	 	
 (vv.>?'vv.>?

 ]+ 01 01
rn   r   c                 &    d| i}t        d|      }|S r4  r   r5  s      r]   r  zShiftRequestForm.as_p        4.%&97C
rn   r   c                 *   | j                   j                  sn| j                   j                  }t        |d      rL|j                  j
                  | j                   _        | j                   j                  rd | j                   _        t        | )  |      S Nr  )r   r~  r   r   r  r@  r  is_permanent_shiftr  r   r   r   r   r   r   s      r]   r   zShiftRequestForm.save  sj    }}%%}}00Hx!562:2M2M2V2V/==3337DMM0w|F##rn   .
r   r   r   r   r   r   r  boolr   r   r   s   @r]   rx  rx    s4     2D
 
6$4 $ $rn   rx  c                   V     e Zd ZdZddiZ G d d      Z fdZd Zd
def fd	Z	 xZ
S )ShiftAllocationFormry  rz  r,  c                   |    e Zd ZdZeZdZdZ eddi       eddd      d	Z	 e
d
       e
d       e
d      dZy)ShiftAllocationForm.Metar   r4  )r  r~  r  r  r  r  r7  r  r  r   rM  true)r  r   r  r  r  r  r  Nr  r   rn   r]   r   r    s`    	 	
 (vv.>?'v6.RS
 ]+ 01 01
rn   r   c                     t        |   |i | | j                  d   j                  j                  j                  ddddd       y )Nr@  z#id_reallocate_to_parent_divchange	innerHTMLz/update-employee-allocation)	hx-target
hx-triggerzhx-swaphx-getr   r   r   r   r   r   r   s      r]   r   zShiftAllocationForm.__init__  sI    $)&)J&&,,33;&&7		
rn   c                 &    d| i}t        d|      }|S r4  r   r5  s      r]   r  zShiftAllocationForm.as_p  r  rn   r   c                 R   | j                   j                  s| j                   j                  }t        |d      r`|j                  j
                  | j                   _        | j                   j                  s%|j                  j                  | j                   _        t        | )  |      S r  )r   r~  r   r   r  r@  r  r  contract_end_dater   r   r  s      r]   r   zShiftAllocationForm.save	  s{    }}%%}}00Hx!562:2M2M2V2V/}}33 33EE MM0 w|F##rn   r  )r   r   r   r   r   r   r   r  r  r   r   r   s   @r]   r  r    s9     2D
 
8	
	$4 	$ 	$rn   r  c                   L     e Zd ZdZddiZ G d d      Zd Zd	def fdZ xZ	S )
WorkTypeRequestFormz&
    WorkTypeRequest model's form
    rz  r,  c                   z    e Zd ZdZeZdZdZ eddi       eddi      dZ	 e
d       e
d	       e
d
      dZy)WorkTypeRequestForm.Metar   r4  )r~  r  previous_work_type_idr7  work_type_changedr  r   rM  r  r  r  r  )r  r  rz  N)r   r   r   r   r@   r   r   r8  r   rO  rS   r  r   rn   r]   r   r  	  s`    	  
 (vv.>?'vv.>?

   01 01]+
rn   r   c                 &    d| i}t        d|      }|S r4  r   r5  s      r]   r  zWorkTypeRequestForm.as_p0	  r  rn   r   c                 *   | j                   j                  sn| j                   j                  }t        |d      rL|j                  j
                  | j                   _        | j                   j                  rd | j                   _        t        | )  |      S r  )r   r~  r   r   r  r  r  is_permanent_work_typer  r   r   r  s      r]   r   zWorkTypeRequestForm.save8	  so    }}%%}}00Hx!56//<< 3 ==7737DMM0w|F##rn   r  r  r   s   @r]   r  r  	  s4     2D
 
0	$4 	$ 	$rn   r  c            
       0    e Zd Z ej                  d ej
                  ddddd            Z ej                  d ej
                  dd	dd
d            Z ej                  d ej
                  ddddd            Z fdZ	d Z
d Z fdZ xZS )ChangePasswordFormFnew-passwordzEnter Old Password&oh-input oh-input--password w-100 mb-2id_old_password)autocompleter   r   r   rM  )stripr   zEnter New Passwordid_new_passwordRe-Enter Passwordid_confirm_passwordc                 *   || _         t        t        |   |i | d | j                  d   _        d | j                  d   _        d | j                  d   _        d | j                  d   _        d | j                  d   _        d | j                  d   _        y )Nold_passwordnew_passwordconfirm_password)r   r   r  r   r   r   	help_textr   r   r   r   r   s       r]   r   zChangePasswordForm.__init__g	  s    	 $0$A&A -1N#),0N#)04&'-04N#-04N#-48&'1rn   c                     | j                   j                  d      }| j                  j                  |      st	        j
                  d      |S )Nr  zIncorrect old password.r   r   r   check_passwordr   r   )r   r  s     r]   clean_old_passwordz%ChangePasswordForm.clean_old_passwords	  sB    ((,,^<yy''5''(ABBrn   c                     | j                   j                  d      }| j                  j                  |      rt	        j
                  d      |S )Nr  z5New password must be different from the old password.r  )r   r  s     r]   clean_new_passwordz%ChangePasswordForm.clean_new_passwordy	  sH    ((,,^<99##L1''G  rn   c                     t         |          }|j                  d      }|j                  d      }|r|r||k7  rt        ddi      |S )Nr  r  z.New password and confirm password do not match)r   r  r   r   )r   r   r  r  r   s       r]   r  zChangePasswordForm.clean	  s\    w}#''7'++,>?,AQ1Q!!QR  rn   )r   r   r   r   	CharFieldPasswordInputr  r  r  r   r  r  r  r   r   s   @r]   r  r  D	  s    "5??"u"" .3A'	

L #5??"u"" .3A'	

L 'u"u"" .2A+	


9	 	rn   r  c            	       r    e Zd Z ej                   ed      d ej                  ddd            Z ej                   ed      d ej                   ed	      dd
       ed            Z ej                   ed      d ej                   ed      dd
       ed            Z
 fdZd Z xZS )ChangeUsernameFormzOld UsernameFreadonlyz"oh-input oh-input--text w-100 mb-2)r  r   rM  )r   r  r   UsernamezEnter New Username)r   r   zEnter your username.r   r  r   r  PasswordzEnter Passwordr  zEnter your password.c                 :    || _         t        t        |   |i | y r   )r   r   r  r   r  s       r]   r   zChangeUsernameForm.__init__	  s    	 $0$A&Arn   c                 X   | j                   j                  d      }t        j                  j	                  |      j                         rt        j                  d      | j                   j                  d      }| j                  j                  |      st        j                  d      |S )Nusernamer  zUsername already exists.passwordzIncorrect password.)
r   r   r   r   r   rc  r   r   r   r  )r   r  r  s      r]   clean_passwordz!ChangeUsernameForm.clean_password	  s    $$((4<<188:''(BCC$$((4yy''1''(=>>rn   )r   r   r   r   r  rS   r   old_usernamer  r  r  r   r  r   r   s   @r]   r  r  	  s    "5??u&=
	L u
mu !56=
 *+
H u
m"u"" !12A
 *+
HBrn   r  c            
            e Zd ZdZ ej
                  dd ej                  d ed      dd      d	      Z ej
                  dd ej                  d ed
      dd      d	      Z	d fd	Z
d Z xZS )ResetPasswordFormz
    ResetPasswordForm
    r   Fr  zEnter Strong Passwordr  )r  r   r   rM  r  r  c                     | j                         r2t        t        dd       }|rt        j                  |t        d             t        |          S )Nr   zPassword changed successfully)is_validr   rH   r	   rh  rS   r   r   )r   r   r   r   s      r]   r   zResetPasswordForm.save	  s?    ==?ni>G  !,K*LMw|~rn   c                     | j                   j                  d      }| j                   j                  d      }||k(  r|S t        j                  t	        d            )z>
        validation method for confirm password field
        r  r  zPassword must be same.)r   r   r   r   rS   )r   r  r  s      r]   clean_confirm_passwordz(ResetPasswordForm.clean_confirm_password	  sX     $$((4,,001CD''####A&>$?@@rn   r   )r   r   r   r   r   r  r  rS   new_password1new_password2r   r  r   r   s   @r]   r  r  	  s     $EOO"u"" . !89A
 M $EOO"u"" . !45A
 MArn   r  )r   r7  r  r  r  r  
created_at
created_bymodified_byr  horilla_historyr  c            
       &   e Zd Zej                  j                         ZeD  cg c]8  }t        |d      r*|j                  t        vr|j                  |j                  f: c}}}} Z ej                  eej                  g d      Zyc c}}}} w )ShiftRequestColumnFormr   )r   r@  r  r  r  r~  r   r   r   N)r   r   r   r;   r   
get_fieldsr  r   r   excluded_fieldsr   field_choicesr   r   r   selected_fieldsr   r   r   r  s   0000r]   r  r   
  s    %%002L " 5.)ejj.O 
U''(M
 0e//++
O   =B
r  c            
       &   e Zd Zej                  j                         ZeD  cg c]8  }t        |d      r*|j                  t        vr|j                  |j                  f: c}}}} Z ej                  eej                  g d      Zyc c}}}} w )WorkTypeRequestColumnFormr   )r   r  r  r  r  r~  r  N)r   r   r   r@   r   r  r  r   r   r  r   r  r   r   r   r  r  s   0000r]   r  r  
  s    "((335L " 5.)ejj.O 
U''(M
 0e//++
Or  r  c            
       &   e Zd Zej                  j                         ZeD  cg c]8  }t        |d      r*|j                  t        vr|j                  |j                  f: c}}}} Z ej                  eej                  g d      Zyc c}}}} w )RotatingShiftAssignExportFormr   )r   rc  rk   r  rg  rh  r  r  N)r   r   r   r8   r   r  r  r   r   r  r   r  r   r   r   r  r  s   0000r]   r  r  *
  s    &,,779L " 5.)ejj.O 
U''(M
 0e//++
Or  r  c            
       &   e Zd Zej                  j                         ZeD  cg c]8  }t        |d      r*|j                  t        vr|j                  |j                  f: c}}}} Z ej                  eej                  g d      Zyc c}}}} w ) RotatingWorkTypeAssignExportFormr   )r   r  rk   r  r  r  r  r  N)r   r   r   r:   r   r  r  r   r   r  r   r  r   r   r   r  r  s   0000r]   r  r  @
  s    )//::<L " 5.)ejj.O 
U''(M
 0e//++
Or  r  c                   *    e Zd ZdZ G d d      Zd Zy)TagsFormz
    Tags form
    c                   <    e Zd ZdZeZdZd eddd      iZddgZ	y	)
TagsForm.Metar   r4  colorheight:50pxr  rV  rM  r   r7  N)
r   r   r   r   r=   r   r   r   rO  r8  r   rn   r]   r   r  [
  s1    	 IW},UVWk*rn   r   c                 &    d| i}t        d|      }|S r4  r   )r   r   r   r  r6  s        r]   r  zTagsForm.as_pe
  r  rn   Nr   r   r   r   r   r  r   rn   r]   r  r  V
  s    + +rn   r  c                   $    e Zd ZdZ G d d      Zy)EmployeeTagFormz
    Employee Tags form
    c                   :    e Zd ZdZeZdZdgZd eddd      iZ	y)	EmployeeTagForm.Metar   r4  r7  r  r  r  rM  N)
r   r   r   r   rF   r   r   r8  r   rO  r   rn   r]   r   r  s
  s.    	 -IW},UVWrn   r   Nr   r   r   r   r   r   rn   r]   r  r  n
  s    X Xrn   r  c                   ,    e Zd ZdZddiZ G d d      Zy)AuditTagFormz
    Audit Tags form
    r   r,  c                       e Zd ZdZeZdZy)AuditTagForm.Metar   r4  N)r   r   r   r   rJ   r   r   r   rn   r]   r   r  
  s    	 rn   r   NrP  r   rn   r]   r  r  ~
  s    
 	D rn   r  c                   $    e Zd ZdZ G d d      Zy)ShiftRequestCommentFormz$
    Shift request comment form
    c                       e Zd ZdZeZdZy)ShiftRequestCommentForm.Metar   commentN)r   r   r   r   r<   r   r   r   rn   r]   r   r  
  s    	 $rn   r   Nr  r   rn   r]   r  r  
       rn   r  c                   $    e Zd ZdZ G d d      Zy)WorkTypeRequestCommentFormz'
    WorkType request comment form
    c                       e Zd ZdZeZdZy)WorkTypeRequestCommentForm.Metar   r  N)r   r   r   r   rA   r   r   r   rn   r]   r   r
  
  s    	 'rn   r   Nr  r   rn   r]   r  r  
  r  rn   r  c                   *    e Zd ZdZ G d d      Zd Zy)DynamicMailConfFormz#
    DynamicEmailConfiguration
    c                       e Zd ZeZdZdgZy)DynamicMailConfForm.Metar4  r7  N)r   r   r   r+   r   r   r8  r   rn   r]   r   r  
  s    )-rn   r   c                 &    d| i}t        d|      }|S r4  r   r5  s      r]   r  zDynamicMailConfForm.as_p
  r  rn   Nr  r   rn   r]   r  r  
  s       rn   r  c                   8    e Zd ZdZ ej
                  dd      Zy)DynamicMailTestFormz
    DynamicEmailTest
    zTo emailT)r   r   N)r   r   r   r   r   
EmailFieldto_emailr   rn   r]   r  r  
  s      uj4@Hrn   r  c                   <    e Zd ZdZddddZ G d d      Zd Zd Zy)	MailTemplateFormz
    MailTemplateForm
    r,  )r   bodyr   c                   d    e Zd ZeZdZ ej                  ddd       ej                         dZ	y)MailTemplateForm.Metar4  r   zdisplay:none;)data-summernoterV  rM  )r  r7  N)
r   r   r   r2   r   r   r   r   r   rO  r   rn   r]   r   r  
  s9    #"ENN*,G +**,	
rn   r   c                 |    i ddddddddd	d
dddddddddddddddddddddddd
dd d!d"}|S )#NReceiver|Full nameinstance.get_full_nameSender|Full nameself.get_full_nameReceiver|Recruitmentinstance.recruitment_idSender|Recruitmentself.recruitment_idReceiver|Companyinstance.get_companySender|Companyself.get_companyReceiver|Job positioninstance.get_job_positionSender|Job positionself.get_job_positionReceiver|Emailinstance.get_mailSender|Emailself.get_mailReceiver|Employee Typeinstance.get_employee_typeSender|Employee Typeself.get_employee_typeReceiver|Work Typeinstance.get_work_typeSender|Work Typeself.get_work_typezCandidate|Full namezCandidate|RecruitmentzCandidate|Companyzinstance.get_emailzinstance.get_interview|safe)zCandidate|Job positionzCandidate|EmailzCandidate|Interview Tabler   r   	mail_datas     r]   get_template_languagez&MailTemplateForm.get_template_language
  s    
 ":
 4
 #$=
 !"7	

  6
 0
 $%@
 "#:
 1
 O
 %&B
 #$<
 !":
  4
 "#;
  $%>!
"  !7#
$ 'B3)F)
	, rn   c                 (    ddddddddd	d
ddddd}|S )Nr  r  r   r"  r$  r&  r(  r*  r,  r.  r0  r2  r4  r6  )r  r  r  r!  r#  r%  r'  r)  r+  r-  r/  r1  r3  r5  r   r7  s     r]   get_employee_template_languagez/MailTemplateForm.get_employee_template_language
  s;    ": 4$="7 60%@#:1+&B$<": 4
	  rn   N)r   r   r   r   r   r   r9  r;  r   rn   r]   r  r  
  s)     26D
 
2rn   r  c                       e Zd ZddiZd ed      fd ed      fd ed      fd	 ed
      fd ed      fd ed      fd ed      fd ed      fgZ ej                  g  ej                  ddi       ed      d      Z	 ej                  e ej                  ddddd            Z
 G d d      Z fd Z xZS )!MultipleApproveConditionFormmulti_approval_managerr,  equalz
Equal (==)notequalzNot Equal (!=)rW   RangeltzLess Than (<)gtzGreater Than (>)lezLess Than or Equal To (<=)gezGreater Than or Equal To (>=)	icontainsContainsr   zoh-select oh-select-2 mb-2rM  zApproval ManagerT)r   r   r   r   r  z#conditionValueDivzcondition-value-fields)r   r  r  r  )r   r   c                       e Zd ZeZdZdgZy)!MultipleApproveConditionForm.Metar4  r7  N)r   r   r   r5   r   r   r8  r   rn   r]   r   rI  +  s    )
rn   r   c                     t        |   |i | dt        d      fgt        j                  j                         D cg c]  }|j                  t        |      f c}z   }|| j                  d   _	        y c c}w )Nreporting_manager_idzReporting Managerr>  )
r   r   rS   rE   r   r   r^  rV   r   r   )r   r   r   r   r   r   s        r]   r   z%MultipleApproveConditionForm.__init__2  sy    $)&)*A.A,BCD9A9I9I9M9M9OH
-5X[[#h-(H
 
 9@,-5H
s   A6)r   r   r   r   rS   CONDITION_CHOICEr   r  r   r>  condition_operatorr   r   r   r   s   @r]   r=  r=    s	    	!"D
 
!L/"	Q'()	!G*	q!"	q#$%	q-./	q012	a
m$	 /U..u||7,H"IJ"#	 +** u||5&12	


 
@ @rn   r=  c                   $    e Zd ZdZ G d d      Zy)DynamicPaginationFormz-
    Form for setting default pagination
    c                       e Zd ZeZdZdZy)DynamicPaginationForm.Metar4  )user_idN)r   r   r   r,   r   r   r8  r   rn   r]   r   rQ  ?  s    !rn   r   Nr  r   rn   r]   rO  rO  :  s     rn   rO  c                       e Zd ZdZy)MultipleFileInputTN)r   r   r   allow_multiple_selectedr   rn   r]   rT  rT  E  s    "rn   rT  c                   *     e Zd Z fdZd fd	Z xZS )rD   c                 X    |j                  dt                      t        |   |i | y )Nr   )
setdefaultrT  r   r   r   s      r]   r   zMultipleFileField.__init__J  s)    ($5$78$)&)rn   c                     t         |   }t        |t        t        f      r|D cg c]  } |||       }}n
 |||      g}|r|d   S d S c c}w )Nr   )r   r  r   r  tuple)r   r  r   single_file_cleandresultr   s         r]   r  zMultipleFileField.cleanN  sb    !GMdT5M*=AB'73BFB "$0F #vay,, Cs   Ar   )r   r   r   r   r  r   r   s   @r]   rD   rD   I  s    *- -rn   rD   c            	            e Zd ZdZ eej                  j                          ede	dd      d      Z
dddddddd	Z G d
 d      Zd Z fdZddedef fdZd Z fdZ xZS )AnnouncementFormz
    Announcement Form
    r  r  r  r  r  r  r,  )r   rz  attachmentsexpire_date	employeesrI  rX  c                   `    e Zd ZdZeZdZdgZ ej                  ddi       e
ddi      d	Zy
)AnnouncementForm.Metar   r4  r7  r  r   rM  r  r   )rz  ra  N)r   r   r   r   r!   r   r   r8  r   r   r   rO  r   rn   r]   r   rd  s  sB    	 -)5>>1BB0GH$FF+;<
rn   r   c                     | j                   j                  dd      j                         }t        |      j                         }|st	        j
                  d      |S )Nrz  r   zDescription is required.)r   r   r  r   r   r   )r   rz  text_contents      r]   clean_descriptionz"AnnouncementForm.clean_description  sQ    ''++M2>DDF!+.446''(BCCrn   c                     t        |   |i | t        t        d            | j                  d<   d| j                  d   _        d| j                  d   _        | j                  d   j                  j                  j                  ddi       y )	NAttachmentsr   r`  Frz  disable_commentszhx-on:clickztogglePublicComments())	r   r   rD   rS   r   r   r   r   r   r   s      r]   r   zAnnouncementForm.__init__  s|    $)&)%6Q}=M%NM".3M"+.3M"+&'..44;;45	
rn   r   re  c                    g }g }d }| j                   j                  d      rt| j                   j                  d      }|d   | j                  _        g }|D ]>  }t	               }||_        |j                          |j                  |j                         @ t        |   |      }|r |j                  j                  |  ||fS )Nr`  r   )filesr  r   attachementr$   r?  r   ri  r^  r   attachementsr  )r   r   rm  multiple_attachment_idsrn  file_instancer   r   s          r]   r   zAnnouncementForm.save  s    "$::m,::--m<L(4QDMM%&(#+ A *%0"""$'..}/?/?@	A
 7<'%H!!%%'>?000rn   c                 "    d| i}t        d|      S )Nr  zannouncement/as_p.htmlr   r  s       r]   r  zAnnouncementForm.as_p  s    4. 8'BBrn   c                    t         |          }t        | j                  d   t              rc| j
                  j                  dd        | j                  d   j                  j                  | j                  j                  d            }||d<   |j                  d      }| j                  j                  d      }| j                  j                  d      }|s"|s |st        j                  t        d            |S )Nrb  r"  rI  rX  zHYou must select at least one of: Employees, Department, or Job Position.)r   r  r   r   rK   r  r  r   r   r  r  r   r   r   r   rS   )r   r   employee_dataemployees_selecteddepartments_selectedjob_positions_selectedr   s         r]   r  zAnnouncementForm.clean  s    w} dkk+.0GHKKOOK. KK4==DDyy((5 E M )6L% *--k:#0044\B!%!2!2!6!6~!F #(*''^  rn   r  )r   r   r   r   rK   rE   r   r   rL   rC   rb  r   r   rg  r   r  r   r   r  r  r   r   s   @r]   r_  r_  Y  s     (!!%%''6'(+!8	
 	I D
 

14 1# 1&C rn   r_  c                   $    e Zd ZdZ G d d      Zy)AnnouncementCommentFormz#
    Announcement comment form
    c                       e Zd ZdZeZdgZy)AnnouncementCommentForm.Metar   r  N)r   r   r   r   r"   r   r   r   rn   r]   r   rz    s    	 $rn   r   Nr  r   rn   r]   rx  rx    s     rn   rx  c                   $    e Zd ZdZ G d d      Zy)AnnouncementExpireFormz"
    Announcement Expire form
    c                       e Zd ZdZeZdZy)AnnouncementExpireForm.Metar   rg   N)r   r   r   r   r#   r   r   r   rn   r]   r   r~    s    	 #rn   r   Nr  r   rn   r]   r|  r|    s     rn   r|  c                   $    e Zd ZdZ G d d      Zy)
DriverFormz
    DriverForm
    c                       e Zd ZeZdZy)DriverForm.Metar4  N)r   r   r   r*   r   r   r   rn   r]   r   r    s    rn   r   Nr  r   rn   r]   r  r    s     rn   r  c            	       X    e Zd Z ej                         Z	 ddZd Zddddeddddf	dZ	y)	PassWordResetFormNc                 ,   t        j                  ||      }dj                  |j                               }t        j                  ||      }t	        ||||g      }	|(t        j                  ||      }
|	j                  |
d       |	j                          y)zO
        Send a django.core.mail.EmailMultiAlternatives to `to_email`.
        r   Nz	text/html)r   r   ru  
splitlinesr   attach_alternativesend)r   subject_template_nameemail_template_namer  
from_emailr  html_email_template_namesubjectr  email_message
html_emails              r]   	send_mailzPassWordResetForm.send_mail  s     ))*?I''',,./&&':GD.wj8*U#/001I7SJ,,ZErn   c                     t         j                         t        j                  j                  di dz  ddi}fd|D        S )a  
        Given an email, return matching user(s) who should receive a reset.

        This allows subclasses to more easily customize the default policies
        that prevent inactive users and users with unusable passwords from
        resetting their password.
        z
%s__iexactr7  Tc              3   n   K   | ],  }|j                         rt        t        |            r| . y wr   )has_usable_passwordr   r   )r   uemailemail_field_names     r]   	<genexpr>z.PassWordResetForm.get_users.<locals>.<genexpr>  s7      
$$&#E716F+GH 
s   25r   )	UserModelget_email_field_name_default_managerr   )r   r  active_usersr  s    ` @r]   	get_userszPassWordResetForm.get_users  sV     %99; 1188 
//T

!
 	
rn   z'registration/password_reset_subject.txtz&registration/password_reset_email.htmlFc
                    | j                   d   }
t        j                  j                  |
      }|j                  }|j
                  }d}	 |j                  j
                  }|r|}|s$t        |      }|j                  }|j                  }n|x}}|rY|j                  |      }|||t        t        |j                              |||rdndd|	xs i }| j                  ||||||       yy# t        $ r
}Y d}~d}~ww xY w)zf
        Generate a one-use only link for resetting password and send it to the
        user.
        r  r  Nhttpshttp)r  domain	site_nameuidr   tokenprotocol)r  )r   r   r   r   r   r  r  r  r   r   r  
make_tokenr   r   r^  r  )r   domain_overrider  r  	use_httpstoken_generatorr  r   r  extra_email_contextr  r   r   r  	work_mailr  current_siter  r  r  r  s                        r]   r   zPassWordResetForm.save!  s      $$W-||2$$		 3399I E+G4L$))I!((F!00I#..t4E &,[-AB'0Gf	 ',"	G NN%#)A     		s   C+ +	C>9C>r   )
r   r   r   r   r  r  r  r  r   r   r   rn   r]   r  r    sA    EOOE "&0
0 GD/!% 5rn   r  c                     	 t        j                  |        y # t        $ r6 	 t        j                  | d       Y y # t        $ r t	        |  d      w xY ww xY w)NF)strictz, is not a valid IP address or CIDR notation.)	ipaddress
ip_addressrX   
ip_networkr   )rY   s    r]   validate_ip_or_cidrr  Y  s`    U# 	  u5 	!'EF 	s    	A;AAc                        e Zd Z ej                   ej
                  ddd      dd      Z G d d	      Zd
 Zd fd	Z	 xZ
S )AttendanceAllowedIPFormrP   zform-control w-100)r   r   rM  z(Allowed IP Addresses or Network PrefixeszEEnter multiple IP addresses or network prefixes, separated by commas.)r   r   r  c                       e Zd ZeZdgZy)AttendanceAllowedIPForm.Metaip_addressesNr   r   r   r%   r   r   r   rn   r]   r   r  l  s    # !rn   r   c                    | j                   j                  dd      j                         j                  d      }g }|D ]G  }|j                         j                  d      }|s%|D ]  }t	        |       |j                  |         I |S )Nr  r   
rt  )r   r   r  rT   r  ri  )r   r  cleaned_ipsipip_addrs        r]   clean_ip_addressesz*AttendanceAllowedIPForm.clean_ip_addressesp  s    ((,,^R@FFHNNtT 	0B!!$'B! 0G'0&&w/0	0 rn   c                 ^   t         |   d      }|j                  rgt        |j                  j                  dg             }t        | j                  d         }t        |j                  |            }||j                  d<   nd| j                  d   i|_        |r|j                          |S )NFr   allowed_ipsr  )	r   r   r^  r   r  r   r   r  union)r   r   r   existing_ipsnew_ips
merged_ipsr   s         r]   r   zAttendanceAllowedIPForm.save{  s    7<u<-;;x77;;M2NOL$++N;<Gl009:J6@H$$]3 t00@(H$ MMOrn   r   )r   r   r   r   r  r   r  r   r  r   r   r   s   @r]   r  r  e  sF    "5??u~~Q9M$NO8YL" "	 rn   r  c                   `     e Zd Z ej                  dd      Z G d d      Zd Z fdZ xZ	S )AttendanceAllowedIPUpdateForm   z
IP Address)
max_lengthr   c                       e Zd ZeZdgZy)"AttendanceAllowedIPUpdateForm.Metar  Nr  r   rn   r]   r   r    s    #rn   r   c                 N    	 t        |       |S # t        $ r t        d      w xY w)Nz#Enter a valid IPv4 or IPv6 address.)r   r   )r   rY   s     r]   validate_ip_addressz1AttendanceAllowedIPUpdateForm.validate_ip_address  s6    	I"5)   	I!"GHH	Is    $c                     t         |          }| j                  j                         D ]  \  }}| j	                  |      ||<    |S r   )r   r  r  r   r  )r   r   r   rY   r   s       r]   r  z#AttendanceAllowedIPUpdateForm.clean  sL    w}!%!2 	GJ'+'?'?'FL$	G rn   )
r   r   r   r   r  r  r   r  r  r   r   s   @r]   r  r    s.     BlCJ    rn   r  c                   2     e Zd Z G d d      Z fdZ xZS )TrackLateComeEarlyOutFormc                       e Zd ZeZdgZy)TrackLateComeEarlyOutForm.Meta	is_enableN)r   r   r   r>   r   r   r   rn   r]   r   r    s    %rn   r   c                     t        |   |i | | j                  d   j                  j                  j                  dddd       y )Nr  z7/attendance/enable-disable-tracking-late-come-early-outthisr  )zhx-postr  r  r  r   s      r]   r   z"TrackLateComeEarlyOutForm.__init__  sF    $)&)K ''--44T#&	
rn   )r   r   r   r   r   r   r   s   @r]   r  r    s     
 
rn   r  c                        e Zd ZdZddiZ ej                   ej                  ddi            Z ej                   ej                  ddi            Z	d Z
 G d	 d
      Z fdZ xZS )HolidayFormaW  
    Form for creating or updating a holiday.

    This form allows users to create or update holiday data by specifying details such as
    the start date and end date.

    Attributes:
        - start_date: A DateField representing the start date of the holiday.
        - end_date: A DateField representing the end date of the holiday.
    r   r,  r  r   rM  )r   c                     | j                   j                  d      }| j                   j                  d      }|r|r||k  rt        t        d            |S )Nrk   end_datez3End date should not be earlier than the start date.)r   r   r   rS   )r   rk   r  s      r]   clean_end_datezHolidayForm.clean_end_date  sW    &&**<8
$$((4(x*'<!GH  rn   c                   2    e Zd ZdZeZdZdgZd ed      iZ	y)HolidayForm.Metar   r4  r7  r   zHoliday NameN)
r   r   r   r   r1   r   r   r8  rS   r  r   rn   r]   r   r    s+    	 -An%
rn   r   c                    t        t        | 
  |i | d| j                  d   j                  j
                  d<   | j                  j                         j                  j                  d      j                   | j                  d   _        | j                  j                         j                  j                  d      j                   | j                  d   _        y )Nr   r  rk   r  )r   r  r   r   r   r   r   r   r   r|  r   r   r   s      r]   r   zHolidayForm.__init__  s    k4)4:6:;AF""((8yy &&00>KKL 	L!' yy &&00<IIJ 	J%rn   )r   r   r   r   r   r   r  r   rk   r  r  r   r   r   r   s   @r]   r  r    st    	 B<D uff%56J uuff%56H	

 


 
rn   r  c                   `     e Zd ZdZ ej
                  g ej                  g       Z fdZ xZ	S )HolidaysColumnExportFormz?
    Form for selecting columns to export in holiday data.
    r  c                 b   t        |   |i | t               }|j                  }|j                  D cg c]E  }|j
                  t        vr1|j
                  |j                  |j
                        j                  fG }}|| j                  d   _	        g d| j                  d   _
        y c c}w )Nr  )r   rk   r  	recurring)r   r   r1   r   r   r   r  r|  r   r   r   )r   r   r   model_instancemetar   r  r   s          r]   r   z!HolidaysColumnExportForm.__init__  s    $)&) "## 
zz0 ZZ

3@@A
 
 2?%&.2
%&.
s   A
B,)
r   r   r   r   r   r   r   r  r   r   r   s   @r]   r  r    s5     0e//++O
 
rn   r  c                   @     e Zd ZdZdddZ G d d      Z fdZ xZS )CompanyLeaveForma  
    Form for managing company leave data.

    This form allows users to manage company leave data by including all fields from
    the CompanyLeaves model except for is_active.

    Attributes:
        - Meta: Inner class defining metadata options.
            - model: The model associated with the form (CompanyLeaves).
            - fields: A special value indicating all fields should be included in the form.
            - exclude: A list of fields to exclude from the form (is_active).
    r,  )based_on_weekbased_on_week_dayc                       e Zd ZdZeZdZdgZy)CompanyLeaveForm.Metar   r4  r7  N)r   r   r   r   r(   r   r   r8  r   rn   r]   r   r    s    	 -rn   r   c                 `    t        |   |i | d| j                  d   j                  _        y)zJ
        Custom initialization to configure the 'based_on' field.
        z"horilla_widgets/select_option.htmlr  N)r   r   r   r   option_template_namer   s      r]   r   zCompanyLeaveForm.__init__%  s1     	$)&)0 	O$++@rn   )r   r   r   r   r   r   r   r   r   s   @r]   r  r    s(      b9D   
 
rn   r  c                   6     e Zd ZdZ G d d      Z fdZ xZS )PenaltyAccountFormz
    PenaltyAccountForm
    c                       e Zd ZeZdZdgZy)PenaltyAccountForm.Metar4  r7  N)r   r   r   r6   r   r   r8  r   rn   r]   r   r  4  s    -rn   r   c                 J   |j                  dd       }t        |   |i | t        j                  d      rl|rit        dd      }|j                  j                         }|j                  j                  |j                  dd            }|| j                  d   _        y y y )	Nr   leave	leavetype)	app_labelr   leave_type_idTr$  r"  )r  r   r   r   r2  rI   available_leaver   r   r   r&  r   r   )r   r   r   r   	LeaveTypeavailable_leavesassigned_leave_typesr   s          r]   r   zPenaltyAccountForm.__init__9  s    ::j$/$)&)W%(/'UI'77;;=#,#4#4#;#;'33O$3O $< $  5IDKK(1 +3%rn   )r   r   r   r   r   r   r   r   s   @r]   r  r  /  s       
	I 	Irn   r  )r   ru   r  r;  rC  r   r   r   typingr   djangor   django.appsr   django.contribr	   django.contrib.authr
   django.contrib.auth.formsr   r   django.contrib.auth.modelsr   r   r   django.contrib.auth.tokensr   django.contrib.sites.shortcutsr   django.core.exceptionsr   django.core.mailr   django.core.validatorsr   django.formsr   r   r   django.templater   django.template.loaderr   django.utils.encodingr   django.utils.htmlr   django.utils.httpr   django.utils.translationr   rS   r   base.methodsr    base.modelsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   base.widgetsrB   employee.filtersrC   employee.formsrD   employee.modelsrE   rF   horillarG   horilla.horilla_middlewaresrH   horilla.methodsrI   horilla_audit.modelsrJ   2horilla_widgets.widgets.horilla_multi_select_fieldrK   &horilla_widgets.widgets.select_widgetsrL   r^   r   rm   r}   r   r   r   r   r  r  r+  rH  rR  ro  r~  r  r  r  r  r  r  r!  r=  rR  ra  rr  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r=  rO  ClearableFileInputrT  	FileFieldr_  rx  r|  r  r  r  r  r  r  r  r  r  r  r  r   rn   r]   <module>r     s4     	  . .    # . J > > > ; 2 3 9 : : " 3 - ( 3 1 1 (" " " " " " " " "F 1 + , 1 ' 6 3 ) V K
Y" ajq|)>&5p| |~*L5:: *LZ+I +\(d (V 02t 2j') 'T
Y 
(Y.i Y.xE-9 E-PQ.) Q.h 9  "p9 pfr1 r1j	ru rj y  "	 <Qi Qhg 	 g Tf	 fR`-eoo `-F	qI qh1$y 1$l?$) ?$D0$) 0$fG GT/ /d-A -A` UZZ *

 *EJJ ,uzz ,y 0Xi X 9 $i  ) ,A%** A;y ;|/@9 /@dI #00 #- - ky k\i Y   	f

 fR	%eoo %PI .
	 
 4
) 4
n
uzz 
B 
y  
FI Irn   