
    si6                    d   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/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZP ddlQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_ ddl`maZambZbmcZcmdZd ddlemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZv  ej                  ex      Zye:d        Zzd Z{e: e>d !      d"               Z|e:e9 e;d#!      d$                      Z}e: e>d%      d&               Z~e:e9d'               Ze:e9 e>d(      d)                      Ze:e9 e>d*      dd+                     Ze:e9d,               Ze: e;d-!      d.               Ze: e>d/      d0               Ze: e>d1      d2               Ze: e;d-      d3               Zd4 Ze:e9d5               Ze:d6        Zd7 Ze:d8        Ze:e9d9               Ze:e9d:               Ze:e9d;               Ze:e9d<               Ze:e9d=               Ze:e9d>               Ze:e9d?               Ze:d@        Ze:e9 eddA!      dB                      Ze:e9 e;d !      dC                      Ze:dD        Ze:e9dE               Ze: e;d-!      dF               Ze: e;d-!      dG               Ze:e9dH               Ze: e;dI!      dJ               Ze: e;dI!      dK               Ze:e9 e;dI!      dL                      Ze:e9 e;dM!      dN                      ZdO Ze: e;dP!      dQ               Ze:e9 e>dR!      dS                      Ze:dT        Ze:e9dU               Ze:dV        Ze:dW        Ze:dX        Ze:dY        Ze:dZ        Ze:d[        Ze: e>d\!      d]               Ze:e9d^               Ze:d_        Ze: e;d\!      d`               Ze:da        Ze:db        Ze: e;dc!      dd               Ze:de        Ze: e;df!      dg               Ze: e;dh!      di               Ze: e;dj!      dk               Ze: e;dl!      dm               Ze:e9 e;dl!      dn                      Ze: e;dl!      do               Ze:e9 e;dp!      dq                      Ze: e;dr!      ds               Ze: e;dt!      du               Ze: e;dt!      e9dv                      Ze: e;dw!      e9dx                      Ze: e;dy!      dz               Ze: e;d{!      d|               Ze:d}        Ze:d~        Ze:d        Ze:d        Ze:d        ZddZe:d        Ze:d        Ze: e;d-!      d               Ze:d        Ze: e;d\!      d               Ze:d        Ze:d        Ze:e9d               Ze:e9d               Ze:d        Ze: e>d      d               Ze:e9d               Ze:e9d               Ze:e9 e;dI!      d                      Ze: e;d!      d               Ze:d        Ze:d        Ze:d        Ze:d        Ze:e9d               ZddlmZ e: e>d      d               Ze: e>d      d               Ze:d        Ze:e9d               Ze: e<d      d               Ze:e9 e<dd      d                      Ze: e<dd      d               Ze: e<dd      d               Ze:e9 e<dd      d                      Ze:d        Ze:e9 e=de6      d                      Ze:d        Ze: e>d      d               Ze: e>d      d               Ze:d        Ze: 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filtersubordinatesemployeemodelget_key_instancesget_paginationis_reportingmanagerpaginator_qrysortby)Company)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_duplication'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_getrO   objectsfilterdistinctobjective_filter_paginationr   )requestemployeetemplateobjective_owncontexts        -/var/www/python-projects/worksol/pms/views.pyobjective_list_viewrj   m   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_idr\   rn   employee_objective_idro   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_rO   rN   rs   rt   r-   sendr^   r_   employee_user_idr   id)
rd   objective_form	objectiverm   rn   default_krsempemp_objectivekeyemp_krs
             ri   obj_form_saver   ~   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	 rk   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
    )re   ro   POST)<script>window.location.reload()</script>)r   p_formk_formokr/objective_creation.htmlrh   )r^   r_   rA   GETgetmethodr   is_validr   r   rB   r>   r   )rd   re   r   rh   s       ri   objective_creationr      s     ||((H"H5N{{'3&w{{3~~&w||4""$'>2 KLL(,(G
 '8'JJrk   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   instancero   r   rm   rn   r   r\   rp   r\   rp   rn   rr   ro   rq   ru   rv   rw   rx   ry   rz   r{   r|   r~   Objective %(objective)s Updatedr   r   T)r   r   updater   )%rU   r`   r   rA   r   r   r   r   r   r   employee_objectiveexistsallr\   lenrO   ra   deletefirstrn   rN   creaters   rt   r-   r   r^   r_   r   r   r   r	   r   r   r   r>   r   )rd   r{   r   r   r   rm   rn   r   assigneenew_empdelete_listemp_objectivesr   existing_empre   emp_objr   r   rh   s                      ri   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)rQ   r`   r   r.   r   r   r   jsondumpsobject_listr   r   )rd   r   
krs_filterr   r   rh   s         ri   view_key_resultr     s     




!C&w{{3J
W[[__V4
5CjjcooF((++FGGG
 '8'BB Gs   6B#c           	         | 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   rQ   r   )rd   query_stringr   rf   r   allowance_ids	data_dicts          ri   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_resultro   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   )rd   formr   r   r   mutable_getkey_result_idsr   
parsed_urlquery_paramsnew_query_strings              ri   key_result_creater   H  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 rk   zpms.add_keyresultc                 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>   rQ   r`   ra   r   r   r   r   r   r	   r   r   r   r   )rd   kr_idr   krr   r   s         ri   kr_create_or_updater   u  s    8D	BJ&&---7==?
z*~~',,<D}}99;  FG#X./
 $$OPP ',,'D}}99;  FG#X./
 $$OPP'=~NNrk   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commitrm   rn   r   r   r   rr   ro   rs   rt   rn   ru   rv   rw   rx   ry   rz   r{   r|   r~   r   r   r   )r   r   zokr/add_assignees.html) rU   r`   r   r7   r   r   r   r   r   rm   addrO   ra   r   ro   r   rN   r   rs   rt   r-   r   r^   r_   r   r   r   r	   r   r   r   r   )rd   r{   r   r   rm   rn   r   r   r   r   r   rh   s               ri   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==rk   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        d      S # t        j                  $ r, t        j                  | t        d             Y t        d      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.R<script> $('.reload-record').click(); $('#reloadMessagesButton').click();</script>)rU   r`   r   r   r   r   r	   r   r   warningrO   DoesNotExisterrorr   )rd   r{   r   s      ri   objective_deleter     s    ;%%))V)4	++22434Y7OO
 ST	*+ \  )) ;w"8 9:\ ;s   BB   2CCpms.change_objectivec                     t        t        |      }|j                  j                  |       t	        j
                  | t        d             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   zManger removed successfully.r   )r   rU   managersr   r	   r   r   r   )rd   r{   
manager_idr   s       ri   objective_manager_remover     sJ     ")7Ij)Wa >?@\ rk   zpms.delete_keyresultc                     t        t        |      }|j                  j                  |       t	        j
                  | t        d             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   z Key result removed successfully.r   )r   rU   ro   r   r	   r   r   r   )rd   r{   r   r   s       ri   key_result_remover     sJ     ")7I""5)Wa BCD\ rk   c                     t        t        |      }t        t        ||      j                          |j                  j                  |       t        j                  | t        d             t        d      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   zAssignee removed successfully.zP<script>$('.reload-record').click();$('#reloadMessagesButton').click();</script>)
r   rU   rO   r   rm   r   r	   r   r   r   )rd   r{   emp_idr   s       ri   assignees_remover  2  s`     ")7IvFfhv&Wa @ABZ rk   c                    | j                   j                         }ddi}| j                   j                  d      }t        | j                   xs ||      j                  j                  d      }| j                  j                  }d}t        | t        j                  j                  d            }t        j                  j                  |      j                  d	d
      j                         }	t        j                  j                  t!        |      t!        |      z  t!        |	      z        j                         }
| j                  j#                  d      r!t        j                  j%                         }
d}n;t        j                  j                  |      j'                         st)        |       rd}t+        | j                   xs ||
      j                  }
t-        |
t/                     }
t-        |t/                     }| j                   j                  d      }| j                   j                  d      }|j1                  |      }|
j1                  |      }
t2        j2                  j5                         }t7        |      }t9        t        |       |d|
|t+               j:                  |||t<        j>                  |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.
    r]   Ffieldqueryset-idT	is_activeemployee_id__inrp   flat)r   )rm   id__inzpms.view_objectiver   all_pagetrue)
manager	superuser
objectivesown_objectivesobjective_filer_formpgcurrent_dater   	gp_fieldsr  ) r   r   r   r5   r   order_byr^   r_   r   r"   r`   ra   rO   values_listrb   rU   r   has_permr   r   r   r/   r   r   get_pagedatetimenowr   r   r   r6   fields)rd   rg   previous_datainitial_datar  objective_filter_ownre   r  sub_employeessub_obj_idsr  objective_paginator_ownown_pager  objectives_ownr  r   rh   s                     ri   rc   rc   K  sP    KK))+Mu%LKKOOG$E*#|mb%  ||((HG3!!((4(8M
 	!!(((G	^$	/	  ""))	8q844q7LLhj  ||12&&**,
				!	!8	!	4	;	;	=ATB &#|jb  :~'78J'(<n>NO{{v&H{{z*H,55h?N$$X.J





!C'I'3 ( 5 7 < < %,,G Nrk   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.
    search r\   zokr/okr_list.htmlr  okr/group_by.html)	r   r   r^   r_   rO   r`   ra   rc   r   )rd   
search_valre   rg   rh   rf   s         ri   objective_list_searchr/    s     *J
||((H%--444JM)'=AG"H{{w2%'++//'*B*N&'8W--rk   c                 ^    t        | j                        j                  }t        | dd|i      S )r)  z3okr/emp_objective/emp_objective_dashboard_view.htmlr   )r1   r   r   r   )rd   r   s     ri   objective_dashboard_viewr1    s3     -W[[9<<N=	>* rk   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      ri   pair_historyz'objective_history.<locals>.pair_history  s$    8}1Q1ayrk   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`   ra   r   ro   r   )r   key_result_iteratorrecord_pair
old_recordrD  r=  history_user_idhistory_change_datere   changed_key_resultsr9  s            ri   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%		rk   r   rr   )rO   r`   r   rN   ra   r   )
emp_obj_idrL  obj_objectiveall_key_resultsr   rK  r9  s        @@ri   objective_historyrQ    s{     * &--11Z1@M'//66+ 7 O & '
:&' !rk   c           
         t         j                  j                  |      }t        j                  j	                  |d      }| j
                  j                  |j                  j                         v sy| j
                  j                  d      s^|j	                  | j
                  j                        j                         s*t        j                  | t        d             t        d      S | j                  j!                         }t#        |      }t$        j$                  j'                         }||||t(        t*        j,                  t.        |t1               d	}t3        | 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)rp   r]   pms.view_employeeobjectiver,  You dont have permission.zobjective-list-view)	r   r   r   r   key_result_formobjective_key_result_statuscomment_formr  emp_obj_formzokr/okr_detailed_view.html)rU   r`   r   rO   ra   r^   r_   r   r   r  r   r	   infor   r   r   r   r   r  r  r=   rN   STATUS_CHOICESr@   r1   r   )	rd   r{   r}   r   r   r   r   r  rh   s	            ri   objective_detailed_viewr[    s$    !!%%%0I&..55 6 N 	!!Y%7%7%;%;%==<<  !=>  W\\-F-F GNNPgq!<=>-..KK))+M'I





!C( ('8'G'G,/1
G '7AArk   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_commentrM  pairr   datecomment)typer_  r^  r   r?  )r`  r   r^  c                     | d   S )Nr^   )xs    ri   <lambda>z2objective_detailed_view_activity.<locals>.<lambda>5  s
    AfI rk   T)r   r   )r   historyscommentsactivity_listz)okr/objective_detailed_view_activity.htmlrT  *<script>window.location.reload();</script>)rO   r`   r   r^   r_   r\   rp   r   r   r  rQ  trackingrL   ra   r;  r   
created_atsortedr   r	   rY  r   r   )rd   r   r   rL  rA  rf  rg  histcomr_  r   r   rh   s                ri    objective_detailed_view_activityrn    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Irk   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   rO   r`   r   r   r^   r_   r\   rr   r   rn  )rd   r   rW  r   r   s        ri   objective_detailed_view_commentrp  C  s     (5L%--11R18	   ."<<44%."		8"==4b99rk   c                    t         j                  j                  |      }|j                  j	                         }| j
                  j                  d      }|d}t        | j
                  |      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+  r]   r  Fr]   r   )r   r   r  r   z)okr/emp_objective/emp_objective_list.htmlr  r-  )rU   r`   r   r   r   r   r1   r   rb   ra   r   r   r   r  r   r   rO   r   )
rd   r{   r   r   r.  r   r   r   rh   rf   s
             ri   emp_objective_searchrs  Y  sB    !!%%%0I11557N*J
,W[[.ILLUUWN;;??9%/'..u.=KK))+M~~/?@N;;??6"D#,,T2N'I'3( 	G ;H{{w2%'++//'*B*N&'8W--rk   c                 &   t         j                  j                  |      }|j                  j	                         }t        | 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   r  krs_page)r   key_result_statusr   r   todayzokr/kr_list.html)rO   r`   r   employee_key_resultr   r3   r   r   rb   r   r   r  r   rN   rZ  r  rw  r^  r   )rd   emp_objective_idr   r   ru  r   rh   rf   s           ri   kr_table_viewrz  {  s     &--115E1FM

+
+
/
/
1C
'++
4
7
7
@
@
BC
C)
*C{{z*H
,,x
 CKK))+M.==&""((*//1G "H'8W--rk   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   )rO   r`   r   r   statusr   r	   rY  r   r   r   rn  )rd   r   r   r}  s       ri   (objective_detailed_view_objective_statusr~    s     "))---4I\\01FINNMM	
23	++
,	-
 4b99rk   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.
    rv  r   ClosedzStatus has been updatedutf-8#<script>location.reload();</script>)r   r   rN   r`   current_valuert   r}  r   r	   rY  r   r   rn  r   contentdecode)rd   r{   r   r}  rx  r  rt   responses           ri   )objective_detailed_view_key_result_statusr    s     \\12F+337757A'55M&33L$%-"%+"MM'16788VDH(+PP rk   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   r  r   z0Current value of %(employee_key_result)s updatedrx  r  r  r  z*Current value is greater than target valuez,Error occurred during current value updationN)r   r   r   rN   r`   rt   rr   r   intr  r   r	   rY  r   r   rn  r}  r   r  r  r   r   )rd   r   r  rx  rt   rp   r  s          ri   %objective_detailed_view_current_valuer    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  rk   c                 v   t         j                  j                  |      }|j                  rAd|_        |j	                          t        j                  | t        d             t        d      S |j                  s6d|_        |j	                          t        j                  | t        d             t        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!.r   )	rU   r`   r   r]   r   r	   rY  r   r   )rd   r   r   s      ri   objective_archiver    s     !!%%%,I!	gq!GHI
 \ 	  	gq!DEF\ rk   rS  c                     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   rV  zokr/emp_obj_single.html)rO   r`   r   rZ  r   )rd   rN  r   rh   s       ri   view_employee_objectiver    sB     &--11Z1@M!'8'G'GG '4g>>rk   c                    | j                   j                         }|j                         D ci c]  \  }}|t        |      dkD  r|n|d    }}}t	        |      }| j
                  dk(  rZt	        | j                        }|j                         r4t        |j                  d         }|j                  d      }|j                  }|j                  j                  |j                         t        |      }	|j                          |	D ]  }
|j                   j                  |
       t"        j$                  j'                  ||
      j)                         rNt"        j$                  j+                  ||
|
j,                  |
j.                  |j0                  	      } t3        j4                  | t7        d
             t9        d      S |t;               dd}t=        | d|      S 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   ro   Fr   r   r   z'Employee objective created successfullyr   Tr   r   r   0okr/emp_objective/emp_objective_create_form.htmlr   )r   r   listsr   r:   r   r   r   r   r   r   rp   rm   r   r\   setro   rN   r`   ra   r   r   rs   rt   rn   r	   r   r   r   r>   r   )rd   r   r   valuer   r   r   r   objset_krsr   r   rh   s                ri   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#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s    G#c                    | j                   j                  d      }t        j                  j	                  |      j                         }|j                  j                         }t        d|i      }|t               dd}t        | d|      S )	Nrp   r   ro   r  Tr  r  r   )r   r   rU   r`   ra   r   ro   r   r:   r>   r   )rd   r{   r   
keyresultsr   rh   s         ri   get_objective_keyresultsr  ]  s|    [[__^,F!!((F(399;I((,,.J&/LMDvxDAGCW rk   c                    t         j                  j                  |      }| j                  j                  |j
                  k(  sU| j                  j                  |j                  j                  j                         v s| j                  j                  d      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   r   Fr   z'Employee objective Updated successfullyr   )r   r   zokr/emp_objective_form.htmlr   zYou don't have permission.)rO   r`   r   r^   r_   r\   rp   r   r   r  r;   r   r   r   r   r	   r   r   r   r>   r   rY  )rd   rN  r   r   r   rh   s         ri   update_employee_objectiver  i  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Hrk   c                    t         j                  j                  |      }|j                  j                  }|j
                  r7d|_        |j                          t        j                  | t        d             nB|j
                  s6d|_        |j                          t        j                  | t        d             | j                  j                  d      rt        d      S 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   Fr  Tr  detail_viewr   HTTP_REFERER/)rO   r`   r   rp   r   r]   r   r	   r   r   r   r   r   META)rd   rN  r   r{   s       ri   archive_employee_objectiver    s     &--11Z1@M''**F %!$J"KL"" $!$G"HI{{}%`
 	
   0 0 EFFrk   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   )rO   r`   r   r   rx  r   r	   r   r   r\   rp   r   rm   r   r   r   r  r   )rd   rN  r   r  re   r   s         ri   delete_employee_objectiver    s     &--11Z1@M++//-0K((//1QOP	
 !,,!..	""8,!$F"GH#GLL$4$4^S$IJJGHHrk   c                 v   | j                   j                  d      }t        j                  j	                  |      j                         }| j                  j                  d      s| j                  j                  d      s| j                  j                  d      s| j                  j                  |j                  j                  j                         v sZ|j                  j                  r#|j                  | j                  j                  k(  s!t        j                  | d       t!        d      S | j                   j                  d      }| j                  j                  d      s| j                  j                  d      s| j                  j                  d      s| j                  j                  |j                  j                  j                         v sc|j                  j                  r#|j                  | j                  j                  k(  s*t        j                  | t#        d	             t!        d      S |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t1        dd|j                  j2                  i             t!        d      S t        j                  | t#        d             t!        d      S )z
    This function is used to change status of the employee objective
        args:
            hx-request
        return:
            a message
    empObjIdr   r   r   pms.change_employeekeyresultYou dont have permission4<script>$('#reloadMessagesButton').click();</script>r}  rT  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é à rz   r{   r|   r~   z4The status of the objective is the same as selected.)r   r   rO   r`   ra   r   r^   r  r_   rp   r   r   self_employee_progress_updater\   r	   rY  r   r   r}  r   r   r-   r   r   r   r   )rd   r   r   r}  s       ri    change_employee_objective_statusr    sE    kkooj)G%--444@FFHM45<<  !?@<<  !?@<<$$(B(B(K(K(O(O(QQ&&DD**gll.G.GG 	g9:RSS[[__X&F45<<  !?@<<  !?@<<$$(B(B(K(K(O(O(QQ&&DD**gll.G.GG 	gq!<=>D NOOA 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, NOO MMQR NOOrk   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   rv  z%okr/key_result/kr_dashboard_view.htmlr   )r3   r   r   r*   r   rN   rZ  r   )rd   r   rh   s      ri   key_result_viewr  	  s`     '++
&
)
)C
17;;??63JFC .==G 'BGTTrk   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rn   end_date)re   r  )rU  rp   objective_typemultiplerp   objective_idsr   rr   r  Fr   Key result createdrU  z'okr/key_result/key_result_creation.htmlzKey results created)r^   r_   rO   r`   ra   r  rn   r  r=   r   loadsr   r   r   r   r   r   r   r  start_valuerr   r	   r   r   r   r[  r\   r   rj   )rd   r{   obj_typere   r   rn   r  r  rU  r  rp   rh   r  rr   form_key_resultr   s                   ri   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Nrk   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  )rU  objecitve_idr   rr   Fr   r  z,okr/key_result/key_result_creation_htmx.htmlr  r  rU  )rO   r`   ra   rn   r  r=   r   r   r   r   r   r  r  rr   r	   r   r   r   r   r  r  )rd   r   objectrn   r  r  rU  rh   r   r!  r  r   r  s                ri   key_result_creation_htmxr  p  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Srk   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   )rU  ro   r   rr   zKey result updatedz%okr/key_result/key_result_update.htmlr  r  rU  )rN   r`   r   r=   r   r   r   rr   r  r   r   r	   rY  r   r   r   r  r  )rd   r   r   rU  rh   r  s         ri   key_result_updater    s     #**..".5J#Z8O"1JMMRG~~'zJ,, 	 78 ##%  "MM'1%9#:;g'NPWXH  ''03XX  *9G%&'BGLLrk   c                    |j                   r_|j                   }t        j                  | j                  j                  |j
                  dddddt        dd|j                  i      d	
	       |j                         }|D ]U  }t        j                  | j                  j                  |j
                  dddddt        dd|j                  i      d	
	       W 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   r|   zchatbox-ellipsesr   r   r   r   r   r   r   iconz,You have been requested to provide feedback!u1   لقد طُلب منك تقديم ملاحظات!z&Sie wurden gebeten, Feedback zu geben!z0Se le ha solicitado que proporcione comentarios.u5   Il vous a été demandé de fournir des commentaires.)	r\   r-   r   r^   r_   r   r   r   requested_employees)rd   feedbackre   all_employeess       ri   send_feedback_notificationsr    s    ''LL%%//.72885tX[[>QR#
	
 002M! 
LL%%//?G<FK5tX[[>QR#
	

rk   zpms.add_feedbackc                    t               }d|j                  d   _        d|i}| j                  dk(  rBt        | j                        }d|j                  d   _        |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-        d
            S ||d<   t/        | d|      S )zr
    This view is used to create feedback object.
    Returns:
        it will return feedback creation html.
    Fr   feedback_formr   subordinate_idemployee_key_results_idr   zFeedback created successfully.)r  feedback-viewzfeedback/feedback_creation.html)r<   r  requiredr   r   r   r   r   rN   r`   ra   r   r   r  r   r  r  r	   r   r   r  r   r   r   )	rd   r   rh   	employeesr   ro   r   r  r   s	            ri   feedback_creationr    sT    >D).DKK&G ~~GLL)-2L!*==?		))*:;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'(CGO455'+GO$'<gFFrk   zpms.change_feedbackc                    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(  rt        | j                  |      }|j                         ry|j                   j#                  d
      }| j                  j#                  d      x}r`|D ][  }	t$        j                  j                  |	      j'                         }
|j)                         }|j*                  j-                  |
       ] |j)                         }|j.                  j1                  |       t3        |j4                  |j4                  j6                  j9                               }||j:                  d<   |j)                         }t        j<                  | t        d             t?        | |       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.htmlr  r  r   r  r  	others_idzFeedback updated successfully!.) rP   r`   r   r<   rJ   ra   r	   r   r   r   r   r  r  r   r   r   r   r   rN   r   r   r  r   r  r  rE   r   r  r   r   rY  r  )rd   r   r  r   feedback_startedrh   r  r  r   ro   r   r  r   other_employeess                 ri   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/t}}66::<O .=Dk*yy{HMM'1%F#GH':g'FPH  ''03XX  (,GO$':GDDrk   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.

    r]   Fr  r   r  )	r  self_feedbackrequested_feedbackanonymous_feedbackall_feedbacksfeedback_filter_formr  r  r   )r   r   r2   r0   r   r   r   r   r  r  rw  r^  r   r   rP   r   )rd   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   rh   s                       ri   filter_pagination_feedbackr  X  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 Nrk   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}       |j                  t
        j                  j                  |	      D cg c]  }|j                   c}       t
        j                  j                  ||t        j                  j                         t        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 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   colleague_idr  r  )pk__inr  start_date__lteend_date__gtepms.view_feedbackFanonymous_feedback_idr]   rr  zfeedback/feedback_list.html)r   r   r"   r`   r^   rP   ra   extendr   r  r^  rw  noner  r   rI   rG   rb   r  r   )rd   r  r\   r  requested_feedback_idsir  r  r  related_anonymous_feedbacksrh   s              ri   feedback_list_searchr    s    {{x(H""&&&EK$$+++DKK ( L M  !!''..+.FG!G !!''..K.HI!I !!''..k.JK!K !!''...EF!F "))00% ( ++-mm))+	 1  ##((*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BQ 	H 	J 	L 	Gs   )L50L:7L?>Mc                 "   | j                   }|j                  }t        j                  j	                  |d      }t        j                  j	                  t        |      t        |      z  t        |      z  t        |      z  t        j                  j                         t        j                  j                               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  Fr[   r  r  r  r  )r  r  r  rr  )r   r]   r  z feedback/feedback_list_view.htmlzfeedback/feedback_empty.html)r^   r_   rP   r`   ra   r   r  r^  rw  rb   r  rI   r   rG   r  r   r   r   )
rd   r^   re   feedback_ownfeedback_requestedfeedback_allr  r  rh   rf   s
             ri   feedback_list_viewr    s    <<D  H##** + L
 "))00	X

"	#
8
$	% h
	  !++-mm))+ 1  hj  }}()''..u.=  ''..(E.R ||$$%89 	!!(("),,//5 	) 	
 &&--e-<  #:("C#**5*9<NNhj  )1<ASG $$&51'8W--rk   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  r\   )yesno)r  r  feedback_statusemployee_staticsrw  z$feedback/feedback_detailed_view.htmlrT  r  r   <script>window.location.href = "
"</script>HTTP_HX_REQUESTdecorator_404.html)rP   r`   r   rF   rJ   ra   r  r   r   rZ  r  rw  r^  r   r	   rY  r   r  keysr   )rd   r   r}   r  is_have_permr  r  r  r  re   r  rh   previous_urlscriptr   s                  ri   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##rk   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  r\   r  )answerskr_feedbacksz+feedback/feedback_detailed_view_answer.htmlrT  r  r  r  r  r  r  )r"   r`   ra   r   rP   rF   rR   rJ   r   r	   rY  r   r  r   r  r   )rd   r   r   re   r  r  r  r  rh   r  r  r   s               ri   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##rk   c                    t         j                  j                  |      }|j                  t        j
                  j                         kD  r3t        j                  | t        d             t        t        d            S |j                  r^|j                  t        j
                  j                         k  r3t        j                  | t        d             t        t        d            S | j                  }t        j                  j                  |      j!                         }t"        j                  j                  ||      }|j$                  }|j&                  j)                         }t*        j                  j)                         }	|j,                  g|j.                  gz   t1        |j2                  j)                               z   t1        |j4                  j)                               z   t1        |j6                  j)                               z   }
||
vr3t        j                  | t        d             t        t        d            S |
D ]1  }t"        j                  j                  ||      j9                         }3 rd	|_        |j=                          |r3t        j                  | t        d
             t        t        d            S ||	|d}t?        | 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   zFeedback not started yetr  zFeedback is due/closedr<  r  You are not allowed to answerr  r  zFeedback already answered)	questionsoptionsr  z$feedback/answer/feedback_answer.html) rP   r`   r   rn   r  r^  rw  r	   rY  r   r   r   r  r^   r"   ra   r   rJ   question_template_idquestionr   rX   r\   r   r   r  r  r  r   r}  r   r   )rd   r   r}   r  r^   re   answerquestion_templater"  r#  feedback_employees
has_answerrh   s                ri   feedback_answer_getr*  Q  sc    ##r#*H X]]0022gq!;<=011 X..1D1D1FFgq!9:;011<<D&&&=CCEH^^""xX"NF 55!**..0I%%))+G			
	 
x$$((*
+	, x&&**,
-	. x!!%%'
(		)  ))gq!@AB011 ' ^^** h + 

&( 	 " gq!<=>011 G 'A7KKrk   c                 "   | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      }|j                  }|j                  j                         }| j                  dk(  r|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        t3        d            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  r\   zOn Trackr   )r&  ro   r  r\   z:Feedback %(review_cycle)s has been answered successfully!.review_cycler  N)r^   r"   r`   ra   r   rP   r   r$  r%  r   r   r   r   rJ   get_or_creater}  r   r  rR   r_   r	   r   r   r-  r   r   )
rd   r   r^   re   r  r'  r"  r%  r&  r   s
             ri   feedback_answer_postr/    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	

 0115  rk   c                    | j                   }t        j                  j                  |      j	                         }t
        j                  j                  |      }t        j                  j                  ||      }t        j                  j                  ||      }|s3t        j                  | t        d             t        t        d            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 yetr  )r  r  key_result_feedbackz)feedback/answer/feedback_answer_view.html)r^   r"   r`   ra   r   rP   r   rJ   rR   r	   rY  r   r   r   r   )	rd   r   r}   r^   re   r  r  r1  rh   s	            ri   feedback_answer_viewr2    s     <<D&&&=CCEH##r#*Hnn##h#OG+33::( ;  gq!?@A011 2G
 'FPPrk   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         nMt        j                  | t        d      |j                  |j
                  dz         t        t        d	            S 	 t        t        d	            S # t         j                  $ r" t        j                  | t        d
             Y Ht         $ r" t        j                  | t        d             Y qw 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  r  Not Started/Feedback %(review_cycle)s deleted successfully!r-  AYou can't delete feedback %(review_cycle)s with status %(status)sr-  r}  r  Feedback not found.Related entries exists)rP   r`   ra   r   rJ   r}  r   r	   r   r   r-  r   r   r   r   r   r   )rd   r   r  answereds       ri   feedback_deleter;    s?   =##**b*1779>>((X(>DDFOOx'-/OOCD!8#8#89: UV#+#8#8HOOTU
 GO455$ GO,--	    :w"7 89 =w": ;<=s   DD 2E='E=<E=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  r4  zFeedback is already startedr  z&Feedback status updated to  %(status)sr}  z1Error occurred during status update to %(status)s)r   r   r   rP   rJ   r`   ra   r	   r   r   r   r}  r   r   rY  )rd   r   r}  r  r&  s        ri   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Ork   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   r`  6zFeedback about keyresult: zfeedback/feedback_overview.htmlfeedback_overviewr   )rP   r`   ra   r   rF   r$  r%  r   feedback_answerfeedback_key_resultr,  r   r\   r&  question_typero   r   )rd   r{   r  r'  r"  feedback_answersr  r@  r%  answer_listr&  kr_feedbacks               ri   get_feedback_overviewrG  !  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	 -(*;<
 	
=xrk   c                 t   t         j                  j                  |      }|j                  r7d|_        |j	                          t        j                  | t        d             nB|j                  s6d|_        |j	                          t        j                  | t        d             t        t        d            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!.r  )
rP   r`   r   r]   r   r	   rY  r   r   r   )rd   r   r  s      ri   feedback_archiverL  L  s     ##r#*H gq!FGHgq!CDEGO,--rk   c                    	 | j                   j                  d      }|r)t        j                  j                  t	        |            nd}t        j                  j                         }|r"|j                  r|j                  j                  nd}| j                   j                  d      dk(  r"t        j                  j                  |      }n$|r!|j                  r| j                   j                  d      dk(  rl|j                         }|j                  g}|r|j                  |j                         t        j                  j                  d|	      j                  |
      }n| j                   j                  d      dk(  r-|rjt        j                  j                  |j                        }n?| j                   j                  d      dk(  r!t        j                  j                  d|      }|D cg c]  }|j                  |f }}d|i}t        d|      }	t        |	      S c c}w #  dg i}t        d|      }	t        |	      cY S xY w)z9
    Get collegues and subordinates for the manager.
    r\   r   Nr   r  r  
colleaguesT)r  !employee_work_info__department_idr  r  subordinates)r  (employee_work_info__reporting_manager_idr  zemployee/employees_select.html)r   r   r"   r`   r  r  employee_work_inforeporting_manager_idrN   ra   get_departmentr   r   excluder   r   )
rd   r\   re   employees_querysetreporting_manager
departmentexclude_idsr  rh   employee_htmls
             ri   get_colleguesr\  b  s   
-+kkoom4@K8##''3{+;'<QU%--224 H77 ''<< 	
 ;;??6"l2!2!:!:!A!A3; "B " H77;;??6*l:!)!8!8!:J#+;;-K(#**+<+?+?@ *2)9)9)@)@"&* *A *g[g1 ' [[__V,	9(-5-=-=-D-D033 .E .* [[__V,>)1)9)9)@)@"&AI *A *& >PPhkk8,P	P	*()I7SM** Q+#()I7SM**s   G4H- 6H(H- (H- -I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   r\   r  r   r  	CompletedzNot-completedr}  zInvalid requesti  r}  N)headersr   r   r   rP   r`   r"   ra   r   rJ   r   r   )rd   is_ajaxr\   r  r  re   r&  r}  s           ri   r  r    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 rk   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,  rg  rh  ri  rj  zQuestion created successfully.z(Error occurred during question creation!N)r   rC   r   rY   r`   r   rP   ra   r   r	   rY  r   r   question_template_detailed_viewr   r   template_idrC  rX   r   r   )
rd   r   r   r'  feedback_ongoingobj_questionrg  rh  ri  rj  s
             ri   question_creationro    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  rk   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)rY   r`   r   r   rW   rC   r%  r   rX   ra   r  r   )rd   r   r'  question_formsetr"  ry  r#  rx  r%  rw  rh   s              ri   question_viewr|    s     )00444;+H<qQ!**..0I	2GGNN )*2299h9O'() /#(G I rk   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   rC  rf  rg  rh  ri  rj  rv  zQuestion updated successfully.
z: N)r   rW   r`   r   rC   r   r   r   rX   r.  rg  rh  ri  rj  r   r	   rY  r   r   rk  ra   r   r   joinerrorsitems)rd   temp_idq_idr%  r   rC  rg  rh  ri  rj  r#  createdrw  r  r  r   s                   ri   question_updater    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           
      8   	 t         j                  j                  |      j                         }|j                  j
                  }t        j                  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 t        $ r, t        j                  | t        d             Y t        d
      S t         $ r?}t        j                  | t        dt#        |                    Y d	}~t        d
      S d	}~ww xY w)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   rv  zQuestion deleted successfully!z!<script>reloadMessage();</script>zQuestion not found.z7Failed to delete question: Question template is in use.zRelated entries exist.zUnexpected error: Nrh  )rW   r`   ra   r   rl  r   rX   r   r	   r   r   r   r   r   r   r   	Exceptionr   )rd   r   r%  r  es        ri   question_deleter  5	  sT   B##**b*1779&&))&&8&<CCE!$D"EF?@@   :w"7 89 DEE  
QPQ	
 DEE  =w": ;< DEE  Bw$6s1vh"? @AADEEBs*   B+B. .2F,'F'FF+FFzpms.add_questiontemplatec                     t               }| j                  dk(  rTt        | j                        }|j                         r/|j	                          t        j                  | t        d             t        | dd|i      S )z
    This view is used to create a question template object.
    Args:
    Returns:
        It will redirect to question_template_detailed_view.
    r   z'Question template created successfully!6feedback/question_template/question_template_form.htmlr   )	rD   r   r   r   r   r	   r   r   r   )rd   r   s     ri   question_template_creationr  W	  sh      !D~~#GLL1==?IIKWa(Q&RS@	 rk   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)rY   r`   r   rD   r   rd   r  rh   s      ri   question_template_viewr  m	  s9     *11557+CUVGI7 rk   c                 `    t         j                  j                         }d|i}t        | d|      S )zH
    This view is used to  view  question template  object in htmx.
    r  z6feedback/question_template/question_template_list.html)rY   r`   r   r   r  s      ri   question_template_hx_viewr  |	  s9     *11557#%78GI7 rk   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  )rr  rs  rt  zmulti-choicesru  )question_id__inr   )r'  r"  rw  rx  r   	form_listrz  )rY   r`   ra   r   r	   r   r   r   r  r%  r   r  rX   rC   r   )
rd   rl  r}   r'  r"  rx  r#  r%  question_form_listrh   s
             ri   rk  rk  	  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   r   r   zQuestion template updatedr  )rY   r`   ra   r   rD   r   r   r   r   r	   r   r   r   )rd   rl  r'  r   rh   s        ri   question_template_updater  	  s     )0077;7GMMO):;DtnG~~#GLL;LM==?IIKWa(C&DEI7 rk   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   re  z$This template is using in a feedbackz0The question template is deleted successfully !.zquestion template not found.r9  zquestion-template-hx-view)rY   r`   r   rP   ra   r	   rY  r   r   r   r   r   r   r   )rd   rl  r'  s      ri   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rV   r`   r   r   rd   r  rh   s      ri   period_viewr  	  s4     nn  "G7G '4g>>rk   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      ri   period_hx_viewr  	  s4     nn  "G7G '4gFFrk   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)	rB   r   r   r   r   r	   r   r   r   )rd   rh   r   s      ri   period_creater  
  sk     z|$G~~',,'==?IIKWa(I&JK"GFO'6@@rk   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)rV   r`   ra   r   rB   r   r   r   r   r	   r   r   r   )rd   	period_idperiodr   rh   s        ri   period_updater  
  s     ^^""i"0668Fv&DtnG~~',,8==?IIKWa(H&IJ"GFO'6@@rk   zpms.delete_periodc                    | j                   j                  d      }	 t        j                  j                  |      }|j	                          t        j                  | t        d             |dk(  rt        d      S t        d      S # t        j                  $ r" t        j                  | t        d             Y Ot        $ r" t        j                  | t        d             Y xw 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.
    HTTP_HX_TARGETr   zPeriod deleted successfully.zPeriod not found.r9  listContainerrh  zperiod-hx-view)r  r   rV   r`   r   r	   r   r   r   r   r   r   r   )rd   r  target
obj_periods       ri   period_deleter  3
  s     \\./F=^^''9'5
!$B"CD
  HII$%%  8w"5 67 =w": ;<=s   AB 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
    r^  r_  r   r   r  failed   ra  )rb  r   r   r   loadrV   r`   rn   r  r   r   )rd   rc  r   
period_objrn   r  s         ri   period_changer  K
  s     oo!!"459IIG>>V#99W%D++t+4J#..J!**Hzx PQQXx011s##rk   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<  )rR  rS  r  zAt Riskra  r	  r,  rN  )count_objectivecount_key_resultcount_feedbackokr_at_riskzdashboard/pms_dashboard.html)r^   r"   r`   ra   r   rQ   r   countr  rO   rP   r   rN   r   )
rd   r^   re   
is_managerr  r  r  r  employees_idsrh   s
             ri   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 datar^  r_  r   message#No records available at the moment.r   F)r}  r]   rS  r  r   objective_labelr  objective_valueN)rb  r   r   rO   rZ  r   r`   ra   filtersubordinatesr  
setdefaultr   r   )rd   rc  r|  r   r}  r  objectives_counts          ri   dashboard_objective_statusr  
  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!! +wrk   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 datar^  r_  r   r  r  r   ra  zpms.view_employeekeyresultr  )r  r   r  key_result_labelr  key_result_valueN)rb  r   r   rN   rZ  r   r`   ra   r  r  r  r   r   )rd   rc  rv  r   r  key_resultskey_results_counts          ri   dashboard_key_result_statusr  
  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!! +wrk   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 datar^  r_  r   r  r  r   ra  r  r  feedback_labelr  feedback_valueN)rb  r   r   rP   rZ  r   r`   ra   r  r  r  r   r   )rd   rc  r  r   r  	feedbacksfeedback_counts          ri   dashboard_feedback_statusr  
  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!! +wrk   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,  rb  )r^   r  r"   r`   ra   r   r_   )rd   r  r   r  r^   r  s         ri   r  r  
  s     <<D}}T%%t%<BBDG&x WFGQ35'"234H   FM ' G45H ??t/@/@?Ark   c           	         | j                   j                  d      }|dk7  r t        j                  j	                  |      nt        j                  j                         }| j                  dk(  rt        d|i      }| j                  dk(  r| j                  j                         }|j                  dt        |j                  dd	
                   t        |      }|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
    selected_companyr   r   r   
company_idr  r   r   Tr  )r   namern   r  r  zokr/create_period.htmlr   r   )sessionr   r!   r`   ra   r   r   rB   r   r   r   r   r  r   r   r   r   period_namern   r  r  as_jsonr   )rd   r  	companiesr   r   r   r  s          ri   create_periodr  
  s7    $$%78J  	*-__  "  ~~<";<~~||  "\4	(=(=d(=(N#OP$==?yy{H"++$00"*"5"5 ( 1 1	  $$&Xv.//'3fd^LLrk   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-archivedr  FalseTarchivedr   z{objective} is {message})r   r  r  Success)r   r   r  r   r   r   rO   r`   r]   r   r	   r   formatr   )rd   r  r  r  rp   objective_objs         ri   objective_bulk_archiver     s    
 ,,u
C
**S/CIG{{{#w.	J- 	
)11555F )()00' 1 	
		
 I.//rk   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   r4  r  z$%(employee)s's %(objective)s deleted)r   re   z?You can't delete objective %(objective)s with status %(status)s)r   r}  r   r  r  )r   r   r  rO   r`   r   r}  r   r	   r   r   r   r\   r   r   r   r   )rd   r  rp   r   s       ri   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  r  r  Tr  r   {feedback} is {message}r  r  r  r  )r   r   r  r   r   r   rP   r`   r]   r   r	   r   r  rI   feedback_subjectr   )rd   r  r  r  r  r  s         ri   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.//rk   c                    | j                   d   }t        j                  |      }| 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          |D ]w  }t        j                  j                  |      }t        d      }|j                          t        j                  | t        d      j!                  |j"                  |             y t%        ddi      S # t        j                  $ r# t        j                  | t        d
             Y zw xY w)z6
    This method is used to bulk delete feedbacks
    r  r  r   r  r4  r5  r-  r6  r7  r8  Deletedr  r  r  r  )r   r   r  rP   r`   r   r}  r   r	   r   r   r-  r   r   r   rI   r  r  r   )rd   r  r  r  r  r  s         ri   feedback_bulk_deleter  _  s    ,,u
C
**S/C,,}-K**[)K >	>''++{+;H(*hoo.N!  GH%x'<'<=>   [ )1(=(="*//	>0 # 

'//33{3CI,'(//$55w 0 	


 I.// $$ 	>NN7A&;$<=	>s   B6F2GG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   	tableNameFr[   r   rS  rr  )employee_id__employee_user_idGemployee_id__employee_work_info__reporting_manager_id__employee_user_idemployee_idstotal_count)safe)r   r   r^   r_   rO   r`   ra   r  r   r   r  r   )	rd   r  tabler^   r  r   r  r  rh   s	            ri   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   ra   r  r  r   rS  r  r,  r  N)r   r   r   r  r^   r_   r5   rO   r`   r   r  ra   r   r   r   r  r   )rd   r  filteredfiltersr  r^   employee_filterfiltered_employeesr   r  r  rh   s               ri   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   re   zWorksol 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!r  z	bag-checkr  rh  Tr   r   &anonymous/anonymous_feedback_form.html)r   r8   r   r^   r   r   r   r   based_onr-   r   r
   r`   ra   r   r\   r   r   r   r   )rd   r   anonymous_idr  rh   s        ri   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   rh  r  r  You are don't have permissions.r   )rI   r`   r   r   r^   r   r   r  r8   r   r   r   r   r   r   r	   rY  r   )rd   r{   r  r   r	  rh   s         ri   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Hrk   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 )rI  r   zpms.anonymousfeedbackFrJ  TrK  r  )rI   r`   r   r   r^   r   r   r  r]   r   r	   rY  r   r   r  rd   r{   r  s      ri   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&''rk   zpms.delete_anonymousfeedbackc                    	 t         j                  j                  |      }|j                          t	        j
                  | t        d             t        t        d            S # t        $ r" t	        j                  | t        d             Y >t         j                  $ r" t	        j                  | t        d             Y qt        $ r" t	        j                  | t        d             Y 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.r8  r9  r  )rI   r`   r   r   r	   r   r   r   r   r   r   r   r   r  s      ri   delete_anonymous_feedbackr  G  s    =$,,00F0;!$D"EF GO,--  
QPQ	
 )) :w"7 89 =w": ;<=s   AA% %(C,1C,'C,+C,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  )rI   r`   r   r   r  s      ri   view_single_anonymous_feedbackr  g  s2     !((,,,7H'7*h9OPPrk   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   rr   r  r   ro   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é!rz   r{   r|   r~   r   )r   r   okr/key_result/kr_form.htmlr   r  )"rO   r`   r   r^   r_   rp   r   r   r  r\   r   r   r  r   r9   r   r   r   r   update_objective_progressr   ro   r   r	   r   r   r-   r   r   r   r   r   r   rY  )rd   rN  r   re   r   r   r  r   emp_key_resultr   rh   s              ri   employee_keyresult_creationr  x  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.rz   r{   r|   r~   r   T)r   r   r  r   )rN   r`   r   rr   r\   r   r   r   r  r9   r   r   r   r   r  r	   r   r   r-   r   r^   r_   r   r   rp   r   r   r   )
rd   r   r   re   r   r   r  r   r  rh   s
             ri   employee_keyresult_updater    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  	dashboardr  z/pms/objective-detailed-view/)rN   r`   r   rr   rp   r   r  r	   r   r   r   r   r   r   )rd   r   r   r   r   s        ri   delete_employee_keyresultr    s     &&**e*4F,,99I00M
MMO++-Wa BCD{{{#RSS3ILL>BCCrk   c                 z   t         j                  j                  |      }| j                  j	                  d      s| j                  j	                  d      s| j                  j	                  d      s| j                  j
                  |j                  j                  j                  j                         v sC|j                  j                  j                  r|j                  | j                  j
                  k(  r| j                  j                  d      }||_        |j                          t        j                   | t#        d      j%                  |             t'        d|j                  j(                   d|j                  j                  j(                         S t        j*                  | d	       t-        d
      S )r  r   r   r   r  rv  z Key result sattus changed to {}.z/pms/kr-table-view/z?&objective_id=r  r   )rN   r`   r   r^   r  r_   rr   rp   r   r   r  r\   r   r}  r   r	   r   r   r  r   r   rY  r   )rd   r   r   r}  s       ri    employee_keyresult_update_statusr!     s\    &&**e*4F45<<  !?@<<  !?@<<$$''44==AACD ((55SS##w||'@'@@ !!"56!$F"G"N"Nv"VW!&">">"A"A!B/RXRnRnR{R{R~R~Q  A
 	
 MM'56CDDrk   c                 L   	 t        | j                  j                  d            }t        | j                  j                  d            }t        j                  j                  |      }| j
                  j                  d      s| j
                  j                  d      s| j
                  j                  d      s| j
                  j                  |j                  j                  j                  j                         v sM|j                  j                  j                  r|j                  j                  | j
                  j                  k(  rTt        d|      }||_        |j!                          |j                  j#                          t%        j&                  | d       nt%        j(                  | d	       t+        d
|j                  j,                  |j,                  |j                  j.                  d      S # t0        $ r"}t3        |       t+        ddi      cY d}~S d}~ww xY w)z?
    This method is used to update keyresult current value
    r  emp_key_result_idr   r   r   r  r   zValue updatedz4You dont have permission to update the current valuesucess)r`  progresskr_progresspkr`  r   N)r   r   r   rN   r`   r^   r  r_   rr   rp   r   r   r  r\   maxr  r   r  r	   r   rY  r   progress_percentager'  r  print)rd   r  	emp_kr_idr   r  s        ri   key_result_current_value_updater,  !  s   
%/%gll&6&6&GH!',,"2"23F"GH	"**..).<LL!!"89||$$%CD||$$%CD||((++88AAEEGH ,,99WW00<<||001
  =1M#0F KKM((BBDWo6MMO  "88LL%992255	
 	
  /aVW-../s   G5G8 8	H#HH#H#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.
    ro   Nr   zdata-updatert   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  rn   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   rQ   r`   ra   r   r   rt   r  strptimer   durationr^  )rd   key_idr   rn   r  s        ri   get_keyresult_datar2  N  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  8rk   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 .
    Tr  pms.view_meetingsr,  r  r  r   )all_meetingsmeetingsfilter_formrequests_idszmeetings/view_meetings.html)r   r   rS   r`   ra   r^   r  r_   r   rb   r  r4   r   r   r   r   r   r   r   r   r   r   )
rd   r   r7  r\   r8  r   r9  r   r6  rh   s
             ri   view_meetingsr:  o  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  r\   r   )r   r  r   r   r  answer_employeesr\   r  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 information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   r^   r_   
isinstancer  rS   r`   ra   r   r?   r   r   r   r   r   r   rV  r-   r   titler   r  r	   r   r   r   )rd   r<  r   r  r   r  r   
answer_empr=  r  re   r   s               ri   create_meetingsrC    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+  )rS   findr  r   r   r	   r   r   )rd   r{   meetingr  s       ri   archive_meetingsrH    sm     mmF#G#---GLLN  	

+,./ 
 Wg&rk   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+  )rS   r`   ra   r   r  r   r   r	   r   r   r   )rd   meet_idr   rG  s       ri   meeting_manager_removerK    sg     %%%1779GOO:&LLNLM rk   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.z3<script>$('#reloadMessagesButton').click()</script>)rS   r`   ra   r   r\   r   r   r	   r   r   r   )rd   rJ  r\   rG  s       ri   meeting_employee_removerM    sj     %%%1779G{+LLNMN MNNrk   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 .
    r4  r,  r5  r  unknownTr  r  r    r   zmeetings/meetings_list.html)r7  r   r   r9  )r   r   r4   r   r^   r  r_   ra   r   rb   r   r  r    r   r   r   r   r   r   r   rO   r   )rd   r   
filter_objr\   r   r9  r   s          ri   filter_meetingsrQ  ,  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   r  z7Minutes of Meeting (MoM) have been created successfullyzmeetings/mom_form.htmlrG  )rS   rF  r   r   r   r  r   r	   r   r   r   )rd   r{   rG  r  s       ri   add_responserS  V  ss     mmF#G~~<<##J/#QPQ	
 '3i5IJJrk   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_idr\   zmeeting-answer-view)r   r   r!  )r"  r#  rG  zmeetings/meeting_answer.html)r^   r_   r   r   r"   r`   ra   r   rS   rT   r'  r%  r   rX   r  r\   r   r   r	   rY  r   r:  r   )rd   r   r}   re   r\   rG  r&  r"  r#  meeting_employeesrh   s              ri   meeting_answer_getrY  k  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Crk   c                 T   | 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%        d            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,  rW  r\   zBQuestions for meeting %(meeting)s has been answered successfully!.rG  r?  N)r^   r_   rS   r`   r   r'  r%  r   r   r   r   rT   r.  r	   r   r   rA  r   r   )rd   r   re   rG  r'  r%  r&  s          ri   meeting_answer_postr[    s    ||((H""b")G11::>>@~~) 	H||& 67 ))F8;;-*@A&&44$f- (& (	 5 	 	RS'--()	

 011  rk   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   rV  )r  rG  z!meetings/meeting_answer_view.html)r"   r`   ra   r   rS   r   rT   r   )rd   r   r   r}   re   rG  r  rh   s           ri   meeting_answer_viewr]    s{     &&&&1779H""b")G$$++wH+UG G '>HHrk   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   rV  FT)is_answeredrG  z,meetings/meeting_question_template_view.html)r^   r_   rS   r`   r   rT   ra   r   )rd   rJ  re   rG  r&  r_  rh   s          ri   meeting_question_template_viewr`    ss     ||((H""g".G##**g8*TFK"G 'I7SSrk   c                     t         j                  j                  |      j                         }d|i}| j                  j                  d      }|r3t        j                  |      }t        ||      \  }}||d<   ||d<   ||d<   t        | d|      S )Nr   rG  r9  previousr4  z!meetings/meeting_single_view.html)
rS   r`   ra   r   r   r   r   r  r   r   )rd   r   rG  rh   requests_ids_jsonr9  previous_idnext_ids           ri   meeting_single_viewrf    s    %%%,224G'"G7zz"34.|R@W"3)
!'>HHrk   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

    Fr[   )r  r  ztabs/performance-tab.htmlr   )rP   r`   ra   r  rw  r   )rd   r'  r  rw  rh   s        ri   performance_tabrh    sR     ##**r5*IL##%E%G '6HHrk   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dashboard/feedback_answer.html)r  r   r  )r   r   r   r^   r_   rP   r`   ra   r   rb   rV  r   r   r  r^  rw  )rd   r   r  re   r	  r  s         ri   dashboard_feedback_answerrn    s    KK))+M++//&)K||((H!))00	XT:
4
@	A
8t
D	E hj	 
 #***QIi5I("$MM//1	
 rk   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)rK   r`   r   r   r	   r   r  loggerr   r   r   )rd   r'  r  s      ri   delete_bonus_point_settingrr    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 deletedrp  Nzemployee-bonus-point-list-view)rM   r`   r   r   r	   r   r   r  rq  r   r   r   )rd   r'  bonusr  s       ri   delete_employee_bonus_pointru  .  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__rw  r  model_classs   ri   Metar{  L  s    EFrk   r  N)r}  r~  r  __doc__r  r  s   ri   InstantModelFormry  G  s    		 	rk   r  automation_multiple_)choicesmail_details_choiceserialized_form)r   r+   r   	ModelFormr,   r   )rd   rw  
model_path	to_fieldsr  r  r  r  s          @ri   bonus_setting_form_valuesr  >  sv    KK E W%J2B:2N/I"K5??  %%5%79OPO #6.	
 rk   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.
    r  r   onTz+Bonus point setting activated successfully.Fz-Bonus point setting deactivated successfully.r  )
r   r   rK   r`   r  r	   r   r   r   r   )rd   r{   r  bonus_point_settings       ri   "update_isactive_bonuspoint_settingr  [  s       -I+337767BD(,%!$Q"RS(-%!$S"TUNOOrk   )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   r   r    base.modelsr!   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/   r0   r1   r2   r3   r4   r5   r6   	pms.formsr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   pms.methodsrE   rF   rG   rH   
pms.modelsrI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   	getLoggerr}  rq  rj   r   r   r   r   r   r   r   r   r   r   r   r  rc   r/  r1  rQ  r[  rn  rp  rs  rz  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/  r2  r;  r=  rG  rL  r\  r  ro  r|  r  r  r  r  r  rk  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,  r2  r:  rC  rD  rH  rK  rM  rQ  rS  rY  r[  r]  r`  rf  rh  rn  rr  ru  r  r  rb  rk   ri   <module>r     s       6 6 0  # + + . * - H H @ @ 3  6	 	 	   =  / @ @ (
 
 
         ( 
		8	$ . . %P 56K 7 K6 67OC 8  OCf )*C + C    4 )*' +  'T ()(O *  (OV >>  >>B 67 8 < +, - ( +, - ( 12 3 .AH .  .&  /d #B #BL 1J  1Jh :  :( .  .@ .  .: :  :,   < *H  *HZ  ,  &BC? D  ?  34, 5  ,^   I  I: 67G 8 G4 67I 8 I4 DP  DPN 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R /0.E 1  .Eb 5 5p 8C  8Cv 0. 0.f ($ ($V $ $D 9L 9Lx )2 )2X Q Q: /0#. 1 #.L P  P< '
 '
T -.. / .( 1+ 1+h G G( *+*A , *AZ  B -.3F / 3Fl -.F / F@ 23 4 ( 34
 5 
 34 5   34  5  F 56 7  . 561 7 10 )*? + ? )*G  + G" ()A  * A" +,A - A, +,& - &, $ $" +D +D\ " "& " "( " "". M MB 0 00 670 8 0> !0 !0H -.+0 / +0\ - -> $% $%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* E E@ )/ )/X  @ C C> W  Wt  *+ , * *+ , $ O O$ %  %P 01K 2 K& 0TBD C  DD 0TB2 C 2> 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rk   