
    vg9#                    R   d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ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+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZL ddlMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[ ddl\m]Z]m^Z^m_Z_ ddl`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZq  ej                  es      Zte6d        Zud Zve6 e7d       d!               Zwe6e5 e7d"       d#                      Zxe6 e7d$      d%               Zye6e5 e:d&      d'                      Zze6e5 e:d(      d)                      Z{e6e5 e:d(      dd*                     Z|e6e5d+               Z}e6 e7d,       d-               Z~e6 e:d.      d/               Ze6 e:d0      d1               Ze6 e7d,      d2               Zd3 Ze6e5d4               Ze6d5        Zd6 Ze6d7        Ze6e5d8               Ze6e5d9               Ze6e5d:               Ze6e5d;               Ze6e5d<               Ze6e5d=               Ze6e5d>               Ze6d?        Ze6e5 e_d@       dA                      Ze6e5 e7d       dB                      Ze6e5dC               Ze6 e7d,       dD               Ze6 e7d,       dE               Ze6e5dF               Ze6 e7dG       dH               Ze6 e7dG       dI               Ze6e5 e7dG       dJ                      Ze6e5 e7dK       dL                      ZdM Ze6 e7dN       dO               Ze6e5 e7dP       dQ                      Ze6dR        Ze6e5dS               Ze6dT        Ze6dU        Ze6dV        Ze6dW        Ze6dX        Ze6dY        Ze6 e7dZ       d[               Ze6e5d\               Ze6d]        Ze6 e7dZ       d^               Ze6d_        Ze6d`        Ze6 e7da       db               Ze6dc        Ze6 e7dd       de               Ze6 e7df       dg               Ze6 e7dh       di               Ze6 e7dj       dk               Ze6e5 e7dj       dl                      Ze6 e7dj       dm               Ze6e5 e7dn       do                      Ze6 e7dp       dq               Ze6 e7dr       ds               Ze6 e7dr       e5dt                      Ze6 e7du       e5dv                      Ze6 e7dw       dx               Ze6 e7dy       dz               Ze6d{        Ze6d|        Ze6d}        Ze6d~        Ze6d        ZddZe6d        Ze6d        Ze6 e7d,       d               Ze6d        Ze6 e7dZ       d               Ze6d        Ze6d        Ze6e5d               Ze6e5d               Ze6d        Ze6 e:d      d               Ze6e5d               Ze6e5d               Ze6e5 e7dG       d                      Ze6 e7d       d               Ze6d        Ze6d        Ze6d        Ze6d        Ze6e5d               ZddlmZ e6 e:d      d               Ze6 e:d      d               Ze6d        Ze6e5d               Ze6 e8d      d               Ze6e5 e8dd      d                      Ze6 e8dd      d               Ze6 e8dd      d               Ze6e5 e8dd      d                      Ze6d        Ze6e5 e9de2      d                      Ze6d        Ze6 e:d      d               Ze6 e:d      d               Ze6d        Ze6 e:d      d               Zy)zr
views.py

This module contains the view functions for handling HTTP requests and rendering
responses in pms app.
    N)tee)parse_qs	urlencodeurlparse)relativedelta)forms)messages)User)	Paginator)ProtectedErrorQ)IntegrityError)modelformset_factory)HttpResponseHttpResponseRedirectJsonResponse)get_object_or_404redirectrender)render_to_string)reverse)gettext_lazy)closest_numberseval_validateget_key_instancesget_paginationpaginator_qrysortby)EmployeeEmployeeWorkInformation)hx_request_requiredlogin_requiredmanager_can_entermeeting_manager_can_enterowner_can_enterpermission_required)group_by_queryset)generate_choices)serialize_form)notify)	ActualKeyResultFilterActualObjectiveFilterAnonymousFeedbackFilterEmployeeObjectiveFilterFeedbackFilterKeyResultFilterMeetingsFilterObjectiveFilterObjectiveReGroup)AddAssigneesFormAnonymousFeedbackFormEmployeeKeyResultFormEmployeeObjectiveCreateFormEmployeeObjectiveFormFeedbackFormKeyResultFormKRFormMeetingsFormObjectiveCommentFormObjectiveForm
PeriodFormQuestionFormQuestionTemplateForm)'check_permission_feedback_detailed_viewget_anonymous_feedbackspms_owner_and_manager_can_enter)AnonymousFeedbackAnswerBonusPointSettingCommentEmployeeBonusPointEmployeeKeyResultEmployeeObjectiveFeedback	KeyResultKeyResultFeedbackMeetingsMeetingsAnswer	ObjectivePeriodQuestionQuestionOptionsQuestionTemplatec                     | j                   j                  }d}t        j                  j	                  |d      }|j                         }t        | |      }t        | ||      S )z
    This view is used to show all the objectives  and returns some objects.
    Returns:
        Objects based on userlevel.
    zokr/okr_view.htmlFemployee_idarchive)useremployee_getrK   objectsfilterdistinctobjective_filter_paginationr   )requestemployeetemplateobjective_owncontexts        /var/www/horilla/pms/views.pyobjective_list_viewrf   i   sc     ||((H"H%--44e 5 M "**,M)'=AG'8W--    c                 (   |j                         }|j                  d   }|j                  d   }|j                  d   }t        j                  | t	        d             |r|D ]  }t        |||      }|j                          |r:|D ]5  }t        |||j                  |j                        }	|	j                          7 t        j                  | j                  j                  |j                  ddd	d
dt        dd|j                  i              yy)z2
    This view is used to save objective form
    	assignees
start_datekey_result_idzObjective created)objective_idrX   rj   employee_objective_idrk   progress_typetarget_valueYou got an OKR!.5   لقد حققت هدفًا ونتيجة رئيسية!'Du hast ein Ziel-Key-Ergebnis erreicht!-   ¡Has logrado un Resultado Clave de Objetivo!0   Vous avez atteint un Résultat Clé d'Objectif !objective-detailed-viewobj_idkwargs	recipientverbverb_arverb_deverb_esverb_frr   N)savecleaned_datar	   success_rK   rJ   ro   rp   r*   sendrZ   r[   employee_user_idr   id)
r`   objective_form	objectiveri   rj   default_krsempemp_objectivekeyemp_krs
             re   obj_form_saver   z   s    ##%I++K8I,,\:J --o>KWa 345 	C-&CJM  & "C..;&)&)&7&7%(%5%5	F KKM" KK))..'OAGJ -x6N	 rg   zpms.add_employeeobjectivepermc                    | j                   j                  }t        |      }| j                  j	                  d      t        | j                        }| j
                  dk(  r<t        | j                        }|j                         rt        | |       t        d      S |t               t               d}t        | d|      S )a  
    This view is for objective creation , and returns a objective form.
    Returns:
        GET:
            objective form, period, department, job position, employee, department
        POST:
            Objective created, and returns to key result creation function
    )ra   rk   POST)<script>window.location.reload()</script>)r   p_formk_formokr/objective_creation.htmlrd   )rZ   r[   r>   GETgetmethodr   is_validr   r   r?   r;   r   )r`   ra   r   rd   s       re   objective_creationr      s     ||((H"H5N{{'3&w{{3~~&w||4""$'>2 KLL(,(G
 '8'JJrg   pms.change_employeeobjectivec                    t         j                  j                  |      }t        |      }| j                  j                  d      t        | j                        }| j
                  dk(  rt        | j                  |      }|j                         r|j                         }|j                  d   }|j                  d   }|j                  d   }|D cg c]  }| }	}g }
|j                  j                         rG|j                  j                         }|D cg c]  }|j                   }}|D cg c]	  }||	vs| }
}t        |
      dkD  r6|
D ]1  }t        j                  j!                  ||      j#                          3 |	D ]Y  }t        j                  j!                  ||      j                         r7t        j                  j!                  ||      j%                         }||_        nt        |||	      }|j                          |r~|D ]y  }t(        j                  j!                  ||
      j                         r3t(        j                  j+                  |||j,                  |j.                        }|j                          { t1        j2                  | j4                  j6                  |j8                  dddddt;        dd|j<                  i             \ t?        j@                  | tC        d      d|iz         tE        d      S |tG               dd}tI        | d|      S c c}w c c}w c c}w )z
    This view takes one arguments, id , and returns a HttpResponse object.,using htmx
    Args:
        id (int): Primary key of EmployeeObjective.
    Returns:
        A HttpResponse object with the content Form errors.
    r   instancerk   r   ri   rj   r   rX   rl   rX   rl   rj   rn   rk   rm   rq   rr   rs   rt   ru   rv   rw   rx   rz   Objective %(objective)s Updatedr   r   T)r   r   updater   )%rQ   r\   r   r>   r   r   r   r   r   r   employee_objectiveexistsallrX   lenrK   r]   deletefirstrj   rJ   createro   rp   r*   r   rZ   r[   r   r   r   r	   r   r   r   r;   r   )r`   rw   r   r   r   ri   rj   r   assigneenew_empdelete_listemp_objectivesr   existing_empra   emp_objr   r   rd   s                      re   objective_updater      s      $$$/H"H5N{{'3&w{{3~~&w||hG""$&++-I&33K@I'44\BJ(55oFK09:Hx:G:K++224!*!=!=!A!A!C;IJCJJ-9!)XW=TH  ;!#& C%--44$'i 5 fh  &$,,33 #) 4 &( 077>>$'i ? eg  *4G&/$'iJG * 
*088??29  @   &( # &7%>%>%E%E6=.1.1.?.?-0-=-=	 &F &F #KKM
* LL--!22+SEKN$18Y\\:R7&N 34X7NN   KLL!/68tTG'8'BBy ;
  Ks   	L1L64	L;>L;zpms.view_keyresultc                 P   t         j                  j                         }t        | j                        }t        || j                  j                  d            }t        j                  |j                  D cg c]  }|j                   c}      }|||d}t        | d|      S c c}w )zR
    This method is used render template to view all the key result instances
    page)krsfkrs_idszokr/key_result/view_kr.html)rM   r\   r   r+   r   r   r   jsondumpsobject_listr   r   )r`   r   
krs_filterr   r   rd   s         re   view_key_resultr     s     




!C&w{{3J
W[[__V4
5CjjcooF((++FGGG
 '8'BB Gs   6B#zpms.view_key_resultc           	         | j                   j                         }t        | j                         j                  }d}| j                   j	                  d      dk(  rd}t        | |d      }t        || j                   j	                  d            }t        j                  |j                  D cg c]  }|j                   c}      }t        |      }t        t        |       t        | |||||d      S c c}w )z[
    Filter and retrieve a list of key results based on the provided query parameters.
    zokr/key_result/kr_card.htmlviewlistzokr/key_result/kr_list.htmlr   r   )r   pdfilter_dictr   )r   r   r+   qsr   r   r   r   r   r   r   r   r   rM   r   )r`   query_stringr   rb   r   allowance_ids	data_dicts          re   filter_key_resultr   '  s     ;;((*L

,
/
/C,H{{v&(0
#x
(C
W[[__V4
5CJJCOOLLMM&Ii+$$		
	 	  Ms   +C2zpms.add_key_resultc                 j   t               }| j                  j                  d      }| j                  j                  d      }| j                  dk(  rSt        | j                        }|j                         r|j                         }t        j                  | t        d      d|iz         | j                  j                         }|j                  dg       }d|v r|j                  d       |j                  t        |j                               |j!                  d|       |j#                         }d| | }t%        |      }t'        |j(                        }	|	j+                  dd	       t#        |	d
      }
|j,                   d|
 }n| j                  j#                         }t/        | d|||d      S )zD
    This method renders form and template to create key result
    datadataUrlr   .Key result %(key_result)s created successfully
key_resultrk   create_new_key_resultz/pms/NT)doseq?z#okr/key_result/key_result_form.html)r   redirect_urlr   )r;   r   r   r   r   r   r   r	   r   r   copygetlistremoveappendstrr   setlistr   r   r   querypoppathr   )r`   formr   r   r   mutable_getkey_result_idsr   
parsed_urlquery_paramsnew_query_strings              re   key_result_creater   D  s    8D;;??6*Lkkooi(G~~gll#==?yy{HBC*+
 "++**,K(00"EN&.8%%&=>!!#hkk"23@((*D"7)D62L!,/J#J$4$45LY-(TB(oo.a0@/ABL";;002L-'J rg   c                 j   t               }d}d}|:t        j                  j                  |      j	                         }t        |      }| j
                  dk(  r|rft        | j                  |      }|j                         r|j                         }t        j                  | t        d      d|iz         t        d      S t        | j                        }|j                         r?|j                         }t        j                  | t        d      d|iz         t        d      S t        | d	d
|i      S )z
    View function for creating or updating a Key Result.

    Parameters:
    - request: HttpRequest object.
    - kr_id: ID of the Key Result to update (optional).

    Returns:
    Renders a form to create or update a Key Result.
    Fr   r   r   z.Key result %(key_result)s updated successfullyr   r   r   z okr/key_result/real_kr_form.htmlr   )r;   rM   r\   r]   r   r   r   r   r   r	   r   r   r   r   )r`   kr_idr   krr   r   s         re   kr_create_or_updater   q  s    8D	BJ&&---7==?
z*~~',,<D}}99;  FG#X./
 $$OPP ',,'D}}99;  FG#X./
 $$OPP'=~NNrg   c                 h   t         j                  j                  |      }t        |      }| j                  dk(  rt        | j
                  |      }|j                         r|j                  d      }|j                  d   }|j                  d   }|D ]H  }|j                  j                  |       t        j                  j                  ||      j                         st        |||	      }j                          |j                  j                         }|ro|D ]j  }	t         j                  j                  ||	
      j                         r3t         j                  j#                  ||	|	j$                  |	j&                  |      }
l t)        j*                  | j,                  j.                  |j0                  dddddt3        dd|j4                  i             K |j                          t7        j8                  | t;        d      d|iz         t=        d      S ||d}t?        | d|      S )z
    this function is used to add assigneesto the objective
        args:
            obj_id(int) : pimarykey of Objective
        return:
            redirect to add assignees form
    r   r   r   Fcommitri   rj   r   r   r   rn   rk   ro   rp   rj   rq   rr   rs   rt   ru   rv   rw   rx   rz   r   r   r   )r   r   zokr/add_assignees.html) rQ   r\   r   r4   r   r   r   r   r   ri   addrK   r]   r   rk   r   rJ   r   ro   rp   r*   r   rZ   r[   r   r   r   r	   r   r   r   r   )r`   rw   r   r   ri   rj   r   r   r   r   r   rd   s               re   add_assigneesr     s    !!%%%0IY/D~~yA==?			/I))+6I**<8J  "##'',(0077 #) 8 &( 0$'iJG '5599;&1 

088??29  @   &( # &7%>%>%E%E6=.8.8.F.F-7-D-D+5 &F &F	
 LL--!22+SEKN$18Y\\:R/"F NN34Y7OO   KLL G '3W==rg   zpms.delete_employeeobjectivec                    	 t         j                  j                  |      }|j                  j	                         s5|j                          t        j                  | t        d      d|iz         n$t        j                  | t        d      d|iz         t        t              S # t        j                  $ r0 t        j                  | t        d             Y t        t              S w xY w)z
    This view takes one arguments, id and returns redirecting to a view.
    Args:
        id (int) : primarykey of the EmployeeObjective.
    Returns:
        Redirect to Objective_list_view".
    r   zObjective %(objective)s deletedr   z?You can't delete objective %(objective)s,related entries existsObjective not found.)rQ   r\   r   r   r   r   r	   r   r   warningrK   DoesNotExisterrorr   rf   )r`   rw   r   s      re   objective_deleter     s    ;%%))V)4	++22434Y7OO
 ST	*+ '(( )) ;w"8 9:'((;s   BB$ $2C'&C'zpms.change_objectivec                 p    t        t        |      }|j                  j                  |       t	        d      S )a  
    Removes a manager from an objective.

    Parameters:
    - request: HttpRequest object.
    - obj_id: ID of the Objective from which to remove the manager.
    - manager_id: ID of the manager to be removed.

    Returns:
    HttpResponse indicating success.
    r    )r   rQ   managersr   r   )r`   rw   
manager_idr   s       re   objective_manager_remover     s/     ")7Ij)rg   zpms.delete_keyresultc                 p    t        t        |      }|j                  j                  |       t	        d      S )a  
    Removes a Key Result from an objective.

    Parameters:
    - request: HttpRequest object.
    - obj_id: ID of the Objective from which to remove the Key Result.
    - kr_id: ID of the Key Result to be removed.

    Returns:
    HttpResponse indicating success.
    r   r   )r   rQ   rk   r   r   )r`   rw   r   r   s       re   key_result_remover     s/     ")7I""5)rg   c                     t        t        |      }t        t        ||      j                          |j                  j                  |       t               S )a  
    Removes an assignee from an objective.

    Parameters:
    - request: HttpRequest object.
    - obj_id: ID of the Objective from which to remove the assignee.
    - emp_id: ID of the employee to be removed as an assignee.

    Returns:
    HttpResponse indicating success.
    r   r   )r   rQ   rK   r   ri   r   r   )r`   rw   emp_idr   s       re   assignees_remover   %  sB     ")7IvFfhv&>rg   c                    | j                   j                         }ddi}| j                   j                  d      }t        | j                   xs ||      j                  j                  d      }| j                  j                  }d}t        j                  j                  t        |      t        |      z        j                         }| j                  j                  d      r!t        j                  j                         }d	}n0t        j                  j                  |      j                         rd	}t!        | j                   xs ||      j                  }t#        |t%                     }t#        |t%                     }	| j                   j                  d
      }
| j                   j                  d      }|	j'                  |
      }|j'                  |      }t(        j(                  j+                         }t-        |      }t/        t0        |       |d||t!               j2                  |||t4        j6                  |d
}|S )a$  
    This view takes two arguments, all_objective,own_objecitve and returns some objects.
    Args:
        all_objective (queryset) : Queryset of objectives
        own_objective (queryset) : Queryset of objectives
    Returns:
        All the filtered and paginated object will return.
    rY   Ffieldqueryset-id)r   )ri   zpms.view_objectiveTr   all_pagetrue)
manager	superuser
objectivesown_objectivesobjective_filer_formpgcurrent_dater   	gp_fieldsr   )r   r   r   r2   r   order_byrZ   r[   rQ   r\   r]   r   r^   has_permr   r   r,   r   r   get_pagedatetimenowr   r   rK   r   r3   fields)r`   rc   previous_datainitial_datar   objective_filter_ownra   r  r  objective_paginator_ownown_pager  objectives_ownr  r   rd   s                   re   r_   r_   <  s    KK))+Mu%LKKOOG$E*#|mb%  ||((HG 	  H!5H8M!MNhj  ||12&&**,
				!	!8	!	4	;	;	=&#|jb  :~'78J'(<n>NO{{v&H{{z*H,55h?N$$X.J





!C'I'3 ( 5 7 < < %,,G Nrg   c                 X   | j                   j                  d      }|d}| j                  j                  }t        j
                  j                  |      }t        | |      }d}| j                   j                  d      dk7  r| j                   j                  d      d}t        | ||      S )
    This view is used to to search objective,  returns searched and filtered objects.
    Returns:
        All the filtered and searched object will based on userlevel.
    searchr   rX   zokr/okr_list.htmlr   okr/group_by.html)	r   r   rZ   r[   rK   r\   r]   r_   r   )r`   
search_valra   rc   rd   rb   s         re   objective_list_searchr  t  s     *J
||((H%--444JM)'=AG"H{{w2%'++//'*B*N&'8W--rg   c                 ^    t        | j                        j                  }t        | dd|i      S )r  z3okr/emp_objective/emp_objective_dashboard_view.htmlr   )r.   r   r   r   )r`   r   s     re   objective_dashboard_viewr     s3     -W[[9<<N=	>* rg   c                     d g fd}t         j                  j                  |       }t        j                  j	                  |      }|D ]
  } ||        j                          S )z
    This view is used to get history of EmployeeObjective,  return objects.
    Args:
        id (int): Primarykey of EmployeeObjective.
    Returns:
        All the history of EmployeeObjective.
    c                 N    t        |       \  }}t        |d       t        ||      S )z%this function return two history pairN)r   nextzip)iterableabs      re   pair_historyz'objective_history.<locals>.pair_history  s$    8}1Q1ayrg   c                    | j                   j                         j                  d      j                         } 
|      D ]  }|\  }}|j	                  |      }|j
                  j                  }|j
                  j                  }t        j                  j                  |      j                         }|j
                  j                  } 	j                  |||| d        y)zkey result historyhistory_dater   )deltachanged_userchanged_datek_rN)historyr   r  iteratordiff_against
new_recordhistory_userr*  r   r\   r]   r   rk   r   )r   key_result_iteratorrecord_pair
old_recordr3  r,  history_user_idhistory_change_datera   changed_key_resultsr(  s            re   key_result_historyz-objective_history.<locals>.key_result_history  s     ""$--n=FFH 	 ((;< 	K%0"J
++J7E#..;;O"'"2"2"?"?''...PVVXH))77J&&"$,$7%		rg   r   rn   )rK   r\   r   rJ   r]   r   )
emp_obj_idr;  obj_objectiveall_key_resultsr   r:  r(  s        @@re   objective_historyr@    s{     * &--11Z1@M'//66+ 7 O & '
:&' !rg   c           
      x   t         j                  j                  |      }t        j                  j	                  |d      }| j
                  j                         }t        |      }t        j                  j                         }||||t        t        j                  t        |t               d	}t        | d|      S )z
    this function is used to update the key result of objectives
        args:
            obj_id(int) : pimarykey of EmployeeObjective
        return:
            objects to objective_detailed_view
    r   F)rl   rY   )	r   r   r   r   key_result_formobjective_key_result_statuscomment_formr
  emp_obj_formzokr/okr_detailed_view.html)rQ   r\   r   rK   r]   r   r   r   r  r  r:   rJ   STATUS_CHOICESr=   r.   r   )	r`   rw   ry   r   r   r  r   r  rd   s	            re   objective_detailed_viewrG    s     !!%%%0I&..55 6 N KK))+M'I





!C( ('8'G'G,/1
G '7AArg   c                 2   t         j                  j                  |      }| j                  j                  |j
                  k(  sU| j                  j                  |j                  j                  j                         v s| j                  j                  d      rt        |      }|j                         }t        j                  j                  |      }g }|D ](  }|d   d   j                  |d<   |j                  |       * |D ]#  }d||j                   d}	|j                  |	       % |D ]  }
d	|
|
d
   d}|j                  |        t#        |d d      }||||d}t%        | d|      S t'        j(                  | t+        d             t-        d      S )z
    This view is used to show objective activity template ,using htmx
    Args:
        id (int): Primary key of EmployeeObjective.
    Returns:
        it will return history,comment object to objective_detailed_view_activity.
    r   zpms.view_commentr<  pairr   datecomment)typerK  rJ  r   r.  )rL  r   rJ  c                     | d   S )NrJ   )xs    re   <lambda>z2objective_detailed_view_activity.<locals>.<lambda>  s
    AfI rg   T)r   r   )r   historyscommentsactivity_listz)okr/objective_detailed_view_activity.htmlYou dont have permission.*<script>window.location.reload();</script>)rK   r\   r   rZ   r[   rX   rl   r   r   r  r@  trackingrH   r]   r*  r   
created_atsortedr   r	   infor   r   )r`   r   r   r;  r0  rR  rS  histcomrK  r   r   rd   s                re    objective_detailed_view_activityr\    s    "))---4I!!Y%:%::<<$$	(>(>(G(G(K(K(MM<<  !34.r2$$&??))	)J 	'D<?77DL  &	'  	*C!G
   )	* & 	-C$!N+J
   ,	- }2EtT # *	
 gJGTTgq!<=>HIIrg   c                 T   t        | j                        }|j                         rtt        j                  j                  |      }|j                  d      }| j                  j                  |_	        ||_
        |j                          t        t        |      S t        t        |      S )z
    This view is used to create comment object for objective activity, using htmx
    Args:
        id (int): Primary key of EmployeeObjective.
    Returns:
        it will redirect to objective_detailed_view_activity.
    r   Fr   )r=   r   r   rK   r\   r   r   rZ   r[   rX   rn   r   r\  )r`   r   rD  r   r   s        re   objective_detailed_view_commentr^     s     (5L%--11R18	   ."<<44%."		8"==4b99rg   c                    t         j                  j                  |      }|j                  j	                         }| j
                  j                  d      }|d}t        | j
                  |      j                  }| j
                  j                  d      dk(  s|j                  d      }| j
                  j                         }t        |t                     }| j
                  j                  d      }|j                  |      }t        |      }t        t        |       ||||d	}d
}	| j
                  j                  d      dk7  r| j
                  j                  d      d}	t!        | |	|      S )z
    This view is used to to search employee objective,returns searched and filtered objects.
    Returns:
        All the filtered and searched object will based on userlevel.
    r   r  r   rY   r  FrY   r   )r   r   r	  r   z)okr/emp_objective/emp_objective_list.htmlr   r  )rQ   r\   r   r   r   r   r.   r   r]   r   r   r   r  r   r   rK   r   )
r`   rw   r   r   r  r  r   r   rd   rb   s
             re   emp_objective_searchra  6  s9    !!%%%0I11557N*J
,W[[.ILLN;;??9%/'..u.=KK))+M~~/?@N;;??6"D#,,T2N'I'3( 	G ;H{{w2%'++//'*B*N&'8W--rg   c                    t         j                  j                  |      }|j                  j	                         }t        |t                     }| j                  j                  d      }|j                  |      }| j                  j                         }|t        j                  ||t        j                  j                         j                         d}d}t        | ||      S )aT  
    Renders a table view of Key Results associated with an employee objective.

    Parameters:
    - request: HttpRequest object.
    - emp_objective_id: ID of the EmployeeObjective to display Key Results for.

    Returns:
    Renders the 'okr/kr_list.html' template with Key Results associated with the specified EmployeeObjective.
    r   krs_page)r   key_result_statusr   r   todayzokr/kr_list.html)rK   r\   r   employee_key_resultr   r   r   r   r  r   rJ   rF  r  re  rJ  r   )r`   emp_objective_idr   r   rc  r  rd   rb   s           re   kr_table_viewrh  X  s     &--115E1FM

+
+
/
/
1C
C)
*C{{z*H
,,x
 CKK))+M .==&""((*//1G "H'8W--rg   c                 "   t         j                  j                  |      }| j                  j                  d      }||_        |j                          t        j                  | t        d      d|j                  iz         t        t        |      S )a(  
    This view is used to  update status of objective in objective detailed view,
    redirect to objective_detailed_view_activity. using htmx
    Args:
        obj_id (int): Primary key of EmployeeObjective.
    Returns:
        All the filtered and searched object will based on userlevel.
    r   objective_statusz&Objective %(objective)s status updatedr   )rK   r\   r   r   statusr   r	   rY  r   r   r   r\  )r`   r   r   rk  s       re   (objective_detailed_view_objective_statusrl  w  s     "))---4I\\01FINNMM	
23	++
,	-
 4b99rg   c                    | j                   j                  d      }t        j                  j                  |      }|j                  }|j
                  }||k\  rd|_        n||_        |j                          t        j                  | t        d             t        t        |      }t        |j                  j                  d      dz         S )a^  
    This view is used to  update status of key result in objective detailed view,
    redirect to objective_detailed_view_activity. using htmx
    Args:
        obj_id (int): Primarykey of EmployeeObjective.
        kr_id (int): Primarykey of EmployeeKeyResult.
    Returns:
        All the filtered and searched object will based on userlevel.
    rd  r   ClosedzStatus has been updatedutf-8#<script>location.reload();</script>)r   r   rJ   r\   current_valuerp   rk  r   r	   rY  r   r   r\  r   contentdecode)r`   rw   r   rk  rf  rq  rp   responses           re   )objective_detailed_view_key_result_statusru    s     \\12F+337757A'55M&33L$%-"%+"MM'16788VDH(+PP rg   c                 v   | j                   dk(  r| j                  j                  d      }t        j                  j                  |      }|j
                  }|j                  j                  }t        |      |k  rK||_	        |j                          t        j                  | t        d      d|iz         t        t        |      S t        |      |k(  ry||_	        d|_        |j                          t        j                  | t        d      d|iz         t        t        |      }t#        |j$                  j'                  d      dz         S t        |      |kD  r/t        j(                  | t        d	             t        t        |      S t        j*                  | t        d
             t        t        |      S y)z
    This view is used to update current value of key result,  return redirect to view . using htmx
    Args:
        kr_id (int): Primarykey of EmployeeKeyresult.
    Returns:
        All the history of EmployeeObjective.
    r   rq  r   z0Current value of %(employee_key_result)s updatedrf  rn  ro  rp  z*Current value is greater than target valuez,Error occurred during current value updationN)r   r   r   rJ   r\   rp   rn   r   intrq  r   r	   rY  r   r   r\  rk  r   rr  rs  r   r   )r`   r   rq  rf  rp   rl   rt  s          re   %objective_detailed_view_current_valuerx    s    ~~((9/77;;u;E*77*@@CC},0=-$$&MMDE(*=>?
 <lKK</0=-)1&$$&MMDE(*=>?   @,OH  ''03XX  ,.Wa(T&UV<lKKw"P QR8,GGE  rg   c                    t         j                  j                  |      }|j                  r7d|_        |j	                          t        j                  | t        d             nB|j                  s6d|_        |j	                          t        j                  | t        d             t        d| j                  d          S )z
    this function is used to archive the objective
        args:
            id(int) : pimarykey of EmployeeObjective
        return:
            redirect to objective_list_view
    r   F$Objective un-archived successfully!.T!Objective archived successfully!.z/pms/objective-list-view?QUERY_STRING)
rQ   r\   r   rY   r   r	   rY  r   r   environ)r`   r   r   s      re   objective_archiver~    s     !!%%%,I!	gq!GHI 	gq!DEF/0O/PQRRrg   pms.view_employeeobjectivec                     t         j                  j                  |      }|t         j                  d}t	        | d|      S )z
    This function is used to render individual view of the employee objective
        args:
            emp_obj_id(int) : pimarykey of EmployeeObjective
        return:
            redirect to individual view of employee objective
    r   )r   rC  zokr/emp_obj_single.html)rK   r\   r   rF  r   )r`   r=  r   rd   s       re   view_employee_objectiver    sB     &--11Z1@M!'8'G'GG '4g>>rg   c                 J   | j                   j                         }|j                         D ci c]  \  }}|t        |      dkD  r|n|d    }}}t	        |      }| j
                  dk(  rt	        | j                        }|j                         rkt        |j                  d         }|j                  d      }|j                  }|j                  j                  |j                         |j                  |j                   j#                         D 	cg c]  }	|	 c}	       t%        |      }
|j                          |
D ]  }|j                   j                  |       t&        j(                  j+                  ||      j-                         rNt&        j(                  j/                  |||j0                  |j2                  |j4                  	      } t7        j8                  | t;        d
             t=        d      S |t?               dd}tA        | d|      S c c}}w c c}	w )z
    This function is used to create the employee objective
        args:
            emp_obj_id(int) : pimarykey of EmployeeObjective
        return:
            redirect to form of employee objective
       r   initialr   rk   Fr   r   r   z'Employee objective created successfullyr   T)r   r   r   z0okr/emp_objective/emp_objective_create_form.htmlr   )!r   r   listsr   r7   r   r   r   r   r   r   rl   ri   r   rX   extendrk   r   setrJ   r\   r]   r   r   ro   rp   rj   r	   r   r   r   r;   r   )r`   r   r   valuer   r   r   r   objr   set_krsr   r   rd   s                 re   create_employee_objectiver    s    ;;D FJZZ\7AsEc%j1nU%(2L  '|<D~~*7<<8==?t((9:Ciiui-G&&CMMg112JJS5F5F5J5J5LMz
MN#hGLLN %%))"-(0077*1 8 &( /66==.5&(&(&6&6%'__#*#5#5 > F Wa(Q&RS KLLvxDAGCW A Ns    H	H c                    t         j                  j                  |      }| j                  j                  |j
                  k(  s:| j                  j                  |j                  j                  j                         v rt        |      }| j                  dk(  rst        | j                  |      }|j                         rL|j                  d      }|j                          t        j                  | t!        d             t#        d      S |t%               d}t'        | d	|
      S t        j(                  | t!        d             t#        d      S )z
    This function is used to update the employee objective
        args:
            emp_obj_id(int) : pimarykey of EmployeeObjective
        return:
            redirect to form of employee objective
    r   r   r   Fr   z'Employee objective Updated successfullyr   )r   r   zokr/emp_objective_form.htmlr   zYou don't have permission.)rK   r\   r   rZ   r[   rX   rl   r   r   r8   r   r   r   r   r	   r   r   r   r;   r   rY  )r`   r=  r   r   r   rd   s         re   update_employee_objectiver  8  s    &--11Z1@M!!]%>%>><<$$(B(B(K(K(O(O(QQ$m<>>V#(ND}}))5)1  !,U*VW#$OPP684g<gNNgq!=>?GHHrg   c                    t         j                  j                  |      }|j                  j                  }|j
                  r7d|_        |j                          t        j                  | t        d             nB|j
                  s6d|_        |j                          t        j                  | t        d             t        | j                  j                  dd            S )z
    This function is used to archive or unarchive the employee objective
        args:
            emp_obj_id(int) : pimarykey of EmployeeObjective
        return:
            redirect to detailed of employee objective
    r   Frz  Tr{  HTTP_REFERER/)rK   r\   r   rl   r   rY   r   r	   r   r   r   META)r`   r=  r   rw   s       re   archive_employee_objectiver  V  s     &--11Z1@M''**F %!$J"KL"" $!$G"HI 0 0 EFFrg   c                    t         j                  j                  |      }| j                  j                  d      }|j                  j                         r t        j                  | t        d             nb|j                  }|j                  }|j                          |j                  j                  |       t        j                  | t        d             |s%t        | j                   j                  dd            S t#        d      S )z
    This function is used to delete the employee objective
        args:
            emp_obj_id(int) : pimarykey of EmployeeObjective
        return:
            redirect to detailed of employee objective
    r   single_viewz6You can't delete this objective,related entries exists Objective deleted successfully!.r  r  r   )rK   r\   r   r   rf  r   r	   r   r   rX   rl   r   ri   r   r   r   r  r   )r`   r=  r   r  ra   r   s         re   delete_employee_objectiver  n  s     &--11Z1@M++//-0K((//1QOP	
 !,,!..	""8,!$F"GH#GLL$4$4^S$IJJGHHrg   c                    | j                   j                  d      }t        j                  j	                  |      j                         }| j                   j                  d      }| j                  j                  d      s^|j                  | j                  j                  k(  s;| j                  j                  |j                  j                  j                         v r|j                  |k7  rI||_        |j                          t        j                   | t#        d|j                   d|j                   d             t%        j&                  | j                  j                  |j                  j(                  d|j                   d|j                   dd|j                   d	|j                   dd
|j                   d|j                   dd|j                   d|j                   dd|j                   d|j                   dt+        dd|j                  j,                  i             t1        d      S t        j.                  | t#        d             t1        d      S t        j.                  | t#        d             t1        d      S )z
    This function is used to change status of the employee objective
        args:
            hx-request
        return:
            a message
    empObjIdr   rk  r   zThe status of the objective 'z)'                    has been changed to .u%   تم تغيير حالة الهدف 'u   '                    إلى zDer Status des Ziels 'z'                    wurde zu u    geändert.zEl estado del objetivo 'z('                    ha sido cambiado a zLe statut de l'objectif 'u(   '                    a été changé à rv   rw   rx   rz   z4The status of the objective is the same as selected.rT  4<script>$('#reloadMessagesButton').click();</script>)r   r   rK   r\   r]   r   rZ   r  rX   r[   rl   r   r   rk  r   r	   r   r   r*   r   r   r   r   rY  r   )r`   r   r   rk  s       re    change_employee_objective_statusr    sf    kkooj)G%--444@FFHM[[__X&F<=$$(A(AA<<$$(B(B(K(K(O(O(QQ6)#)M  3M4N4N3O P))6)=)=(>aA KK))'33DD4]5O5O4P Q))6)=)=(>aA?@Z@Z?[ \)001401K1K0L M+223;@2=3M3M2N O((5(<(<'=Q@3M4N4N3O P((5(<(<'=Q@ -$m&@&@&C&CD2 NOO MMQR NOO 	gq!<=>NOOrg   pms.add_employeekeyresultc                     t        | j                        j                  }t        |d| j                  j	                  d      d      }|t
        j                  d}t        | d|      S )z
    This view is used to view key result,
    Args:
        request: Request object.
    Returns:
        if errorr occur it will return errorr message.
    "employee_objective_id__employee_idr   )r   rd  z%okr/key_result/kr_dashboard_view.htmlr   )r0   r   r   r'   r   rJ   rF  r   )r`   r   rd   s      re   key_result_viewr    s`     '++
&
)
)C
17;;??63JFC .==G 'BGTTrg   c                    | j                   j                  }|dk(  r]t        j                  j	                  t        |            }d}d}|D ]  }|j                  }|j                  } t        |||d      }nrt        j                  |      }	|	D ]H  }
t        j                  j	                  |
      j                         }|j                  }|j                  }J t        |d      }|||d}|dk(  r|j                  d      }||d	<   | j                  d
k(  r|dk(  rt        j                  j                  t        |            }t        | j                  d|i      }|j!                         ri|j#                  d      }|j$                  |_        ||_        |j#                          t+        j,                  | t/        d             t1        t2        |      S ||d<   n|dk(  r t        j                  |      }	|	D ]  }
t        j                  j	                  |
      j                         }t        | j                  d|i      }|j!                         rL|j#                  d      }|j$                  |_        |j4                  |_        ||_        |j#                          ||d<   t7        | d|      c S  t+        j,                  | t/        d             t1        t8              S t7        | d|      S )z
    This view is used to create key result,
    Args:
        id (int): Primarykey of EmployeeObjective.
        obj_type (str): type  of objecitve
    Returns:
        if errorr occur it will return errorr message .
    
individualr   Nrj   end_date)ra   r  )rB  rl   objective_typemultiplerl   objective_idsr   rn   r  Fr   Key result createdrB  z'okr/key_result/key_result_creation.htmlzKey results created)rZ   r[   rK   r\   r]   rw  rj   r  r:   r   loadsr   r   r   r   r   r   r   rq  start_valuern   r	   r   r   r   rG  rX   r   rf   )r`   rw   obj_typera   r   rj   r  r  rB  r  rl   rd   r  rn   form_key_resultr   s                   re   key_result_creationr    s    ||((H<%--44F4D	
 	$CJ||H	$ (jh'W
 

6*) 	*L)1188L8IOOQI"--J ))H	* (jh'W
 +"G
 :N+#( ~~|#$5$=$=$A$AS[$A$Q!+'>@U&VO '')&++5+9#'#5#5 -B*		  !,@*AB 7@@-<)*# !JJv.M - -55<<<MSSU	"/LL+BI*N# #++-*//u/=D'+'9'9D$'0'<'<D$1:D.IIK1@G-.!!JG   Wa(=&>?/00'DgNNrg   c                    t         j                  j                  |      }d}d}|D ]  }|j                  }|j                  } t        ||d      }||d}t         j                  j                  |      }| j                  dk(  rd|i}	t        | j                  |	      }
|
j                         r|
j                  d	      }|j                  |_        ||_        |j                          t        j                  | t!        d
             t#        | d|      }t%        |j&                  j)                  d      dz         S |
|d<   t#        | d|      S )a  
    This view is used to create key result in objective detailed view,  using htmx
    Args:
        id (int): Primarykey of EmployeeObjective.
        obj_type (str): type  of objecitve
    Returns:
        if errorr occure it will return errorr message .
    r   Nr  r  )rB  objecitve_idr   rn   Fr   r  z,okr/key_result/key_result_creation_htmx.htmlro  rp  rB  )rK   r\   r]   rj   r  r:   r   r   r   r   r   rq  r  rn   r	   r   r   r   r   rr  rs  )r`   r   objectrj   r  r  rB  rd   r   r  r  r   rt  s                re   key_result_creation_htmxr  )  sS    &&---4FJH  ^^
<<  $)x@O #22FG!))---4I~~/;'lK##%"''u'5D#11D)2D&IIKWa(<&=>GH    ''03XX  &5!"'I7SSrg   zpms.update_employeekeyresultc                     t         j                  j                  |      }t        |      }||j                  d}| j
                  dk(  rt        | j                  |      }|j                  |j                  d<   |j                         rc|j                          t        j                  | t        d             t        | d|      }t        |j                   j#                  d      d	z         S ||d
<   t        | d|      S )z
    This view is used to update key result, using htmx
    Args:
        id (int): Primarykey of EmployeeKeyResult.
    Returns:
        success or errors message.
    r   r   )rB  rk   r   rn   zKey result updatedz%okr/key_result/key_result_update.htmlro  rp  rB  )rJ   r\   r   r:   r   r   r   rn   r  r   r   r	   rY  r   r   r   rr  rs  )r`   r   r   rB  rd   rt  s         re   key_result_updater  S  s     #**..".5J#Z8O"1JMMRG~~'zJ,, 	 78 ##%  "MM'1%9#:;g'NPWXH  ''03XX  *9G%&'BGLLrg   c                    |j                   r_|j                   }t        j                  | j                  j                  |j
                  dddddt        dd|j                  i      d	
	       |j                  r_|j                  }t        j                  | j                  j                  |j
                  dddddt        dd|j                  i      d	
	       |j                  rt|j                  j                         }|D ]U  }t        j                  | j                  j                  |j
                  dddddt        dd|j                  i      d	
	       W |j                  ru|j                  j                         }|D ]U  }t        j                  | j                  j                  |j
                  dddddt        dd|j                  i      d	
	       W y y )NzYou have received feedback!u!   لقد تلقيت ملاحظات!zSie haben Feedback erhalten!u"   ¡Has recibido retroalimentación!u"   Vous avez reçu des commentaires !zfeedback-detailed-viewr   rx   zchatbox-ellipsesr{   r|   r}   r~   r   r   r   iconz2You have been assigned as a manager in a feedback!u6   لقد تم تعيينك كمدير في ملاحظة!z4Sie wurden als Manager in einem Feedback zugewiesen!u0   ¡Has sido asignado como manager en un feedback!u=   Vous avez été désigné comme manager dans un commentaire !z6You have been assigned as a subordinate in a feedback!u8   لقد تم تعيينك كمرؤوس في ملاحظة!z9Sie wurden als Untergebener in einem Feedback zugewiesen!u4   ¡Has sido asignado como subordinado en un feedback!uA   Vous avez été désigné comme subordonné dans un commentaire !z4You have been assigned as a colleague in a feedback!u6   لقد تم تعيينك كزميل في ملاحظة!z4Sie wurden als Kollege in einem Feedback zugewiesen!u/   ¡Has sido asignado como colega en un feedback!u?   Vous avez été désigné comme collègue dans un commentaire !)rX   r*   r   rZ   r[   r   r   r   r   subordinate_idr   colleague_id)r`   r   ra   r  subordinatessubordinate
colleagues	colleagues           re   send_feedback_notificationsr  t  s   ##LL%%//.72885tTWWoN#
	
 //LL%%..ELJFS5tTWWoN#
	
 **..0' 	KKK))%66MRSN[ !94/R'
	 &&**,
# 	IKK))#44KPNIY !94/R'
	 rg   zpms.add_feedbackc                    t               }d|i}| j                  dk(  r(t        | j                        }|j                         r|j                  j                  d      }| j                  j                  d      x}r`|D ][  }t        j                  j                  |      j                         }|j                         }|j                  j                  |       ] |j                         }|j                  j                  |       t        j                   | t#        d             t%        | |       t'        t(              S ||d<   t+        | d|      S )	zr
    This view is used to create feedback object.
    Returns:
        it will return feedback creation html.
    feedback_formr   r  employee_key_results_idr   zFeedback created successfully.)r   zfeedback/feedback_creation.html)r9   r   r   r   r   r   rJ   r\   r]   r   r   r  r   r  r  r	   r   r   r  r   feedback_list_viewr   )	r`   r   rd   	employeesr   rk   r   r  r   s	            re   feedback_creationr    s.    >DG ~~GLL)==?		))*:;I!(!5!56O!PP~P%3 JM!2!:!:!A!A( "B "eg  %)IIKM!99==jIJ yy{H##''	2Wa(H&IJ'h?.//'+GO$'<gFFrg   zpms.change_feedbackc                 D   t         j                  j                  |      }t        |      }t        j                  j                  |      }d|i}|rSt        j                  | t        d             t        | d|      }t        |j                  j                  d      dz         S | j                  d	k(  r_t        | j                  |      }|j                         r2|j                   j#                  d
      }| j                  j#                  d      x}r`|D ][  }	t$        j                  j                  |	      j'                         }
|j)                         }|j*                  j-                  |
       ] |j)                         }|j.                  j1                  |       |j)                         }t        j2                  | t        d             t5        | |       t        | d|      }t        |j                  j                  d      dz         S ||d<   t        | d|      S )z
    This view is used to  update the feedback.
    Args:
        id(int) : primarykey of the feedback.
    Returns:
        it will redirect to  feedback_detailed_view.
    r   r   feedback_idr  z"Ongoing feedback is not editable!.zfeedback/feedback_update.htmlro  rp  r   r  r  zFeedback updated successfully!.)rL   r\   r   r9   rF   r]   r	   r   r   r   r   rr  rs  r   r   r   r   r   rJ   r   r   r  r   r  r  rY  r  )r`   r   feedbackr   feedback_startedrd   rt  r  r   rk   r   r  r   s                re   feedback_updater    s    ##r#*H*D~~,,,B%Gw"F GH'#BGL##G,/TT
 	
 ~~GLL8<==?		))*:;I!(!5!56O!PP~P%3 JM!2!:!:!A!A( "B "eg  %)IIKM!99==jIJ yy{H##''	299;DMM'1%F#GH'6g'FPH  ''03XX  (,GO$':GDDrg   c           
      0   | j                   j                         }ddi}t        | j                   xs ||      }t        | j                   xs ||      }t        | j                   xs ||      }	t        | j                   |      j                  }t        |j                  t                     }
t        |j                  t                     }t        |	j                  t                     }| j                   j                  d      }|
j                  |      }|j                  |      }|j                  |      }t        j                  j                         j                         }t        |      }t        t        |       d|||||j                  |||d	}|S )aj  
    This view is used to filter or search the feedback object  ,

    Args:
        self_feedback (queryset): self feedback filtered queryset.
        requested_feedback (queryset): requested feedback filtered queryset.
        all_feedback (queryset): all feedback filtered queryset.

    Returns:
        it will return the filtered and searched object.

    rY   Fr   r   r  )	r  self_feedbackrequested_feedbackanonymous_feedbackall_feedbacksfeedback_filter_formr	  r
  r   )r   r   r/   r-   r   r   r   r   r  r  re  rJ  r   r   rL   r   )r`   r  r  all_feedbackr  r  r  feedback_filter_ownfeedback_filter_requestedfeedback_filter_allfeedback_paginator_ownfeedback_paginator_requestedfeedback_paginator_allpage_numberfeedbacks_ownfeedbacks_requestedfeedbacks_allr  r   rd   s                       re   filter_pagination_feedbackr  -  s|     KK))+Mu%L(#|m !/#|.@! )#|l 10b  '':'='=~?OP#,!$$n&6$  '':'='=~?OP++//&)K*33K@M6??L*33K@M



!
!
#
(
(
*C'Ih	*&10& 3 8 8 
G Nrg   c                    | j                   j                  d      }|d}t        j                  j                  | j                        }t
        j                  j                  |      j                  |      }g }|j                  t
        j                  j                  |      D cg c]  }|j                   c}       |j                  t
        j                  j                  |      D cg c]  }|j                   c}       |j                  t
        j                  j                  |      D cg c]  }|j                   c}       t
        j                  j                  |	      j                  |      }t
        j                  j                         }| j                  j                  d
      r/t
        j                  j                         j                  |      }n0t
        j                  j                  |      j                  |      }| j                  j                  d
      s5t        j                  j                  | j                  j                  d      nt        j                  j                  d      }t        |      }	|	|z  j                         }t        | ||||      }
t!        | d|
      S c c}w c c}w c c}w )
    This view is used to filter or search the feedback object  ,
    Args:
    Returns:
        it will return the filtered and searched object.
    r  r   r+  r  )review_cycle__icontainsr   r  r  )pk__inpms.view_feedbackFanonymous_feedback_idrY   r`  zfeedback/feedback_list.html)r   r   r   r\   rZ   rL   r]   r  r   noner  r   rE   rC   r^   r  r   )r`   r  rX   r  requested_feedback_idsir  r  r  related_anonymous_feedbacksrd   s              re   feedback_list_searchr  f  sw    {{x(H""&&&EK$$+++DKK ( L M  !!''..+.FG!G !!''..K.HI!I !!''..k.JK!K "))008N0OVV ( W  ##((*L||01''++-44X4V  ''..+.FMM$, N 
 ||$$%89 	!!(("),,//5 	) 	
 &&--e-<  #:+"F58JJTTV( 2LBTG '8'BBE 	H 	J 	Ls   )K0K7Kc                    | j                   }|j                  }t        j                  j	                  |d      }t        j                  j	                  t        |      t        |      z  t        |      z        j                         }|j                  d      r!t        j                  j	                  d      }n!t        j                  j	                  |d      }| j                   j                  d      s5t        j                  j	                  | j                   j                  d	      nt        j                  j	                  d      }t        |      }|j	                  d      |z  j                         }t        | ||||      }t        j                  j                         j                         rd
}	nd}	t        | |	|      S )r  FrW   r  r  r  r  r`  )r   rY   r  z feedback/feedback_list_view.htmlzfeedback/feedback_empty.html)rZ   r[   rL   r\   r]   r   r^   r  rE   r   rC   r  r   r   r   )
r`   rZ   ra   feedback_ownfeedback_requestedfeedback_allr  r  rd   rb   s
             re   r  r    s    <<D  H##** + L
 "))00	X!99AX<VVhj  }}()''..u.=  ''..(E.R ||$$%89 	!!(("),,//5 	) 	
 &&--e-<  #:("C#**5*9<NNhj  )1<ASG $$&51'8W--rg   c                 
   t         j                  j                  |      }t        | |d      }|rt        j                  j                  |      }|j                         }g }g }|D ]T  }	t        j                  j                  ||	      j                         r|j                  |	       D|j                  |	       V ||d}
||t         j                  |
t        j                  j                         j                         d}t        | d|      S t        j                  | t!        d             | j"                  j                  d	d
      }d| d}d}|| j"                  j%                         v rt        | d      S t'        |      S )z
    This view is used to for detailed view of feedback,
    Args:
        id(int) : primarykey of the feedback
    Returns:
        it will return the feedback object to feedback_detailed_view template .
    r   r  r  r  rX   )yesno)r  r  feedback_statusemployee_staticsre  z$feedback/feedback_detailed_view.htmlrT  r  r   <script>window.location.href = "
"</script>HTTP_HX_REQUESTdecorator_404.html)rL   r\   r   rB   rF   r]   requested_employeesr   r   rF  r  re  rJ  r   r	   rY  r   r  keysr   )r`   r   ry   r  is_have_permr  r  r  r  ra   r  rd   previous_urlscriptr   s                  re   feedback_detailed_viewr    ss    ##r#*H:.L !>>00R0@002	! 	$H~~$$$( % fh 

8$		(#	$ $'b1  0'66 0&&,,.335
 gEwOOgq!<=>||''<3L>L',,##%%'#788F##rg   c                 l   t         j                  j                  |      j                         }t        j                  j                  |      j                         }t        | |d      }t        j                  j                  ||      }|r3t        j                  j                  ||      }||d}t        | d|      S t        j                  | t        d             | j                  j                  dd	      }	d
|	 d}
d}|| j                  j                         v rt        | d      S t        |
      S )z
    This view is used show  answer ,
    Args:
        id(int) : primarykey of the feedback.
        emp_id(int) : primarykey of the Employee.
    Returns:
        it will return the answers .
    r   r  r  rX   r  )answerskr_feedbacksz+feedback/feedback_detailed_view_answer.htmlrT  r  r  r  r  r  r  )r   r\   r]   r   rL   rB   rN   rF   r   r	   rY  r   r  r   r  r   )r`   r   r   ra   r  r  r  r  rd   r  r  r   s               re   feedback_detailed_view_answerr    s$    &&&&1779H&&"&-335H:.L %,,33( 4 L ..''H('S(
 gLgVVgq!<=>||''<3L>L',,##%%'#788F##rg   c                    | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      }t        j                  j                  ||      }|j                  }|j                  j                         }t        j                  j                         }	|j                  g|j                  gz   t        |j                  j                               z   t        |j                   j                               z   }
||
vr.t#        j$                  | t'        d             t)        t*              S |
D ]1  }t        j                  j                  ||      j-                         }3 rd|_        |j1                          |r.t#        j$                  | t'        d             t)        t*              S ||	|d}t3        | d	|      S )
z
    This view is used to render the feedback questions ,
    Args:
        id(int) : primarykey of the feedback.
    Returns:
        it will redirect to feedaback_answer.html .
    r+  r   r  You are not allowed to answerr   rn  zFeedback already answered)	questionsoptionsr  z$feedback/answer/feedback_answer.html)rZ   r   r\   r]   r   rL   r   rF   question_template_idquestionr   rT   rX   r   r   r  r  r	   rY  r   r   r  r   rk  r   r   )r`   r   ry   rZ   ra   r  answerquestion_templater  r  feedback_employees
has_answerrd   s                re   feedback_answer_getr    s    <<D&&&=CCEH##r#*H^^""xX"NF 55!**..0I%%))+G			
	 
x$$((*
+	, x&&**,
-	.  ))gq!@AB*++ ' ^^** h + 

&( 	 " gq!<=>*++ G 'A7KKrg   c                    | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      }|j                  }|j                  j                         }| j                  dk(  rz|D ]  }| j                  j                  d|j                         s,| j                  j                  d|j                         }t        j                  j                  d|i|||       d|_        |j!                           |j"                  j                         D ]  }	| j                  j                  d|	j                         s,| j                  j                  d|	j                         }t$        j                  j                  d|i|	|| j                   j&                          t)        j*                  | t-        d	      d
|j.                  iz         t1        t2              S y)z
    This view is used to create feedback answer ,
    Args:
        id(int) : primarykey of the feedback.
    Returns:
        it will redirect to feedback_list_view if the form was success full.
    r+  r   r   r
  )r
  question_idr  rX   zOn Trackr   )r
  rk   r  rX   z:Feedback %(review_cycle)s has been answered successfully!.review_cycleN)rZ   r   r\   r]   r   rL   r   r  r	  r   r   r   r   rF   get_or_createrk  r   r  rN   r[   r	   r   r   r  r   r  )
r`   r   rZ   ra   r  r  r  r	  r
  r   s
             re   feedback_answer_postr  N  s    <<D&&&=CCEH##r#*H 55!**..0I~~! 
	 H||& 67 ))F8;;-*@A,,$f- ( ( (	 -  #-
	  #::>>@ 	J||*Z]]O <= ))Jz}}o*FG!))77$f-", ( ' 9 9	 8 	 	JKx4456	

 *++5  rg   c                    | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      }t        j                  j                  ||      }t        j                  j                  ||      }|s.t        j                  | t        d             t        t              S |||d}t        | d|      S )z
    This view is used to  view the feedback for employee.
    Args:
        id(int) : primarykey of the feedback.
    Returns:
        it will return feedback answer object to feedback_answer_view.
    r+  r   r  zFeedback is not answered yet)r  r  key_result_feedbackz)feedback/answer/feedback_answer_view.html)rZ   r   r\   r]   r   rL   r   rF   rN   r	   rY  r   r   r  r   )	r`   r   ry   rZ   ra   r  r  r  rd   s	            re   feedback_answer_viewr  {  s     <<D&&&=CCEH##r#*Hnn##h#OG+33::( ;  gq!?@A*++ 2G
 'FPPrg   zpms.delete_feedbackc                 $   	 t         j                  j                  |      j                         }t        j                  j                  |      j                         }|j
                  dk(  s|j
                  dk(  rA|s?|j                          t        j                  | t        d      d|j                  iz         nHt        j                  | t        d      |j                  |j
                  dz         t        t              S 	 t        t              S # t         j                  $ r0 t        j                  | t        d	             Y t        t              S t         $ r0 t        j                  | t        d
             Y t        t              S w xY w)z
    This view is used to  delete the feedback.
    Args:
        id(int) : primarykey of the feedback.
    Returns:
        it will redirect to  feedback_list_view.
    r   r  rn  Not Started/Feedback %(review_cycle)s deleted successfully!r  AYou can't delete feedback %(review_cycle)s with status %(status)sr  rk  Feedback not found.Related entries exists)rL   r\   r]   r   rF   rk  r   r	   r   r   r  r   r   r  r   r   r   )r`   r   r  answereds       re   feedback_deleter    sS   =##**b*1779>>((X(>DDFOOx'-/OOCD!8#8#89: UV#+#8#8HOOTU
 .//$ &''	    :w"7 89 &''  =w": ;<&''=s   DD 2F'FFc                 (   | j                   j                  d      }t        t        |      }t        j
                  j                  |      }|dk(  r,|r*t        j                  | t        d             t        d      S ||_        |j                          |j                  |k(  r8t        j                  | t        d      dt        |      iz         t        d      S t        j                  | t        d	      dt        |      iz         t        d      S )
z
    This view is used to  update status of feedback.
    Args:
        obj_id (int): Primarykey of feedback.
    Returns:
         message to the view
    r  r   r  r  zFeedback is already startedr  z&Feedback status updated to  %(status)srk  z1Error occurred during status update to %(status)s)r   r   r   rL   rF   r\   r]   r	   r   r   r   rk  r   r   rY  )r`   r   rk  r  r
  s        re   feedback_detailed_view_statusr!    s     \\/0F b1H^^""x"8F6!$A"BCRSSHOMMOF"Q?@HaPViCXX	
 RSSMM	
=>(AfIAVV NOOrg   c                    |r.t         j                  j                  |      j                         nd}|r0t	        | |d      r |j
                  }|j                  j                         }|j                  j                         }|j                  j                         }i }|D ]_  }g }	|D ]Q  }
|
j                  |k(  s|	j                  |
j                  |
j                  d|
j                  j                  igi       S |	||<   a |D ]K  }g }	|	j                  |j                  |j                  ddigi       |	|d|j                  j                   <   M t!        | dd	|i
      S yy)z
    overview of feedback
    r   Nr  r   rL  6zFeedback about keyresult: zfeedback/feedback_overview.htmlfeedback_overviewr   )rL   r\   r]   r   rB   r  r	  r   feedback_answerfeedback_key_resultr  r   rX   r
  question_typerk   r   )r`   rw   r  r  r  feedback_answersr  r$  r	  answer_listr
  kr_feedbacks               re   get_feedback_overviewr+    s   
 >Dx&&&&1779H; 3 %99%..224	#3377933779! 	6HK* 	%%1&&".. &!'););)I)I J1	 +6h'	6 ( 	KK((;+=+=}*MN
  ,[-F-F-T-T,UV	 -(*;<
 	
=xrg   c                    t         j                  j                  |      }|j                  rEd|_        |j	                          t        j                  | t        d             t        t              S |j                  s6d|_        |j	                          t        j                  | t        d             t        t              S )v
    this function is used to archive the feedback for employee
    args:
        id(int): primarykey of feedback
    r   F#Feedback un-archived successfully!.T Feedback archived successfully!.)
rL   r\   r   rY   r   r	   rY  r   r   r  )r`   r   r  s      re   feedback_archiver0    s     ##r#*H gq!FGH
 &''	 gq!CDE&''rg   c                    	 | j                   j                  d      }|r)t        j                  j                  t	        |            nd}|rt        j                  j                         }|j                  r|j                  j                  nd}| j                   j                  d      dk(  rl|j                         }|j                  g}|r|j                  |j                         t        j                  j                  d|      j                  |      }n| j                   j                  d      d	k(  r-|rt        j                  j                  |j                        }n| j                   j                  d      d
k(  r"t        j                  j                  d|      }nN| j                   j                  d      dk(  r0t        j                  j                  |      j                  dd      }|D cg c]  }|j                  |f }}d|i}t        d|      }	t!        |	      S t#        ddid      S c c}w # t        j$                  $ r t#        ddid      cY S t&        $ r"}
t#        dt)        |
      id      cY d}
~
S d}
~
ww xY w)z9
    Get collegues and subordinates for the manager.
    rX   r   Nr   r  T)	is_active!employee_work_info__department_idid__inr  r  )r2  (employee_work_info__reporting_manager_id
keyresultsr  r   key_result_id__titler  zemployee/employees_select.htmlr   zEmployee not foundi  rk  zInvalid Employee ID  i  )r   r   r   r\   rw  r  employee_work_inforeporting_manager_idget_departmentr   r   r]   excluderJ   values_listr   r   r   r   	Exceptionr   )r`   rX   ra   employees_querysetreporting_manager
departmentexclude_idsr  rd   employee_htmles              re   get_colleguesrH  !  sT   
.;kkoom4@K8##''3{+;'<QU!)!1!1!6!6!8 .. ++@@  {{v&,6%446
'{{m$&&'8';';< &.%5%5%<%<"j &= &''- # (I5$)1)9)9)@)@,// *A *& (N:%-%5%5%<%<"X &= &" (L8%6%>%>%E%E7? &F &+d$:; # BTTX(++x0TIT"I.G,-MwWM..*> ?LL U    JW&;<SII ;Wc!f-c::;s<   G4H< 6H7H< (H< 7H< <"J
 J
(J?J
J
c                    | j                   j                  d      dk(  }|r| j                  dk(  r| j                  j                  d      }| j                  j                  d      }t        j
                  j                  |      }t        j
                  j                  |      j                         }t        j
                  j                  ||      }|rt        d      n
t        d	      }t        d
|i      S t        d
did      S y)zthis function is used to un-archive the feedback
    args:
        id(int): primarykey of feedback
        emp_id(int): primarykey of feedback
    X-Requested-WithXMLHttpRequestr   rX   r  r   r   	CompletedzNot-completedrk  zInvalid requestr;  r:  N)headersr   r   r   rL   r\   r   r]   r   rF   r   r   )r`   is_ajaxrX   r  r  ra   r
  rk  s           re   r  r  W  s     oo!!"459IIG>>V#!,,**=9K!,,**=9K''++{+;H''..+.>DDFH^^**xX*VF'-Q{^1_3EF6 233X'89#FF rg   zpms.add_questionc                    | j                   dk(  rt        | j                        }t        j                  j                  |      }t        j                  j                  |      j                         }|r/t        j                  | t        d             t        t        |      S |j                         r |j                  d      }||_        |j                          |j"                  dk(  r| j                  j                  d      }| j                  j                  d	      }| j                  j                  d
      }| j                  j                  d      }	t%        |||||	      j                          t        j&                  | t        d             t        t        |      S t        j&                  | t        d             t        t        |      S t        j(                  | t        d             t        t        |      S y)z
    This view is used to  create  question object.
    Args:
        id(int) : primarykey of the question template.

    Returns:
        it will redirect to  question_template_detailed_view.
    r   r   r  z&Question template is used in feedback.Fr   4option_aoption_boption_coption_d)r  rR  rS  rT  rU  zQuestion created successfully.z(Error occurred during question creation!N)r   r@   r   rU   r\   r   rL   r]   r   r	   rY  r   r   question_template_detailed_viewr   r   template_idr'  rT   r   r   )
r`   r   r   r  feedback_ongoingobj_questionrR  rS  rT  rU  s
             re   question_creationrZ  l  s    ~~GLL),4488B8?#++22!2 3 

%' 	 MM'1%M#NO;R@@==?99E92L'8L$))S0"<<++J7"<<++J7"<<++J7"<<++J7 ,%%%% $&  !,L*MN ?DDWa(H&IJ;R@@NN7A&P$QR;R@@C  rg   c                 Z   t         j                  j                  |      }t        t        t
        d      }|j                  j                         } ||      }g }g d}|D ]3  }t        j                  j                  |      }	|j                  |	       5 |||||d}
t        | d|
      S )	z
    This view is used to  view  question object.
    Args:
        id(int) : primarykey of the question template.
    Returns:
        it will redirect to  question_template_detailed_view.
    r   r   )r   extrar   )textratingsbooleanzMulti-choiceslikertr  )r  r  question_optionsquestion_typesformset?feedback/question_template/question_template_detailed_view.html)rU   r\   r   r   rS   r@   r	  r   rT   r]   r  r   )r`   r   r  question_formsetr  rd  r  rc  r	  rb  rd   s              re   question_viewrg    s     )00444;+H<qQ!**..0I	2GGNN )*2299h9O'() /#(G I rg   zpms.change_questionc                 <   | j                   dk(  rt        j                  j                  |      }t	        | j
                  |      }|j                         rO|j                  d   }|dk(  r|j                  d   }|j                  d   }|j                  d   }|j                  d	   }	t        j                  j                  |
      \  }
}||
_
        ||
_        ||
_        |	|
_        |
j                          |j                          t        j                   | t#        d             t%        t&        |      S |j                          t        j                  j)                  |
      }|r|j+                          t        j                   | t#        d             t%        t&        |      S t        j,                  | dj/                  |j0                  j3                         D cg c]  \  }}|D ]	  }| d|   c}}}             t%        t&        |      S yc c}}}w )z
    This view is used to  update  question object.
    Args:
        id (int): primarykey of question
        temp_id (int): primarykey of question_template
    Returns:
        it will redirect to  question_template_detailed_view.

    r   r   r   r'  rQ  rR  rS  rT  rU  ra  zQuestion updated successfully.
: N)r   rS   r\   r   r@   r   r   r   rT   r  rR  rS  rT  rU  r   r	   rY  r   r   rV  r]   r   r   joinerrorsitems)r`   temp_idq_idr	  r   r'  rR  rS  rT  rU  r  createdrb  r   rl  r   s                   re   question_updaterq    s    ~~##''4'0GLL8<==? --o>M#,,Z8,,Z8,,Z8,,Z8#2#:#:#H#H ( $I $  $, #+ #+ #+ 		gq)I'JK ?II		#2#:#:#A#Ah#A#W #$++-gq)I'JK ?II NN		 .2[[->->-@ )E6%+ " !'E7++	 ;WEES  Ds   !Hzpms.delete_questionc                    	 t         j                  j                  |      j                         }|j                  j
                  }t        j                  j                  |      j                          |j                          t        j                  | t        d             t        t        |      S # t        $ r" t        j                  | t        d             Y n`t         j                  $ r" t        j                  | t        d             Y n-t         $ r" t        j                  | t        d             Y nw xY wt        t              S )z
    This view is used to  delete  question object.
    Args:
        id (int): primarykey of question
    Returns:
        it will redirect to  question_template_detailed_view.
    r   ra  zQuestion deleted successfully!z7Failed to delete question: Question template is in use.zQuestion not found.r  )rS   r\   r]   r   rW  r   rT   r   r	   r   r   r   rV  r   r   r   r   )r`   r   r	  rn  s       re   question_deleters    s    =##**b*1779&&))&&8&<CCE!$D"EF7AA 
QPQ	
    :w"7 89 =w": ;<=3W==s   B0B3 3(D:1D:'D:9D:zpms.add_questiontemplatec                    t               }| j                  dk(  rt        | j                        }|j                         r*|j	                         }t        t        |j                        S t        j                  | dj                  |j                  j                         D cg c]  \  }}|D ]	  }| d|   c}}}             t        t              S yc c}}}w )z
    This view is used to create a question template object.
    Args:
    Returns:
        It will redirect to question_template_detailed_view.
    r   ri  rj  N)rA   r   r   r   r   r   rV  r   r	   r   rk  rl  rm  question_template_view)r`   r   r   r   rl  r   s         re   question_template_creationrv  	  s      !D~~#GLL1==?yy{H;X[[IINN		 .2[[->->-@ )E6%+ " !'E7++	 233!  s   "Czpms.view_questiontemplatec                 j    t         j                  j                         }t        |d}t	        | d|      S )z
    This view is used to  view  question template  object.
    Returns:
        it will redirect to  question_template_detailed_view.
    )r   question_templatesz6feedback/question_template/question_template_view.html)rU   r\   r   rA   r   r`   rx  rd   s      re   ru  ru  3	  s9     *11557+CUVGI7 rg   c                 `    t         j                  j                         }d|i}t        | d|      S )zH
    This view is used to  view  question template  object in htmx.
    rx  z6feedback/question_template/question_template_list.html)rU   r\   r   r   ry  s      re   question_template_hx_viewr{  B	  s9     *11557#%78GI7 rg   c                    t         j                  j                  |      j                         }|s.t	        j
                  | t        d             t        t              S |j                  j                         j                  d      }g d}t        j                  j                  |      }|D cg c]  }t        |       }}||||t        |d}	t        | d|	      S c c}w )	z
    This view is used to  view question template object.
    Args:
        id (int): primarykey of question template
        temp_id (int): primarykey of question_template
    Returns:
        it will redirect to  question_template_detailed_view.
    r   z Question template does not existr  )r]  r^  r_  zmulti-choicesr`  )question_id__inr   )r  r  rb  rc  r   	form_listre  )rU   r\   r]   r   r	   r   r   r   ru  r	  r   r  rT   r@   r   )
r`   rW  ry   r  r  rc  r  r	  question_form_listrd   s
             re   rV  rV  P	  s     )0077;7GMMOw"D EF.//!**..099%@INN%%,,Y,GG KTTh,9TT.#('G I  Us   0Czpms.change_questiontemplatec                 l   t         j                  j                  |      j                         }t	        |      }d|i}| j
                  dk(  r[t	        | j                  |      }|j                         r/|j                          t        j                  | t        d             ||d<   t        | d|      S )z
    This view is used to  update  question template object.
    Args:
        id (int): primarykey of question template
    Returns:
        it will redirect to  question_template_view.

    r   r   question_update_formr   zQuestion template updatedz8feedback/question_template/question_template_update.html)rU   r\   r]   r   rA   r   r   r   r   r	   rY  r   r   )r`   rW  r  r  rd   r   s         re   question_template_updater  u	  s     )0077;7GMMO/9JK%';<G~~#GLL;LM==?IIKMM'1%@#AB*.&'KW rg   zpms.delete_questiontemplatec                 "   	 t         j                  j                  |      }t        j                  j	                  |      r t        j                  | t        d             n/|j                          t        j                  | t        d             t        d      S # t         j                  $ r, t        j                  | t        d             Y t        d      S t        $ r, t        j                  | t        d             Y t        d      S w xY w)z
    This view is used to  delete  question template object.
    Args:
        id (int): primarykey of question template
    Returns:
        it will redirect to  question_template_view.
    r   rP  z$This template is using in a feedbackz0The question template is deleted successfully !.zquestion template not found.r  zquestion-template-hx-view)rU   r\   r   rL   r]   r	   rY  r   r   r   r   r   r   r   )r`   rW  r  s      re   question_template_deleter  	  s    =,4488K8H""8I"JMM'1%K#LM$$&MN /00	 (( Cw"@ AB /00  =w": ;</00=s   BB 2D'DDzpms.view_periodc                 `    t         j                  j                         }d|i}t        | d|      S )zg
    This view is used to view period objects.
    Returns:
        it will return to period_view.
    periodszperiod/period_view.htmlrR   r\   r   r   r`   r  rd   s      re   period_viewr  	  s4     nn  "G7G '4g>>rg   c                 b    t         j                  j                         }d|i}t        | d|      S )a  
    Renders a view displaying periods used for tracking Key Results' completion time.

    Parameters:
    - request: HttpRequest object.

    Returns:
    Renders the 'period/period_list.html' template with a list of historical periods used for tracking Key Results.
    r  zperiod/period_list.htmlr   r  r  s      re   period_hx_viewr  	  s4     nn  "G7G '4gFFrg   zpms.add_periodc                    dt               i}| j                  dk(  rZt        | j                        }|j                         r0|j	                          t        j                  | t        d             n||d<   t        | d|      S )zk
    This view is used to create period objects.
    Returns:
        it will redirect to period_view.
    r   r   zPeriod creation was Successful zperiod/period_create.html)	r?   r   r   r   r   r	   r   r   r   )r`   rd   r   s      re   period_creater  	  sk     z|$G~~',,'==?IIKWa(I&JK"GFO'6@@rg   zpms.change_periodc                 n   t         j                  j                  |      j                         }t	        |      }d|i}| j
                  dk(  r\t	        | j                  |      }|j                         r0|j                          t        j                  | t        d             n||d<   t        | d|      S )z
    This view is used to update period objects.
    Args:
        id (int): primarykey of period
    Returns:
        it will redirect to period_view.
    r   r   r   r   zPeriod updated  Successfully. zperiod/period_update.html)rR   r\   r]   r   r?   r   r   r   r   r	   r   r   r   )r`   	period_idperiodr   rd   s        re   period_updater  	  s     ^^""i"0668Fv&DtnG~~',,8==?IIKWa(H&IJ"GFO'6@@rg   zpms.delete_periodc                    	 t         j                  j                  |      }|j                          t	        j
                  | t        d             t        d      S # t         j                  $ r, t	        j                  | t        d             Y t        d      S t        $ r, t	        j                  | t        d             Y t        d      S w xY w)z
    This view is used to delete period objects.
    Args:
        id (int): primarykey of period
    Returns:
        it will redirect to period_view.
    r   zPeriod deleted successfully.zPeriod not found.r  zperiod-hx-view)rR   r\   r   r   r	   r   r   r   r   r   r   )r`   r  
obj_periods      re   period_deleter  	  s    =^^''9'5
!$B"CD
 $%%	  8w"5 67 $%%  =w": ;<$%%=s   AA 2C'CCc                 H   | j                   j                  d      dk(  }|rw| j                  dk(  r[t        j                  |       }t
        j                  j                  |      }|j                  }|j                  }t        ||d      S t        ddi      S t        d      S )	zp
    this function is used to detect the period change and
    return the start and end date of that period
    rJ  rK  r   r   r  failed   r:  )rM  r   r   r   loadrR   r\   rj   r  r   r   )r`   rN  r   
period_objrj   r  s         re   period_changer  
  s     oo!!"459IIG>>V#99W%D++t+4J#..J!**Hzx PQQXx011s##rg   c                 <   | j                   }t        j                  j                  |      j	                         }t        j                  j                  |      }t
        j                  j                         j                         }|j                  d      r|j                  d      rzt        j                  j                         j                         }t        j                  j                         j                         }t        j                  j                  d      }nb|r|D cg c]  }|j                   }}t        j                  j                  |      j                         }t        j                  j                  |      j                         }t        j                  j                  |      j                  d      }nt        j                  j                  |      j                         }t        j                  j                  |	      j                         }t        j                  j                  |      j                         }t        j                  j                  |      j                  d      }||||d
}	t        | d|	      S c c}w )zb
    This view is used to view dashboard.
    Returns:
        it will redirect to dashboard.
    r+  )r6  r  r  zAt Riskr:  )employee_id__inr  r8  )count_objectivecount_key_resultcount_feedbackokr_at_riskzdashboard/pms_dashboard.html)rZ   r   r\   r]   r   rM   r   countr  rK   rL   r   rJ   r   )
r`   rZ   ra   
is_managerr  r  r  r  employees_idsrd   s
             re   dashboard_viewr  !
  s:    <<D&&&=CCEH!!((19 ) J !((,,.446}}12t}}8 ,33779??A!))--/557'//66i6H	5?@@@+33::) ; 

%' 	 "))000OUUW'//66) 7 

&	&
" 	 ,33::x:PVVX,44;;/7 < 

%' 	 "))00X0FLLN'//6686LSS T 
 +,("	G '97CC/ As   )Jc                    | j                   j                  d      dk(  }|r| j                  dk(  rt        j                  }dt        d      i}|D ]  }t        j                  j                  |d   d      }t        | |d	
      j                         }|sF|j                  dg       j                  |d          |j                  dg       j                  |        t        |      S yy)zobjective dashboard datarJ  rK  r   message#No records available at the moment.r   F)rk  rY   r  r   r   objective_labelr  objective_valueN)rM  r   r   rK   rF  r   r\   r]   filtersubordinatesr  
setdefaultr   r   )r`   rN  rj  r   rk  r  objectives_counts          re   dashboard_objective_statusr  P
  s     oo!!"459IIG7>>U*,;;1BCD& 		PF*2299ay% : J  2*3O eg    126==fQiH 126==>NO		P D!! +wrg   c                    | j                   j                  d      dk(  }|r| j                  dk(  rt        j                  }dt        d      i}|D ]  }t        j                  j                  |d         }t        | |dd	
      j                         }|sF|j                  dg       j                  |d          |j                  dg       j                  |        t        |      S yy)zkey result dashboard datarJ  rK  r   r  r  r   r:  zpms.view_employeekeyresultr  )r   r   r   key_result_labelr  key_result_valueN)rM  r   r   rJ   rF  r   r\   r]   r  r  r  r   r   )r`   rN  rd  r   r  key_resultskey_results_counts          re   dashboard_key_result_statusr  d
  s     oo!!"459IIG7>>U*-<<1BCD" 
	RA+33::!A$:GK 2$1:	!
 eg  ! 2B7>>qtD 2B7>>?PQ
	R D!! +wrg   c                    | j                   j                  d      dk(  }|r| j                  dk(  rt        j                  }dt        d      i}|D ]  }t        j                  j                  |d         }t        | |d	      j                         }|sE|j                  d
g       j                  |d          |j                  dg       j                  |        t        |      S yy)zfeedback dashboard datarJ  rK  r   r  r  r   r:  r  r  feedback_labelr  feedback_valueN)rM  r   r   rL   rF  r   r\   r]   r  r  r  r   r   )r`   rN  r  r   r  	feedbacksfeedback_counts          re   dashboard_feedback_statusr  y
  s     oo!!"459IIG7>>U*"111BCD  	MA ((//qt/<I/)2Eeg   0"5<<QqTB 0"5<<^L	M D!! +wrg   c                    | j                   }|j                  |      r|S t        j                  j	                  |      j                         }|rW|. |j                  di | d|i |j                  di ||iz  }|S |j	                  |      |j	                  |      z  }|S |j	                  |j                        }|S )zJ
    This method is used to filter out subordinates queryset element.
    r+  *__employee_work_info__reporting_manager_id)5employee_id__employee_work_info__reporting_manager_idr  rN  )rZ   r  r   r\   r]   r   r[   )r`   r   r   r   rZ   r  s         re   r  r  
  s     <<D}}T%%t%<BBDG&x WFGQ35'"234H   FM ' G45H ??t/@/@?Arg   c                    | j                   dk(  r
t               }| j                   dk(  rt        | j                        }|j                         rH|j	                         }t        |j                  |j                  |j                  |j                  d      S |j                  j                         }t        d|i      S t        | ddi      S )z
    This is an ajax method to return json response to create stage related
    to the project in the task-all form fields
    r   r   )r   namerj   r  rl  zokr/create_period.htmlr   r   )r   r?   r   r   r   r   r   period_namerj   r  rl  as_jsonr   )r`   r   r   rl  s       re   create_periodr  
  s     ~~|~~',,'==?yy{H"++$00"*"5"5 ( 1 1	  $$&Xv.//'3fd^LLrg   c                    | j                   d   }t        j                  |      }d}t        d      }| j                  j                  d      dk(  rd}t        d      }|D ]i  }t        j                  j                  |      }||_        |j                          t        j                  | t        d	      j                  ||
             k t        ddi      S )zB
    This method is used to archive/un-archive bulk objectivs
    idsFun-archivedr2  FalseTarchivedr   z{objective} is {message})r   r  r  Success)r   r   r  r   r   r   rK   r\   rY   r   r	   r   formatr   )r`   r  r2  r  rl   objective_objs         re   objective_bulk_archiver  
  s    
 ,,u
C
**S/CIG{{{#w.	J- 	
)11555F )()00' 1 	
		
 I.//rg   c                 h   | j                   d   }t        j                  |      }|D ]  }	 t        j                  j                  |      }|j                  dk(  s|j                  dk(  rJ|j                          t        j                  | t        d      |j                  |j                  dz         n9t        j                  | t        d      |j                  |j                  dz          t!        d
di      S # t        j                  $ r# t        j                  | t        d	             Y 	w xY w)z6
    This method is used to bulk delete objective
    r  r   r  rn  z$%(employee)s's %(objective)s deleted)r   ra   z?You can't delete objective %(objective)s with status %(status)s)r   rk  r   r  r  )r   r   r  rK   r\   r   rk  r   r	   r   r   r   rX   r   r   r   r   )r`   r  rl   r   s       re   objective_bulk_deleter  
  s    ,,u
C
**S/C ?	?)11555FI=0I4D4D4P  "  <=%.%8%8$-$9$9   WX$-$7$79CSCSTU?, I.// !-- 	?NN7A&<$=>	?s   CC;;2D10D1c                    | j                   d   }| j                   d   }t        j                  |      }t        j                  |      }d}t        d      }| j                  j                  d      dk(  rd}t        d      }|D ]i  }t        j                  j                  |	      }||_        |j                          t        j                  | t        d
      j                  ||             k |D ]s  }t        j                  j                  |	      }||_        |j                          t        j                  | t        d
      j                  |j                  |             u t        ddi      S )zB
    This method is used to archive/un-archive bulk feedbacks
    r  announy_idsFr  r2  r  Tr  r   z{feedback} is {message})r  r  r  r  )r   r   r  r   r   r   rL   r\   rY   r   r	   r   r  rE   feedback_subjectr   )r`   r  r  r2  r  r  s         re   feedback_bulk_archiver  
  sX   
 ,,u
C,,}-K
**S/C**[)KIG{{{#w.	J- 
&&**k*:''(//g/V	
	
 # 	
'//33{3C''(//$55w 0 	
		
 I.//rg   c                 P   | j                   d   }t        j                  |      }|D ]  }	 t        j                  j                  |      }|j                  dk(  s|j                  dk(  r?|j                          t        j                  | t        d      d|j                  iz         n9t        j                  | t        d      |j                  |j                  dz          t        d
di      S # t        j                  $ r" t        j                  | t        d	             Y w xY w)z6
    This method is used to bulk delete feedbacks
    r  r   rn  r  r  r  r  r  r  r  r  )r   r   r  rL   r\   r   rk  r   r	   r   r   r  r   r   r   r   )r`   r  r  r  s       re   feedback_bulk_deleter    s    ,,u
C
**S/C >	>''++{+;H(*hoo.N!  GH%x'<'<=>   [ )1(=(="*//	>0 I.// $$ 	>NN7A&;$<=	>s   B6C002D%$D%c                    | j                   j                  d      }| j                   j                  d      }| j                  j                  }t        j
                  j                  |d      }|dk(  r|dk(  r| j                  j                  d      r!t        j
                  j                  d      }nwt        j
                  j                  | j                        t        j
                  j                  | j                  	      z  }n!t        j
                  j                  |d      }|D cg c]  }t        |j                         }}|j                         }||d
}t        |d      S c c}w )z^
    This method is used to return all the id of the employees to select the employee row
    r   	tableNameFrW   r   r  r`  )employee_id__employee_user_idGemployee_id__employee_work_info__reporting_manager_id__employee_user_idemployee_idstotal_count)safe)r   r   rZ   r[   rK   r\   r]   r  r   r   r  r   )	r`   r  tablerZ   r  r   r  r  rd   s	            re   objective_selectr  =  s=   
 ++//&)KKKOOK(E<<$$D!))00T50QIeE>||$$%AB-55<<U<K	-55<<29,, = %--44\c\h\h 5 	 *1188 % 9 I ,55CCK5L5//#K+KHGe,, 6s   /E/c                 \   | j                   j                  d      }| j                   j                  d      }|rt        j                  |      ni }| j                   j                  d      }| j                  j
                  }t        |t        j                  j                               }|dk(  r|dk(  r{| j                  j                  d      r*t        |t        j                  j                               }nat        |t        j                  j                  | j                              }n+t        |t        j                  j                  |            }|j                  }|D cg c]  }t        |j                         }	}|j                         }
|	|
d	}t!        |      S y
c c}w )zM
    This method is used to return all the ids of the filtered employees
    r   r]   r  r   r   r  r  r  r  N)r   r   r   r  rZ   r[   r2   rK   r\   r   r  r]   r   r   r   r  r   )r`   r  filteredfiltersr  rZ   employee_filterfiltered_employeesr   r  r  rd   s               re   objective_select_filterr  ]  sf   
 ++//&)K{{x(H&.djj"BGKKOOK(E<<$$D%g8I8Q8Q8U8U8WXOeE>||$$%AB"1&7&?&?&C&C&E# #2.66==`g`l`l > # ."3";";"B"Bt"B"TO -///ABCFFBB(..0#/LG$$3 ( Cs   *F)c                 \   | j                   dk(  rt        | j                        }| j                  j                  }|j                         r|j                  d      }||_        |j                          |j                  dk(  rs	 t        j                  t        j                  j                  d      j                         |j                  j                   ddd	d
dt#        d      d	       t%        d      S t%        d      S t               }|dd}t'        | d|      S #  Y t%        d      S xY w)a  
    View function for adding anonymous feedback.

    Parameters:
    - request: HttpRequest object.

    Returns:
    - If request method is POST and form is valid:
        Saves the submitted feedback and sends a notification if based on an employee.
        Returns a JavaScript snippet to reload the page.
    - If request method is GET or form is invalid:
        Renders the 'anonymous/anonymous_feedback_form.html' template with the feedback form.
    r   Fr   ra   zHorilla Bot)usernamez#You received an anonymous feedback!u0   لقد تلقيت تقييمًا مجهولًا!z%Sie haben anonymes Feedback erhalten!u&   ¡Has recibido un comentario anónimo!u$   Vous avez reçu un feedback anonyme!zfeedback-viewz	bag-checkr  rU  Tr   r   &anonymous/anonymous_feedback_form.html)r   r5   r   rZ   r   r   r   r  based_onr*   r   r
   r\   r]   r   rX   r   r   r   r   )r`   r   anonymous_idr  rd   s        re   anonymous_feedback_addr    s     ~~$W\\2||==?yyy.H-9H*MMO  J.KK++]+CIIK"*"6"6"G"GB R G H F!(!9(
   LMM< LMM$&t,G'CWMM LMMs   A'D D+c                 `   t         j                  j                  |      }t        | j                  j
                        |j                  k(  s| j                  j                  d      rt        |      }| j                  j
                  }| j                  dk(  r[t        | j                  |      }|j                         r4|j                  d      }||_        |j                          t        d      S |dd}t        | d	|      S t        j                   | t#        d
             t        d      S )a  
    View function for editing anonymous feedback.

    Parameters:
    - request: HttpRequest object.
    - id: ID of the AnonymousFeedback instance to be edited.

    Returns:
    - If request method is POST and form is valid:
        Saves the edited feedback.
        Returns a JavaScript snippet to reload the page.
    - If request method is GET or form is invalid:
        Renders the 'anonymous/anonymous_feedback_form.html' template with the feedback form pre-filled with existing data.
    r   zpms.change_anonymousfeedbackr   r   Fr   rU  r  r  You are don't have permissions.r   )rE   r\   r   r   rZ   r   r  r  r5   r   r   r   r   r   r   r	   rY  r   )r`   rw   r  r   r  rd   s         re   edit_anonymous_feedbackr    s    " !((,,,7H
7<<??x===AVAV&B %h7||>>V#(ID}}99E921=.#$PQQ51gGQQgq!BCDGHHrg   c                 p   t         j                  j                  |      }t        | j                  j
                        |j                  k(  s| j                  j                  d      r|j                  rEd|_        |j                          t        j                  | t        d             t        t              S |j                  sdd|_        |j                          t        j                  | t        d             t        t              S t        j                  | t        d             t        t              S )r-  r   zpms.anonymousfeedbackFr.  Tr/  r  )rE   r\   r   r   rZ   r   r  r  rY   r   r	   rY  r   r   r  r`   rw   r  s      re   archive_anonymous_feedbackr    s     !((,,,7H
7<<??x===AVAVB $HMMOMM'1%J#KL &'' !!#HMMOMM'1%G#HI &'' 	gq!BCD&''rg   zpms.delete_anonymousfeedbackc                 (   	 t         j                  j                  |      }|j                          t	        j
                  | t        d             t        t              S # t        $ r0 t	        j                  | t        d             Y t        t              S t         j                  $ r0 t	        j                  | t        d             Y t        t              S t        $ r0 t	        j                  | t        d             Y t        t              S w xY w)z
    Deletes an anonymous feedback entry.

    Parameters:
    - request: HttpRequest object.
    - id: ID of the AnonymousFeedback instance to be deleted.

    Returns:
    Redirects to the feedback list view after deleting the feedback.
    r   zFeedback deleted successfully!z7Failed to delete feedback: Feedback template is in use.r  r  )rE   r\   r   r   r	   r   r   r   r   r   r   r   r  r  s      re   delete_anonymous_feedbackr    s    =$,,00F0;!$D"EF &''  
QPQ	
 &'' )) :w"7 89
 &''  =w": ;<&''=s   AA   (D1D'DDc                 `    t         j                  j                  |      }t        | dd|i      S )a4  
    Renders a view to display a single anonymous feedback entry.

    Parameters:
    - request: HttpRequest object.
    - id: ID of the AnonymousFeedback instance to be displayed.

    Returns:
    Renders the 'anonymous/single_view.html' template with the details of the specified anonymous feedback.
    r   zanonymous/single_view.htmlr  )rE   r\   r   r   r  s      re   view_single_anonymous_feedbackr    s2     !((,,,7H'7*h9OPPrg   c                 x   t         j                  j                  |      }| j                  j                  |j
                  j                  j                         v s| j                  j                  d      r|j                  }| j                  j                         }|j                         D ci c]  \  }}|t        |      dkD  r|n|d    }}}|j                  d      s||d<   t        |      }| j                  dk(  rt        | j                         }|j#                         r|j%                          |j'                          |j(                  d   }	|j*                  j-                  |	       t/        j0                  | t3        d	             t5        j6                  | j                  j                  |j8                  d
ddddt;        dd|j
                  j<                  i             t?        d      S ||d}
tA        | d|
      S t/        jB                  | t3        d             t?        d      S c c}}w )a  
    This view is for employee keyresult creation , and returns a employee keyresult form.
    Returns:
        GET:
            employee keyresult form
        POST:
            employee keyresult created, and returnes to employee objective details view
    r   r  r  r   rn   r  r   rk   z Key result assigned sucessfully.zYou got an Key Result!.u/   لقد حصلت على نتيجة رئيسية!u(   Du hast ein Schlüsselergebnis erreicht!u$   ¡Has conseguido un Resultado Clave!u#   Vous avez obtenu un Résultat Clé!rv   rw   rx   rz   r   )r   r   okr/key_result/kr_form.htmlr   r  )"rK   r\   r   rZ   r[   rl   r   r   r  rX   r   r   r  r   r6   r   r   r   r   update_objective_progressr   rk   r   r	   r   r   r*   r   r   r   r   r   r   rY  )r`   r=  r   ra   r   r   r  r   emp_key_resultr   rd   s              re   employee_keyresult_creationr  &  s    &--11Z1@M!!]%?%?%H%H%L%L%NN<<  !<= ,,{{! JN
;E3C#e*q.eAh6
 
  784>L01.|D>>V#27<<@N&&(##%779+88I
++//
;   !,N*OPLL--&772MFBA$1 (-*D*D*G*GH $$OPP"*
 g<gNNgq!BCDGHHQ
s   0 H6c                 p   t         j                  j                  |      }|j                  j                  }| j
                  j                         }t        |      dkD  rD|j                         D ci c]  \  }}|t        |      dkD  r|n|d    }}}t        ||      }nt        |      }| j                  dk(  rt        | j                  |      }|j                         r|j                          |j                  j                          t        j                   | t#        d             t%        j&                  | j(                  j*                  |j,                  dd	d
ddt/        dd|j                  j0                  j2                  i             t5        d      S |dd}	t7        | d|	      S c c}}w )a  
    This function is for update employee keyresult, and returns a employee keyresult form.
    Returns:
        GET:
            employee keyresult form
        POST:
            employee keyresult updated, and returnes to employee objective details view
    r   r  r   )r  r   r   r   zKey result Updated sucessfully.zYour Key Result updated.u.   تم تحديث نتيجتك الرئيسية.u*   Ihr Schlüsselergebnis wurde aktualisiert.z%Se ha actualizado su Resultado Clave.u)   Votre Résultat Clé a été mis à jour.rv   rw   rx   rz   r   T)r   r   r  r   )rJ   r\   r   rn   rX   r   r   r   r  r6   r   r   r   r   r  r	   r   r   r*   r   rZ   r[   r   r   rl   r   r   r   )
r`   r   r   ra   r   r   r  r   r  rd   s
             re   employee_keyresult_updater  d  s    &&**e*4F++77H;;D
4y1} JN
;E3C#e*q.eAh6
 
 /|fU.?~~.w||fM""$!((BBDWa(I&JKKK))"33/HD?C -$f&B&B&O&O&R&RS   KLL G '8'JJ?
s   2 F2zpms.delete_employeekeyresultc                    t         j                  j                  |      }|j                  j                  }|j                  }|j                          |j                          t        j                  | t        d             | j                  j                  d      rt        d      S t        d|j                         S )
    This function is used to delete the employee key result
        args:
            kr_id(int) : pimarykey of EmployeeKeyResult
        return:
            redirect to detailed of employee objective
    r   r  	dashboardz/pms/dashboard-viewz/pms/objective-detailed-view/)rJ   r\   r   rn   rl   r   r  r	   r   r   r   r   r   )r`   r   r   r   r   s        re   delete_employee_keyresultr     s     &&**e*4F,,99I00M
MMO++-Wa BCD{{{#-//3ILL>BCCrg   c                    t         j                  j                  |      }| j                  j                  d      }||_        |j                          t        j                  | t        d      j                  |             t        d|j                  j                   d|j                  j                  j                         S )r  r   rd  z Key result sattus changed to {}.z/pms/kr-table-view/z?&objective_id=)rJ   r\   r   r   rk  r   r	   r   r   r  r   rn   r   rl   )r`   r   r   rk  s       re    employee_keyresult_update_statusr    s     &&**e*4F\\12FFM
KKMWa BCJJ6RS
f::==>ofNjNjNwNwNzNzM{| rg   c                    	 t        | j                  j                  d            }t        | j                  j                  d            }t        j                  j                  |      }||j
                  k  r>||_        |j                          |j                  j                          t        ddi      S y#  t        ddi      cY S xY w)z?
    This method is used to update keyresult current value
    rq  emp_key_result_idr   rL  sucessr   N)r   r   r   rJ   r\   rp   rq  r   rn   r  r   )r`   rq  	emp_kr_idr   s       re   key_result_current_value_updater    s    

/%gll&6&6&GH!',,"2"23F"GH	"**..).<F///#0F KKM((BBD 233	 0
/VW-..s   B4B8 8C	c                    | j                   j                  d      r| j                   j                  d      nd}t        j                  j	                  |      j                         }|r| j                   j                  d      dk(  rt        d|j                   d      S | j                   j                  d      dk(  rot        j                  j                  | j                   j                  d	      d
      }|t        |j                        z   j                         }t        d| d      S y| j                   j                  d      dk(  rt        d      S | j                   j                  d      dk(  rt        d      S y)zG
    Function to get the data of keyresult and return to the form.
    rk   Nr   zdata-updaterp   z0<input type="number" name="target_value" value="z`" class="oh-input w-100 form-control test test" placeholder="Target Value" id="id_target_value">r  rj   z%Y-%m-%d)daysz*<input type="date" name="end_date" value="zN" class="oh-input w-100 form-control" placeholder="End Date" id="id_end_date">z<input type="number" name="target_value" value="" class="oh-input w-100 form-control test test" placeholder="Target Value" id="id_target_value">zx<input type="date" name="end_date" value="" class="oh-input w-100 form-control" placeholder="End Date" id="id_end_date">)r   r   rM   r\   r]   r   r   rp   r  strptimer   durationrJ  )r`   key_idr   rj   r  s        re   get_keyresult_datar    sm    -4KKOOO,L(RV  ""))V)4::<J;;??=)^;B:CZCZB[  \|  }  ;;??=)Z7!**33-zJ #]
8K8K%LLRRTH<XJ  GU  V  8 ;;??=)^; c  ;;??=)Z7 K  8rg   c                    | j                   j                         }t        j                  j	                  d      }| j
                  j                  d      sL| j
                  j                  }|j	                  t        |      t        |      z        j                         }|j                  d      }t               }t        || j                   j                  d            }t        j                  |j                   D cg c]  }|j"                   c}      }t%        |      }t'        t        |       t        j                  j	                         }|||j(                  |d}	t+        | d	|	      S c c}w )
zo
    This view is used to view the meeting ,
    Returns:
        it will redirect to view_meetings.html .
    Tr2  pms.view_meetingsr  r  r  r   )all_meetingsmeetingsfilter_formrequests_idszmeetings/view_meetings.html)r   r   rO   r\   r]   rZ   r  r[   r   r^   r  r1   r   r   r   r   r   r   r   r   r   r   )
r`   r  r  rX   r  r   r  r   r  rd   s
             re   view_meetingsr    s,    KK))+M&&&6H<<  !45ll//??+&;)??

(* 	   'H "KXw{{v'>?H::8;O;OPxx{{PQL'Ih	*##**,L %"''$	G '8'BB Qs   ?E0c                 8   t        t        | j                  j                  d                  }d}| j                  j
                  dd}|r@t        |t              r0t        j                  j                  |      j                         }i }t        ||      }| j                  dk(  rt        | j                  |      }|j                         rk|j!                         }|j"                  d   D cg c]  }|j$                   }}|j"                  d	   D cg c]  }|j$                   }}|j"                  d
   }	|	j'                  |j"                  d	         D 
cg c]  }
|
j$                   }	}
	 t)        j*                  | j                  j
                  |d|j,                   d|j,                   d|j,                   dd|j,                   d|j,                   dt/        d      d|j,                   z   	       	 t)        j*                  | j                  j
                  |	d|j,                   d|j,                   dd|j,                   dd|j,                   d|j,                   dt/        d      d|j,                   z   	       	 t)        j*                  | j                  j
                  |d|j,                   d|j,                   d|j,                   d d!|j,                   d"|j,                   dt/        d      d|j,                   z   	       t3        j4                  | t7        d#             t9        | d$d%|i      S c c}w c c}w c c}
w # t0        $ r}Y d}~id}~ww xY w# t0        $ r
}Y d}~d}~ww xY w# t0        $ r
}Y d}~xd}~ww xY w)&z
    This view is used to create the meeting ,
    Returns:
        Get:
            it renders form.html to create the meeting.
        Post:
            it will redirect to view_meetings.html .
    instance_idN)r  rX   r   )r   r  r   r   r  answer_employeesrX   r4  z>You have been added as an answerable employee for the meeting uG   لقد تمت إضافتك كموظف مسؤول عن الاجتماع u2   Du wurden als Mitarbeiter zum Ausfüllen für das u   -Meeting hinzugefügtu;   Se le ha agregado como empleado responsable de la reunión uJ   Vous avez été ajouté en tant que employé responsable pour la réunion informationzview-meetingsz?search=)r{   r|   r}   r~   r   r   r  r   z#You have been added to the meeting u/   لقد تمت إضافتك إلى اجتماع r  zSie wurden zur u    Besprechung hinzugefügtu   Te han agregado a la reunión u'   Vous avez été ajouté à la réunion z1You have been added as a manager for the meeting u7   لقد تمت إضافتك كمدير للاجتماع u(   Sie wurden als Manager für das Meeting u    hinzugefügtu4   Se le ha agregado como administrador de la reunión u<   Vous avez été ajouté en tant que responsable de réunion zMeeting added successfullyzmeetings/form.htmlr   )r   r   r   r   rZ   r[   
isinstancerw  rO   r\   r]   r   r<   r   r   r   r   r   r   r?  r*   r   titler   rA  r	   r   r   r   )r`   r  r   r  r   r  r   
answer_empr  r  ra   r   s               re   create_meetingsr    s     GKKOOM$B CDKH!,,33DIGz+s3##**k*:@@B7;D~~GLL8<==?yy{H8<8I8I)8T-4((H 
 #'"3"34F"G  ++    ))-8I !* 1 1,,-?@ !2 ! ))I LL--.YZbZhZhYijefnftfteuvPQYQ_Q_P``uvYZbZhZhYijhiqiwiwhxy&$_5(8>>BR8SS
LL--'>x~~>NOMhnnM]]^_-hnn-==VW<X^^<LMEhnnEUV&$_5(8>>BR8SS
LL--&LX^^L\]UV^VdVdUefFx~~FVVcdRS[SaSaRbcZ[c[i[iZjk&$_5(8>>BR8SS
 Wa(D&EFD	
 { 
&      sK   1M
MM2BM  BM0 BN 	M-(M-0	N>N	NN)Fzpms.change_meetingsc                     t        j                  |      }|j                   |_        |j                          |j                  rt	        d      n
t	        d      }t        j                  | |       t        d      S )z
    This view is used to archive and unarchive the meeting ,
    Args:
        meet_id(int) : primarykey of the meeting.
        employee_id(int) : primarykey of the employee
    Returns:
        it will redirect to view_meetings.html .
    zMeeting unarchived successfullyzMeeting archived successfullyr   )rO   findr2  r   r   r	   r   r   )r`   rw   meetingr  s       re   archive_meetingsr#  s  sm     mmF#G#---GLLN  	

+,./ 
 Wg&rg   c                    t         j                  j                  |      j                         }|j                  j                  |       |j                          t        j                  | t        d             t        d      S )z
    This view is used to remove the manager from the meeting ,
    Args:
        meet_id(int) : primarykey of the meeting.
        employee_id(int) : primarykey of the employee
    Returns:
        it will redirect to view_meetings.html .
    r   z7Manager has been successfully removed from the meeting.r   )rO   r\   r]   r   r  r   r   r	   r   r   r   )r`   meet_idr   r"  s       re   meeting_manager_remover&    sg     %%%1779GOO:&LLNLM rg   c                    t         j                  j                  |      j                         }|j                  j                  |       |j                          t        j                  | t        d             t        d      S )z
    This view is used to remove the employees from the meeting ,
    Args:
        meet_id(int) : primarykey of the meeting.
        employee_id(int) : primarykey of the employee
    Returns:
        it will redirect to view_meetings.html .
    r   z8Employee has been successfully removed from the meeting.r   )rO   r\   r]   r   rX   r   r   r	   r   r   r   )r`   r%  rX   r"  s       re   meeting_employee_remover(    si     %%%1779G{+LLNMN rg   c           	      0   | j                   j                         }t        | j                         j                  }| j                  j                  d      sL| j                  j                  }|j                  t        |      t        |      z        j                         }| j                   j                  d      | j                   j                  d      dk(  r|j                  d      }|j                  d      }t        | |d	      }t        || j                   j                  d
            }t        j                  |j                   D cg c]  }|j"                   c}      }t%        |      }t'        t(        |       t+        | d||||d      S c c}w )zn
    This view is used to filter the meeting ,
    Returns:
        it will render to meeting_list.html .
    r  r  r  r2  unknownTr  r  r   r   zmeetings/meetings_list.html)r  r   r   r  )r   r   r1   r   rZ   r  r[   r]   r   r^   r   r  r   r   r   r   r   r   r   r   rK   r   )r`   r  
filter_objrX   r   r  r   s          re   filter_meetingsr,    sN    KK))+M,//J<<  !45ll//&&+&;)??

(* 	 	$,;;??;'94&&&6
$$U+JX6Jz7;;??6+BCJ:::;Q;QRxx{{RSL'I'3%"$(		
	 	 Ss   Fc                 
   t        j                  |      }| j                  dk(  rQ| j                  j	                  d      }||_        |j                          t        j                  | t        d             t        | dd|i      S )z
    This view is used to add the MoM to the meeting ,
    Args:
        id(int) : primarykey of the meeting.
    Returns:
        it will redirect to view_meetings.html .
    r   rt  z7Minutes of Meeting (MoM) have been created successfullyzmeetings/mom_form.htmlr"  )rO   r!  r   r   r   rt  r   r	   r   r   r   )r`   rw   r"  rt  s       re   add_responser.    ss     mmF#G~~<<##J/#QPQ	
 '3i5IJJrg   T)
answerablec                 <   | j                   j                  }| j                  j                  d      x}r.t        j
                  j                  |      j                         }t        j
                  j                  |      }t        j
                  j                  ||      }|j                  j                  j                         }t        j
                  j                         }|j                  j                         |j                  j                         z  }	|s| j                  j                  d      r"t!        d|j"                  |j"                        S ||	vr.t%        j&                  | t)        d             t!        t*              S |||d}
t-        | d|
      S )	z
    This view is used to render the Meeting questions ,
    Args:
        id(int) : primarykey of the meeting.
    Returns:
        it will redirect to meeting_answer.html .
    r   r   
meeting_idrX   zmeeting-answer-view)r   r   r  )r  r  r"  zmeetings/meeting_answer.html)rZ   r[   r   r   r   r\   r]   r   rO   rP   r  r	  r   rT   r  rX   r   r   r	   rY  r   r  r   )r`   r   ry   ra   rX   r"  r
  r  r  meeting_employeesrd   s              re   meeting_answer_getr4    sL    ||((Hkkooh//{/##**k*:@@B""b")G##**g8*TF))22668I%%))+G++-0C0C0G0G0II*-'**X[[QQ((gq!@AB&& G '97CCrg   c                 J   | j                   j                  }t        j                  j	                  |      }|j
                  j                  j                         }| j                  dk(  r|D ]x  }| j                  j	                  d|j                         s,| j                  j	                  d|j                         }t        j                  j                  d|i|||       z t        j                  | t        d      d|j                   iz         t#        t$              S y)z
    This view is used to create meeting answer ,
    Args:
        id(int) : primarykey of the meeting.
    Returns:
        it will redirect to view_meeting if the form was success full.
    r   r   r
  )r
  r  r2  rX   zBQuestions for meeting %(meeting)s has been answered successfully!.r"  N)rZ   r[   rO   r\   r   r  r	  r   r   r   r   rP   r  r	   r   r   r  r   r  )r`   r   ra   r"  r  r	  r
  s          re   meeting_answer_postr6    s    ||((H""b")G11::>>@~~) 	H||& 67 ))F8;;-*@A&&44$f- (& (	 5 	 	RS'--()	

 &&  rg   c                    t         j                  j                  |      j                         }t        j                  j                  |      }t        j                  j                  ||      }||d}t        | d|      S )z
    This view is used to view the meeting for employee.
    Args:
        id(int) : primarykey of the meeting.
        emp_id(int) : id of the employee
    Returns:
        it will return meeting answer object to meeting_answer_view.
    r   r1  )r  r"  z!meetings/meeting_answer_view.html)r   r\   r]   r   rO   r   rP   r   )r`   r   r   ry   ra   r"  r  rd   s           re   meeting_answer_viewr8  6  s{     &&&&1779H""b")G$$++wH+UG G '>HHrg   c                     | j                   j                  }t        j                  j	                  |      }t
        j                  j                  ||      }d}|rd}||d}t        | d|      S )z
    This view is used to view the activity sidebar page for employee.
    Args:
        id(int) : primarykey of the meeting.
    Returns:
        it will return meeting answer object to meeting_question_template_view.
    r   r1  FT)is_answeredr"  z,meetings/meeting_question_template_view.html)rZ   r[   rO   r\   r   rP   r]   r   )r`   r%  ra   r"  r
  r:  rd   s          re   meeting_question_template_viewr;  M  ss     ||((H""g".G##**g8*TFK"G 'I7SSrg   c                     t         j                  j                  |      j                         }d|i}| j                  j                  d      }|r3t        j                  |      }t        ||      \  }}||d<   ||d<   ||d<   t        | d|      S )Nr   r"  r  previousr#  z!meetings/meeting_single_view.html)
rO   r\   r]   r   r   r   r   r  r   r   )r`   r   r"  rd   requests_ids_jsonr  previous_idnext_ids           re   meeting_single_viewrA  e  s    %%%,224G'"G7zz"34.|R@W"3)
!'>HHrg   r  c                     t         j                  j                  |d      }t        j                  j	                         }||d}t        | d|      S )a  
    This function is used to view performance tab of an employee in employee individual
    & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    emp_id (int): The id of the employee.

    Returns: return performance-tab template

    FrW   )r  r
  ztabs/performance-tab.htmlr   )rL   r\   r]   r  re  r   )r`   r   r  re  rd   s        re   performance_tabrC  s  sR     ##**vu*ML##%E%G '6HHrg   c                    | j                   j                         }| j                   j                  d      }| j                  j                  }t
        j                  j                  t        |d      t        |d      z  t        |d      z        j                         }|j                  |      }t        ||      }t        | d||t        j                  j                         d      S )	Nr   T)r   manager_id__is_active)r  colleague_id__is_active)r  subordinate_id__is_active)feedback_answer__employee_idz(request_and_approve/feedback_answer.html)r  r   r
  )r   r   r   rZ   r[   rL   r\   r]   r   r^   r?  r   r   r  rJ  re  )r`   r  r  ra   r  r  s         re   dashboard_feedback_answerrI    s    KK))+M++//&)K||((H!))00	XT:
4
@	A
8t
D	E hj	 
 #***QIi5I2"$MM//1	
 rg   zpms.delete_bonuspointsettingc                 "   	 t         j                  j                  |      j                          t	        j
                  | d       t        t        d            S # t        $ r+}t        |       t	        j                  | d       Y d}~Cd}~ww xY w)z$
    Delete bonus point setting
    r   zBonus Point Setting deletedSomething went wrongNzbonus-point-setting-list-view)rG   r\   r   r   r	   r   rA  loggerr   r   r   )r`   pkrG  s      re   delete_bonus_point_settingrN    sv    8!!%%%,335"?@ G;<==  8q	w 6778s   AA 	B#!B		Bzpms.delete_employeebonuspointc                 P   	 t         j                  j                  |      }|j                          t	        j
                  | t        | d             t        t        d            S # t        $ r4}t        |       t	        j                  | t        d             Y d}~Ld}~ww xY w)z 
    Automation delete view
    r   z deletedrK  Nzemployee-bonus-point-list-view)rI   r\   r   r   r	   r   r   rA  rL  r   r   r   )r`   rM  bonusrG  s       re   delete_employee_bonus_pointrQ    s    ;"**..".5!ugX$6"78 G<=>>  ;q	w"8 9::;s   AA( (	B%1*B  B%c                     | j                   d   }	 | j                   d   }t        |      \  }} G fddt        j                        }t	         |       d      }t        |||d      S )Nmodelc                   *    e Zd ZdZ G  fdd      Zy)3bonus_setting_form_values.<locals>.InstantModelFormz"
        InstantModelForm
        c                       e Zd ZW  ZdZy)8bonus_setting_form_values.<locals>.InstantModelForm.Meta__all__N)__name__
__module____qualname__rS  r  model_classs   re   MetarW    s    EFrg   r^  N)rY  rZ  r[  __doc__r^  r\  s   re   InstantModelFormrU    s    		 	rg   r`  automation_multiple_)choicesmail_details_choiceserialized_form)r   r(   r   	ModelFormr)   r   )r`   rS  
model_path	to_fieldsrc  r`  rd  r]  s          @re   bonus_setting_form_valuesrh    sv    KK E W%J2B:2N/I"K5??  %%5%79OPO #6.	
 rg   zpms.update_bonuspointsettingc                 R   | j                   j                  d      }t        j                  j                  |      }|dk(  r'd|_        t        j                  | t        d             n&d|_        t        j                  | t        d             |j                          t        d      S )	z
    htmx function to update is active field in BonusPointSetting.
    Args:
    - is_active: Boolean value representing the state of BonusPointSetting,
    - obj_id: Id of BonusPointSetting object.
    r2  r   onTz+Bonus point setting activated successfully.Fz-Bonus point setting deactivated successfully.r  )
r   r   rG   r\   r2  r	   r   r   r   r   )r`   rw   r2  bonus_point_settings       re   "update_isactive_bonuspoint_settingrl    s       -I+337767BD(,%!$Q"RS(-%!$S"TUNOOrg   )N)NN)r_  r  r   logging	itertoolsr   urllib.parser   r   r   dateutil.relativedeltar   djangor   django.contribr	   django.contrib.auth.modelsr
   django.core.paginatorr   django.db.modelsr   r   django.db.utilsr   django.formsr   django.httpr   r   r   django.shortcutsr   r   r   django.template.loaderr   django.urlsr   django.utils.translationr   r   base.methodsr   r   r   r   r   r   employee.modelsr   r    horilla.decoratorsr!   r"   r#   r$   r%   r&   horilla.group_byr'   #horilla_automations.methods.methodsr(   %horilla_automations.methods.serializer)   notifications.signalsr*   pms.filtersr+   r,   r-   r.   r/   r0   r1   r2   r3   	pms.formsr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   pms.methodsrB   rC   rD   
pms.modelsrE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   	getLoggerrY  rL  rf   r   r   r   r   r   r   r   r   r   r   r   r   r_   r  r   r@  rG  r\  r^  ra  rh  rl  ru  rx  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r+  r0  rH  r  rZ  rg  rq  rs  rv  ru  r{  rV  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r#  r&  r(  r,  r.  r4  r6  r8  r;  rA  rC  rI  rN  rQ  rh  rl  rN  rg   re   <module>r     s       6 6 0  # + + . * - H H @ @ 3  6  >  / @ @ (
 
 
     
    ( 
		8	$ . . %P 34K 5 K6 67OC 8  OCf '(C ) C  *+ ,  4 )*' +  'T )*(O +  (OV >>  >>B 67) 8 )6 +, - " +, - " 12 3 *5p .  .&  /d B B< 1J  1Jh :  :( .  .@ .  .: :  :,   < *H  *HZ S S(  &BC? D  ?  34, 5  ,^ I  I8 67G 8 G, 67I 8 I4 3P  3Pl 34U 5 U& 34MO 5 MO` 34$T 5  $TN 67M 8  M<=@ *+G , GN -.*E /  *EZ 5 5p 2C  2Cj ,. ,.^ ($ ($V $ $D .L .Lb ), ),X Q Q: -.#( / #(L P  P< '
 '
T -.( / (& 2; 2;j G G( *+*A , *AZ  B -.3F / 3Fl -.> / >> 234 4 46 34
 5 
 34 5   34  5  F 56 7  0 561 7 10 )*? + ? )*G  + G" ()A  * A" +,A - A, +,& - && $ $" +D +D\ " "& " "( " "". M M2 0 00 670 8 0>  0  0F -.0 / 0B - -> $% $%N *N  *NZ !I  !IH ( (4 34( 5 (< Q  Q 9I  9Ix 34-K 5  -K` 67D 8 D*  $ / /"  @ C C> W  Wt  *+ , * *+ , $  $ %  %P 01K 2 K& 0TBD C  DD 0TB' C '> 0TBI C I* 0TBT C  T* 
I 
I $h/I 0  I,  , 34
> 5 
> 45? 6 ?  8 34P 5 Prg   