403Webshell
Server IP : 65.108.144.40  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User : dev ( 1000)
PHP Version : 8.2.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/erp/pms/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/erp/pms/__pycache__/views.cpython-310.pyc
o

hͦh9#�@s8
dZddlZddlZddlZddlmZddlmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZmZmZddlm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z)ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:ddl;m<Z<ddl=m>Z>ddl?m@Z@ddlAmBZBddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLddlMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[ddl\m]Z]m^Z^m_Z_ddl`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqe�res�Zte6dd��Zudd �Zve6e7d!d"�d#d$���Zwe6e5e7d%d"�d&d'����Zxe6e7d(�d)d*���Zye6e5e:d+�d,d-����Zze6e5e:d.�d/d0����Z{e6e5e:d.��dd1d2����Z|e6e5d3d4���Z}e6e7d5d"�d6d7���Z~e6e:d8�d9d:���Ze6e:d;�d<d=���Z�e6e7d5�d>d?���Z�d@dA�Z�e6e5dBdC���Z�e6dDdE��Z�dFdG�Z�e6dHdI��Z�e6e5dJdK���Z�e6e5dLdM���Z�e6e5dNdO���Z�e6e5dPdQ���Z�e6e5dRdS���Z�e6e5dTdU���Z�e6e5dVdW���Z�e6dXdY��Z�e6e5e_dZd"�d[d\����Z�e6e5e7d!d"�d]d^����Z�e6e5d_d`���Z�e6e7d5d"�dadb���Z�e6e7d5d"�dcdd���Z�e6e5dedf���Z�e6e7dgd"�dhdi���Z�e6e7dgd"�djdk���Z�e6e5e7dgd"�dldm����Z�e6e5e7dnd"�dodp����Z�dqdr�Z�e6e7dsd"�dtdu���Z�e6e5e7dvd"�dwdx����Z�e6dydz��Z�e6e5d{d|���Z�e6d}d~��Z�e6dd���Z�e6d�d���Z�e6d�d���Z�e6d�d���Z�e6d�d���Z�e6e7d�d"�d�d����Z�e6e5d�d����Z�e6d�d���Z�e6e7d�d"�d�d����Z�e6d�d���Z�e6d�d���Z�e6e7d�d"�d�d����Z�e6d�d���Z�e6e7d�d"�d�d����Z�e6e7d�d"�d�d����Z�e6e7d�d"�d�d����Z�e6e7d�d"�d�d����Z�e6e5e7d�d"�d�d�����Z�e6e7d�d"�d�d����Z�e6e5e7d�d"�d�d�����Z�e6e7d�d"�d�d����Z�e6e7d�d"�d�d����Z�e6e7d�d"�e5d�d�����Z�e6e7d�d"�e5d�d�����Z�e6e7d�d"�d�d����Z�e6e7d�d"�d�d����Z�e6d�d���Z�e6d�d„�Z�e6d�dĄ�Z�e6d�dƄ�Z�e6d�dȄ�Z��dd�dʄZ�e6d�d̄�Z�e6d�d΄�Z�e6e7d5d"�d�dЄ��Z�e6d�d҄�Z�e6e7d�d"�d�dԄ��Z�e6d�dք�Z�e6d�d؄�Z�e6e5d�dڄ��Z�e6e5d�d܄��Z�e6d�dބ�Z�e6e:d߃d�d���Z�e6e5d�d���Z�e6e5d�d���Z�e6e5e7dgd"�d�d����Z�e6e7d�d"�d�d���Z�e6d�d��Z�e6d�d��Z�e6d�d��Z�e6d�d��Z�e6e5d�d���Z�dd�lm�Z�e6e:d��d�d����Z�e6e:d��d�d����Z�e6d�d���Z�e6e5d�d����Z�e6e8d��d��d���Z�e6e5e8d��d�d��d�d����Z�e6e8d��d�d��d�d���Z�e6e8d��d�d��d�d���Z�e6e5e8d��d�d��d	�d
����Z�e6�d�d��Z�e6e5e9�d
e2��d�d����Z�e6�d�d��Z�e6e:�d��d�d���Z�e6e:�d��d�d���Z�e6�d�d��Z�e6e:�d��d�d���Z�dS(zr
views.py

This module contains the view functions for handling HTTP requests and rendering
responses in pms app.
�N)�tee)�parse_qs�	urlencode�urlparse)�
relativedelta)�forms)�messages)�User)�	Paginator)�ProtectedError�Q)�IntegrityError)�modelformset_factory)�HttpResponse�HttpResponseRedirect�JsonResponse)�get_object_or_404�redirect�render)�render_to_string)�reverse)�gettext_lazy)�closest_numbers�
eval_validate�get_key_instances�get_pagination�
paginator_qry�sortby)�Employee�EmployeeWorkInformation)�hx_request_required�login_required�manager_can_enter�meeting_manager_can_enter�owner_can_enter�permission_required)�group_by_queryset)�generate_choices)�serialize_form)�notify)	�ActualKeyResultFilter�ActualObjectiveFilter�AnonymousFeedbackFilter�EmployeeObjectiveFilter�FeedbackFilter�KeyResultFilter�MeetingsFilter�ObjectiveFilter�ObjectiveReGroup)�AddAssigneesForm�AnonymousFeedbackForm�EmployeeKeyResultForm�EmployeeObjectiveCreateForm�EmployeeObjectiveForm�FeedbackForm�
KeyResultForm�KRForm�MeetingsForm�ObjectiveCommentForm�
ObjectiveForm�
PeriodForm�QuestionForm�QuestionTemplateForm)�'check_permission_feedback_detailed_view�get_anonymous_feedbacks�pms_owner_and_manager_can_enter)�AnonymousFeedback�Answer�BonusPointSetting�Comment�EmployeeBonusPoint�EmployeeKeyResult�EmployeeObjective�Feedback�	KeyResult�KeyResultFeedback�Meetings�MeetingsAnswer�	Objective�Period�Question�QuestionOptions�QuestionTemplatecCs:|jj}d}tjj|dd�}|��}t||�}t|||�S)z�
    This view is used to show all the objectives  and returns some objects.
    Returns:
        Objects based on userlevel.
    zokr/okr_view.htmlF��employee_id�archive)�user�employee_getrJ�objects�filter�distinct�objective_filter_paginationr)�request�employee�template�
objective_own�context�rc�/var/www/erp/pms/views.py�objective_list_viewis�
rec

Cs�|��}|jd}|jd}|jd}t�|td��|rY|D];}t|||d�}|��|rA|D]}t|||j|jd�}	|	��q0t	j
|jj|j
ddd	d
dtdd
|jid�d�qdSdS)z2
    This view is used to save objective form
    �	assignees�
start_date�
key_result_idzObjective created)�objective_idrVrg��employee_objective_idrh�
progress_type�target_value�You got an OKR!.�5لقد حققت هدفًا ونتيجة رئيسية!�'Du hast ein Ziel-Key-Ergebnis erreicht!�-¡Has logrado un Resultado Clave de Objetivo!�0Vous avez atteint un Résultat Clé d'Objectif !�objective-detailed-view�obj_id��kwargs��	recipient�verb�verb_ar�verb_de�verb_es�verb_frrN)�save�cleaned_datar�success�_rJrIrlrmr)�sendrXrY�employee_user_idr�id)
r^�objective_form�	objectiverfrg�default_krs�emp�
emp_objective�key�emp_krrcrcrd�
obj_form_savezsD


��

���r�zpms.add_employeeobjective��permcCsx|jj}t|d�}|j�d�durt|j�}|jdkr-t|j�}|��r-t||�t	d�S|t
�t�d�}t|d|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
    )r_rhN�POST�)<script>window.location.reload()</script>)r��p_form�k_form�okr/objective_creation.html�rb)
rXrYr=�GET�get�methodr��is_validr�rr>r:r)r^r_r�rbrcrcrd�objective_creation�s




�r��pms.change_employeeobjectivec
s�tjj|d�}t|d�}|j�d�durt|j�}|jdkr�t|j|d�}|��r�|��}|j	d}|j	d}|j	d}dd	�|D��g}|j
��r_|j
��}	d
d	�|	D�}
�fdd	�|
D�}t
|�dkrt|D]}tjj||d
���qg�D]]}tjj||d
���r�tjj||d
���}||_nt|||d�}|��|r�|D]}
tjj||
d���s�tjj||
|
j|
jd�}|��q�tj|jj|jdddddtdd|jid�d�qvt�|t d�d|i�t!d�S|t"�dd�}t#|d|�S) 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���instancerhNr�rfrgcS�g|]}|�qSrcrc)�.0�assigneercrcrd�
<listcomp>��z$objective_update.<locals>.<listcomp>cS�g|]}|j�qSrc�rV�r�r�rcrcrdr���csg|]}|�vr|�qSrcrc�r�r_��new_emprcrdr��sr�rVri�rVrirg�rkrhrjrnrorprqrrrsrtrurw�Objective %(objective)s Updatedr�r�T)r�r��updater�)$rPrZr�r=r�r�r�r�r~r�employee_objective�exists�all�lenrJr[�delete�firstrgrI�createrlrmr)r�rXrYr�rr�rr�r�rr:r)r^rtr�r�r�rfrgr��delete_list�emp_objectives�existing_empr��emp_objr�r�rbrcr�rd�objective_update�s�








�����������
���r�zpms.view_keyresultcCsTtj��}t|j�}t||j�d��}t�dd�|j	D��}|||d�}t
|d|�S)zR
    This method is used render template to view all the key result instances
    �pagecSr�rcr��r�r�rcrcrdr�r�z#view_key_result.<locals>.<listcomp>)�krs�f�krs_idszokr/key_result/view_kr.html)rLrZr�r*r�rr��json�dumps�object_listr)r^r��
krs_filterr�rbrcrcrd�view_key_results

�r�zpms.view_key_resultcCs�|j��}t|j�j}d}|j�d�dkrd}t||d�}t||j�d��}t�dd�|j	D��}t
|�}tt|�t
||||||d	��S)
z[
    Filter and retrieve a list of key results based on the provided query parameters.
    zokr/key_result/kr_card.html�view�listzokr/key_result/kr_list.htmlrr�cSr�rcr�r�rcrcrdr�5r�z%filter_key_result.<locals>.<listcomp>)r��pd�filter_dictr�)r�rr*�qsr�rrr�r�r�rrrLr)r^�query_stringr�r`�
allowance_ids�	data_dictrcrcrd�filter_key_result's&

��r�zpms.add_key_resultcCst�}|j�d�}|j�d�}|jdkr}t|j�}|��rx|��}t�|t	d�d|i�|j�
�}|�dg�}d|vrA|�d�|�
t|j��|�d|�|��}d|�|��}t|�}t|j�}	|	�dd	�t|	d
d�}
|j�d|
��}n|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_resultrh�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~rr�r��copy�getlist�remove�append�strr��setlistrrr�query�pop�pathr)r^�formr�r�r��mutable_get�key_result_idsr��
parsed_url�query_params�new_query_stringrcrcrd�key_result_createDs@

��




�r�cCs�t�}d}d}|durtjj|d���}t|d�}|jdkr]|r@t|j|d�}|��r?|��}t	�
|td�d|i�td�Snt|j�}|��r]|��}t	�
|td	�d|i�td�St
|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.
    FNr�r�r�z.Key result %(key_result)s updated successfullyr�r�r�z okr/key_result/real_kr_form.htmlr�)r:rLrZr[r�r�r�r�r~rr�r�rr)r^�kr_idr��krr�r�rcrcrd�kr_create_or_updateqs<

���

��r�c
CsJtjj|d�}t|d�}|jdkr�t|j|d�}|��r�|jdd�}|jd}|jd}|D]W}|j	�
|�tjj||d��
�sGt|||d	�}|��|j��}|rn|D]}	tjj||	d
��
�smtjj||	|	j|	j|d�}
qTtj|jj|jdd
dddtdd|jid�d�q.|��t�|td�d|i�td�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��commitrfrgr�r�r��rkrhrlrmrgrnrorprqrrrsrtrurwr�r�r�)r�r�zokr/add_assignees.html) rPrZr�r3r�r�r�r~rrf�addrJr[r�rhr�rIr�rlrmr)r�rXrYr�rr�rr�r�rr)r^rtr�r�rfrgr�r�r�r�r�rbrcrcrd�
add_assignees�sr




���
����
����r�zpms.delete_employeeobjectivecCs�z3tjj|d�}|j��s|��t�|td�d|i�nt�	|td�d|i�Wt
t�SWt
t�St
jyHt�|td��Yt
t�Sw)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�zObjective %(objective)s deletedr�z?You can't delete objective %(objective)s,related entries exists�Objective not found.)rPrZr�r�r�r�rr�r��warningrJ�DoesNotExist�errorrre)r^rtr�rcrcrd�objective_delete�s*

������r�zpms.change_objectivecC� tt|d�}|j�|�td�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��)rrP�managersr�r)r^rt�
manager_idr�rcrcrd�objective_manager_remove��r�zpms.delete_keyresultcCr�)a
    Removes a Key Result from an objective.

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

    Returns:
    HttpResponse indicating success.
    r�r�)rrPrhr�r)r^rtr�r�rcrcrd�key_result_remover�r�cCs0tt|d�}tt||d���|j�|�t�S)a
    Removes an assignee from an objective.

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

    Returns:
    HttpResponse indicating success.
    r�r�)rrPrJr�rfr�r)r^rt�emp_idr�rcrcrd�assignees_remove%s�r�cCs.|j��}ddi}|j�d�}t|jp||d�j�d�}|jj}d}tj	�
t|d�t|d�B���}|j�
d�r@tj	��}d	}ntj	j
|d���rKd	}t|jpP||d�j}t|t��}t|t��}	|j�d
�}
|j�d�}|	�|
�}|�|�}tj��}
t|�}tt|�|d||t�j||
|tj|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.
    rWF�field��queryset�-id)r�)rfzpms.view_objectiveTr��all_page�true)
�manager�	superuser�
objectives�own_objectives�objective_filer_form�pg�current_dater��	gp_fieldsr�)r�rr�r1r��order_byrXrYrPrZr[rr\�has_permr�r�r+r
r�get_page�datetime�nowrrrJr�r2�fields)r^ra�
previous_data�initial_datar��objective_filter_ownr_rr�objective_paginator_own�own_pager�objectives_ownrr�rbrcrcrdr]<sX
	
���

��



�r]cCsl|j�d�}|durd}|jj}tjj|d�}t||�}d}|j�d�dkr0|j�d�dur0d}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.
    �searchNr�r�zokr/okr_list.htmlr��okr/group_by.html)	r�r�rXrYrJrZr[r]r)r^�
search_valr_rarbr`rcrcrd�objective_list_searchts
 rcCst|j�j}t|dd|i�S)rz3okr/emp_objective/emp_objective_dashboard_view.htmlr�)r-r�r�r)r^r�rcrcrd�objective_dashboard_view�s�rcsTdd��g���fdd�}tjj|d�}tjj|d�}|D]}||�q����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.
    cSs t|�\}}t|d�t||�S)z%this function return two history pairN)r�next�zip)�iterable�a�brcrcrd�pair_history�s

z'objective_history.<locals>.pair_historyc	sv|j���d���}�|�D]*}|\}}|�|�}|jj}|jj}tj	j
|d���}|jj}��
||||d��qdS)zkey result history�history_date�r�)�delta�changed_user�changed_date�k_rN)�historyr�r
�iterator�diff_against�
new_record�history_userr"rrZr[r�rhr�)	r��key_result_iterator�record_pair�
old_recordr+r$�history_user_id�history_change_dater_��changed_key_resultsr!rcrd�key_result_history�s"�
���z-objective_history.<locals>.key_result_historyr��rk)rJrZr�rIr[r)�
emp_obj_idr4�
obj_objective�all_key_resultsr�rcr2rd�objective_history�s	�
r9c	
Ksbtjj|d�}tjj|dd�}|j��}t|�}tj�	�}||||t
tjt
|t�d�	}t|d|�S)z�
    this function is used to update the key result of objectives
        args:
            obj_id(int) : pimarykey of EmployeeObjective
        return:
            objects to objective_detailed_view
    r�F)rirW)	r�r�r�r��key_result_form�objective_key_result_status�comment_formr�emp_obj_formzokr/okr_detailed_view.html)rPrZr�rJr[r�rrr
rr9rI�STATUS_CHOICESr<r-r)	r^rtrvr�r�rr�rrbrcrcrd�objective_detailed_view�s$
�

�r?c
Cstjj|d�}|jj|jks|jj|jj��vs|j�	d�r{t
|�}|��}tjj
|d�}g}|D]}|ddj|d<|�|�q1|D]}d||jd�}	|�|	�qD|D]}
d	|
|
d
d�}|�|�qUt|dd
�dd�}||||d�}t|d|�St�|td��td�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�zpms.view_commentr5�pairr�date�comment)�typerBrAr�r&)rCr�rAcSs|dS)NrArc)�xrcrcrd�<lambda>sz2objective_detailed_view_activity.<locals>.<lambda>T)r�r)r��historys�comments�
activity_listz)okr/objective_detailed_view_activity.html�You dont have permission.�*<script>window.location.reload();</script>)rJrZr�rXrYrVrir�r�rr9�trackingrGr[r"r��
created_at�sortedrr�infor�r)
r^r�r�r4r(rGrH�hist�comrBr�r�rbrcrcrd� objective_detailed_view_activity�sB
����rQcCsXt|j�}|��r'tjj|d�}|jdd�}|jj|_	||_
|��tt|�Stt|�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�rJrZr�r~rXrYrVrkrrQ)r^r�r<r�r�rcrcrd�objective_detailed_view_comment s




rRc
Cs�tjj|d�}|j��}|j�d�}|durd}t|j|�j}|j�d�dks-|jdd�}|j�	�}t
|t��}|j�d	�}|�|�}t
|�}tt|�||||d
�}d}	|j�d�dkrg|j�d�durgd
}	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�rNr�rWrF�rWr�)r�r�rr�z)okr/emp_objective/emp_objective_list.htmlr�r)rPrZr�r�r�r�r-r�r[rr
rrrrrJr)
r^rtr�r�rrr�r�rbr`rcrcrd�emp_objective_search6s.



� rTcCsptjj|d�}|j��}t|t��}|j�d�}|�|�}|j�	�}|t
j||tj�
���d�}d}t|||�S)aT
    Renders a table view of Key Results associated with an employee objective.

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

    Returns:
    Renders the 'okr/kr_list.html' template with Key Results associated with the specified EmployeeObjective.
    r��krs_page)r��key_result_statusr�r��todayzokr/kr_list.html)rJrZr��employee_key_resultr�r
rr�rrrIr>r
rWrAr)r^�emp_objective_idr�r�rUrrbr`rcrcrd�
kr_table_viewXs


�rZcCsLtjj|d�}|j�d�}||_|��t�|td�d|j	i�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�)rJrZr�r��statusr~rrNr�r�rrQ)r^r�r�r\rcrcrd�(objective_detailed_view_objective_statusws��
r]cCst|j�d�}tjj|d�}|j}|j}||krd|_n||_|��t�	|t
d��tt|d�}t
|j�d�d�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.
    rVr��ClosedzStatus has been updated�utf-8�#<script>location.reload();</script>)r�r�rIrZ�
current_valuermr\r~rrNr�rrQr�content�decode)r^rtr�r\rXrarm�responsercrcrd�)objective_detailed_view_key_result_status�s
�recCs|jdkr�|j�d�}tjj|d�}|j}|jj}t|�|kr7||_	|�
�t�|t
d�d|i�tt|�St|�|krb||_	d|_|�
�t�|t
d�d|i�tt|�}t|j�d�d�St|�|krut�|t
d	��tt|�St�|t
d
��tt|�SdS)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�rar�z0Current value of %(employee_key_result)s updatedrXr^r_r`z*Current value is greater than target valuez,Error occurred during current value updationN)r�r�r�rIrZrmrkr��intrar~rrNr�rrQr\rrbrcr�r�)r^r�rarXrmrirdrcrcrd�%objective_detailed_view_current_value�sF

��
��
�

�rgcCsltjj|d�}|jrd|_|��t�|td��n|js,d|_|��t�|td��td|j	d���S)z�
    this function is used to archive the objective
        args:
            id(int) : pimarykey of EmployeeObjective
        return:
            redirect to objective_list_view
    r�F�$Objective un-archived successfully!.T�!Objective archived successfully!.z/pms/objective-list-view?�QUERY_STRING)
rPrZr�rWr~rrNr�r�environ)r^r�r�rcrcrd�objective_archive�s	rl�pms.view_employeeobjectivecCs&tjj|d�}|tjd�}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�r;zokr/emp_obj_single.html)rJrZr�r>r)r^r6r�rbrcrcrd�view_employee_objective�s
�rncCs|j��}dd�|��D�}t|d�}|jdkr|t|j�}|��r|t|jd�}|j	dd�}|j
}|j�|j
�|�dd	�|j��D��t|�}|�	�|D] }|j�|�tjj||d
���sotjj|||j|j|jd�}	qOt�|td��td
�S|t�dd�}
t|d|
d�S)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
    cS�*i|]\}}|t|�dkr|n|d�qS��r�r��r�r��valuercrcrd�
<dictcomp>��z-create_employee_objective.<locals>.<dictcomp>��initialr�rhFr�cSr�rcrc)r�r�rcrcrdr� r�z-create_employee_objective.<locals>.<listcomp>r�r�z'Employee objective created successfullyr�T)r�r�r�z0okr/emp_objective/emp_objective_create_form.htmlr�) r�r��listsr6r�r�r�r�rr~rirfr�rV�extendrhr��setrIrZr[r�r�rlrmrgrr�r�rr:r)r^r�rr�r�r��obj�set_krsr�r�rbrcrcrd�create_employee_objectivesH
�


�����r~cCs�tjj|d�}|jj|jks|jj|jj��vrPt	|d�}|j
dkrCt	|j|d�}|��rC|j
dd�}|�
�t�|td��td�S|t�d�}t|d	|d
�St�|td��td�S)z�
    This function is used to update the employee objective
        args:
            emp_obj_id(int) : pimarykey of EmployeeObjective
        return:
            redirect to form of employee objective
    r�r�r�Fr�z'Employee objective Updated successfullyr�)r�r�zokr/emp_objective_form.htmlr�zYou don't have permission.)rJrZr�rXrYrVrir�r�r7r�r�r�r~rr�r�rr:rrN)r^r6r�r�r�rbrcrcrd�update_employee_objective8s


rcCsrtjj|d�}|jj}|jrd|_|��t�|t	d��n|js0d|_|��t�|t	d��t
|j�dd��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�FrhTri�HTTP_REFERER�/)rJrZr�rir�rWr~rr�r�r�META)r^r6r�rtrcrcrd�archive_employee_objectiveVs
r�cCs�tjj|d�}|j�d�}|j��rt�|td��n|j	}|j
}|��|j�
|�t�|td��|s>t|j�dd��Std�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�)rJrZr�r�rXr�rr�r�rVrir�rfr�r�rr�r)r^r6r�r�r_r�rcrcrd�delete_employee_objectivens

�r�cCsV|j�d�}tjj|d���}|j�d�}|j�d�s,|j|jj	ks,|jj	|j
j��vr�|j
|kr�||_
|��t�|td|j
�d|j
�d���tj|jj	|jjd|j
�d|j
�d�d|j
�d	|j
�d�d
|j
�d|j
�d�d
|j
�d|j
�d�d|j
�d|j
�d�tdd|j
jid�d�td�St�|td��td�St�|td��td�S)z�
    This function is used to change status of the employee objective
        args:
            hx-request
        return:
            a message
    �empObjIdr�r\r�zThe status of the objective 'z)'                    has been changed to �.u%تم تغيير حالة الهدف 'u'                    إلى zDer Status des Ziels 'z'                    wurde zu u geändert.zEl estado del objetivo 'z('                    ha sido cambiado a zLe statut de l'objectif 'u('                    a été changé à rsrtrurwz4The status of the objective is the same as selected.rI�4<script>$('#reloadMessagesButton').click();</script>)r�r�rJrZr[r�rXrrVrYrir�r�r\r~rr�r�r)r�r�rr�rNr)r^r�r�r\rcrcrd� change_employee_objective_status�s`

�

���
�
�
�
�
�
�����r��pms.add_employeekeyresultcCs<t|j�j}t|d|j�d�d�}|tjd�}t|d|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�rVz%okr/key_result/kr_dashboard_view.htmlr�)r/r�r�r&r�rIr>r)r^r�rbrcrcrd�key_result_view�s
��r�cCs�|jj}|dkr*tjjt|�d�}d}d}|D]}|j}|j}qt|||d�d�}n"t	�
|�}	|	D]}
tjj|
d���}|j}|j}q1t|||d�d�}|||d�}|dkr_|�d�}||d	<|j
d
kr�|dkr�tjjt|�d�}
t|jd|
id�}|��r�|jd
d�}|j|_|
|_|��t�|td��tt|�S||d<nQ|dkr�t	�
|�}	|	D]9}
tjj|
d���}t|jd|id�}|��r�|jd
d�}|j|_|j|_||_|��q�||d<t|d|�St�|td��tt�St|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�rg�end_date)r_rx)r:ri�objective_type�multipleri�
objective_idsr�rkrwFr��Key result createdr:z'okr/key_result/key_result_creation.htmlzKey results created)rXrYrJrZr[rfrgr�r9r��loadsr�r�r�r�r�r�r~ra�start_valuerkrr�r�rr?rVrre)r^rt�obj_typer_r�rgr�r|r:r�rirbrtrk�form_key_resultr�rcrcrd�key_result_creation�sx
�

��


�



�
�r�c
Cs�tjj|d�}d}d}|D]}|j}|j}q
t||d�d�}||d�}tjj|d�}|jdkrkd|i}	t|j|	d�}
|
�	�rg|
j
dd	�}|j|_||_
|�
�t�|td
��t|d|�}t|j�d�d
�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�rw)r:�objecitve_idr�rkFr�r�z,okr/key_result/key_result_creation_htmx.htmlr_r`r:)rJrZr[rgr�r9r�r�r�r�r~rar�rkrr�r�rrrbrc)
r^r��objectrgr�r|r:rbr�rr�r�rdrcrcrd�key_result_creation_htmx)s8�

��r�zpms.update_employeekeyresultcCs�tjj|d�}t|d�}||jd�}|jdkrHt|j|d�}|j|jd<|�	�rD|�
�t�|t
d��t|d|�}t|j�d�d	�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�)r:rhr�rkzKey result updatedz%okr/key_result/key_result_update.htmlr_r`r:)rIrZr�r9r�r�r�rkrxr�r~rrNr�rrrbrc)r^r�r�r:rbrdrcrcrd�key_result_updateSs 

��r�c
Cs|jr|j}tj|jj|jdddddtdd|jid�d	d
�	|jr<|j}tj|jj|jddd
ddtdd|jid�d	d
�	|j	ra|j	�
�}|D]}tj|jj|jdddddtdd|jid�d	d
�	qF|jr�|j�
�}|D]}tj|jj|jdddddtdd|jid�d	d
�	qkdSdS)NzYou have received feedback!u!لقد تلقيت ملاحظات!zSie haben Feedback erhalten!u"¡Has recibido retroalimentación!u"Vous avez reçu des commentaires !zfeedback-detailed-viewr�ruzchatbox-ellipses�rxryrzr{r|r}r�iconz2You have been assigned as a manager in a feedback!u6لقد تم تعيينك كمدير في ملاحظة!z4Sie wurden als Manager in einem Feedback zugewiesen!u0¡Has sido asignado como manager en un feedback!u=Vous avez été désigné comme manager dans un commentaire !z6You have been assigned as a subordinate in a feedback!u8لقد تم تعيينك كمرؤوس في ملاحظة!z9Sie wurden als Untergebener in einem Feedback zugewiesen!u4¡Has sido asignado como subordinado en un feedback!uAVous avez été désigné comme subordonné dans un commentaire !z4You have been assigned as a colleague in a feedback!u6لقد تم تعيينك كزميل في ملاحظة!z4Sie wurden als Kollege in einem Feedback zugewiesen!u/¡Has sido asignado como colega en un feedback!u?Vous avez été désigné comme collègue dans un commentaire !)rVr)r�rXrYr�rr�r��subordinate_idr��colleague_id)r^r�r_r�subordinates�subordinate�
colleagues�	colleaguercrcrd�send_feedback_notificationstsp�
�
�
��r�zpms.add_feedbackc	Cs�t�}d|i}|jdkr[t|j�}|��rW|j�d�}|j�d�}r;|D]}tjj|d��	�}|�
�}|j�|�q%|�
�}|j
�|�t�|td��t||d�tt�S||d<t|d|�S)	zr
    This view is used to create feedback object.
    Returns:
        it will return feedback creation html.
    �
feedback_formr�r��employee_key_results_idr�zFeedback created successfully.)r�zfeedback/feedback_creation.html)r8r�r�r�r�r�rIrZr[r�r~r�r�r�r{rr�r�r�r�feedback_list_viewr)	r^r�rb�	employeesr�rhr�r�r�rcrcrd�feedback_creation�s.�

��r�zpms.change_feedbackc
Cs8tjj|d�}t|d�}tjj|d�}d|i}|r1t�|td��t	|d|�}t
|j�d�d�S|j
d	kr�t|j|d�}|��r�|j�d
�}|j�d�}rg|D]}	tjj|	d���}
|��}|j�|
�qQ|��}|j�|�|��}t�|td��t||�t	|d|�}t
|j�d�d�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!.zfeedback/feedback_update.htmlr_r`r�r�r�zFeedback updated successfully!.)rKrZr�r8rEr[rr�r�rrrbrcr�r�r�r�r�rIr�r~r�r�r�r{rNr�)
r^r��feedbackr��feedback_startedrbrdr�r�rhr�r�r�rcrcrd�feedback_update�sD
�
��
�r�c
Cs�|j��}ddi}t|jp||d�}t|jp||d�}t|jp ||d�}	t|j|d�j}t|jt��}
t|jt��}t|	jt��}|j�d�}
|
�|
�}|�|
�}|�|
�}t	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.

    rWFr�r�r)	r�
self_feedback�requested_feedback�anonymous_feedback�
all_feedbacks�feedback_filter_formrrr�)r�rr.r,r�r
rr�rr
rWrArrrKr�)r^r�r��all_feedbackr�rr�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_allrr�rbrcrcrd�filter_pagination_feedback-sN

�
�
����



�r�c
CsP|j�d�}|durd}tjj|jd�}tjj|d�j|d�}g}|�dd�tjj|d	�D��|�d
d�tjj|d�D��|�dd�tjj|d
�D��tjj|d�j|d�}tj��}|j�	d�rntj�
�j|d�}ntjj|d	�j|d�}|j�	d�s�tjj|jjdd�ntjjdd�}t
|�}||B��}t|||||�}	t|d|	�S)��
    This view is used to filter or search the feedback object  ,
    Args:
    Returns:
        it will return the filtered and searched object.
    rNr�r#r�)�review_cycle__icontainscSr�rcr��r��ircrcrdr�xr�z(feedback_list_search.<locals>.<listcomp>�r�cSr�rcr�r�rcrcrdr�{r��r�cSr�rcr�r�rcrcrdr�~r��r�)�pk__in�pms.view_feedbackF��anonymous_feedback_idrWrSzfeedback/feedback_list.html)r�r�rrZrXrKr[rz�nonerr�rDr�rBr\r�r)
r^r�rVr��requested_feedback_idsr�r�r��related_anonymous_feedbacksrbrcrcrd�feedback_list_searchfsL	�����
�
���
�r�c
Cs�|j}|j}tjj|dd�}tj�t|d�t|d�Bt|d�B���}|�d�r0tjjdd�}ntjj|dd�}|j�d�sHtjj|jj	dd	�ntjjdd�}t
|�}|jdd�|B��}t|||||�}tj���
�rod
}	nd}	t||	|�S)r�FrUr�r�r�r�rS)r�rWr�z feedback/feedback_list_view.htmlzfeedback/feedback_empty.html)rXrYrKrZr[rr\rrDr�rBr�r�r�r)
r^rXr_�feedback_own�feedback_requested�feedback_allr�r�rbr`rcrcrdr��s>���

����
�r�cKs�tjj|d�}t||d�}|rQtjj|d�}|��}g}g}|D]}	tjj||	d���r2|�|	�q |�|	�q ||d�}
||tj	|
t
j
����d�}t
|d|�St�|td��|j�d	d
�}d|�d�}
d
}||j��vrtt
|d�St|
�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�rV)�yes�no)r�r��feedback_status�employee_staticsrWz$feedback/feedback_detailed_view.htmlrIr�r�� <script>window.location.href = "�
"</script>�HTTP_HX_REQUEST�decorator_404.html)rKrZr�rArEr[�requested_employeesr�r�r>r
rWrArrrNr�r��keysr)r^r�rvr��is_have_permr�r�r�r�r_r�rb�previous_url�scriptr�rcrcrd�feedback_detailed_view�s@	���
�
r�cCs�tjj|d���}tjj|d���}t||d�}tjj||d�}|r5tjj||d�}||d�}t|d|�St	�
|td��|j�
dd	�}	d
|	�d�}
d}||j��vrXt|d
�St|
�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��rVr�)�answers�kr_feedbacksz+feedback/feedback_detailed_view_answer.htmlrIr�r�r�r�r�r�)rrZr[r�rKrArMrErrrNr�r�r�r�r)r^r�r�r_r�r�r�r�rbr�r�r�rcrcrd�feedback_detailed_view_answer�s*
���
r�c
Ks|j}tjj|d���}tjj|d�}tjj||d�}|j}|j	�
�}tj�
�}	|jg|j
gt|j�
��t|j�
��}
||
vrNt�|td��tt�S|
D]}tjj||d���}qP|rfd|_|��|rtt�|td��tt�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#r�r��You are not allowed to answerr�r^zFeedback already answered)�	questions�optionsr�z$feedback/answer/feedback_answer.html)rXrrZr[r�rKr�rE�question_template_id�questionr�rSrVr�r�r�r�rrNr�rr�r�r\r~r)
r^r�rvrXr_r��answer�question_templater�r��feedback_employees�
has_answerrbrcrcrd�feedback_answer_getsF


�������r�c
Cs|j}tjj|d���}tjj|d�}|j}|j�	�}|j
dkr�|D])}|j�d|j���rK|j�d|j���}t
jjd|i|||d�d|_|��q"|j�	�D]$}	|j�d|	j���ru|j�d|	j���}tjjd|i|	||jjd�qQt�|td	�d
|ji�tt�SdS)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�rVzOn Trackr�)r�rhr�rVz:Feedback %(review_cycle)s has been answered successfully!.�review_cycleN)rXrrZr[r�rKr�r�r�r�r�r�r�rE�
get_or_creater\r~r�rMrYrr�r�r�rr�)
r^r�rXr_r�r�r�r�r�r�rcrcrd�feedback_answer_postNsH


�������r�c	Ksz|j}tjj|d���}tjj|d�}tjj||d�}tjj||d�}|s1t	�
|td��tt
�S|||d�}t|d|�S)z�
    This view is used to  view the feedback for employee.
    Args:
        id(int) : primarykey of the feedback.
    Returns:
        it will return feedback answer object to feedback_answer_view.
    r#r�r�zFeedback is not answered yet)r�r��key_result_feedbackz)feedback/answer/feedback_answer_view.html)rXrrZr[r�rKr�rErMrrNr�rr�r)	r^r�rvrXr_r�r�r�rbrcrcrd�feedback_answer_view{s
��r�zpms.delete_feedbackcCs�zItjj|d���}tjj|d���}|jdks|jdkr1|s1|��t�|t	d�d|j
i�nt�|t	d�|j
|jd��tt
�WSWtt
�Stjy^t�|t	d	��Ytt
�Styqt�|t	d
��Ytt
�Sw)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\�Feedback not found.�Related entries exists)rKrZr[r�rEr\r�rr�r�r�r�rr�r�r�r)r^r�r��answeredrcrcrd�feedback_delete�s<


�����
����r�cCs�|j�d�}tt|d�}tjj|d�}|dkr%|r%t�|t	d��t
d�S||_|��|j|krCt�
|t	d�dt	|�i�t
d�St�|t	d	�dt	|�i�t
d�S)
z�
    This view is used to  update status of feedback.
    Args:
        obj_id (int): Primarykey of feedback.
    Returns:
         message to the view
    r�r�r�r�zFeedback is already startedr�z&Feedback status updated to  %(status)sr\z1Error occurred during status update to %(status)s)r�r�rrKrErZr[rr�r�rr\r~r�rN)r^r�r\r�r�rcrcrd�feedback_detailed_view_status�s$

��r�cCs�|rtjj|d���nd}|rtt||dd�rv|j}|j��}|j��}|j	��}i}|D]!}g}	|D]}
|
j
|krH|	�|
j|
j
d|
j
jigi�q2|	||<q,|D]}g}	|	�|j|j
ddigi�|	|d|jj��<qPt|dd	|id
�SdSdS)z
    overview of feedback
    r�Nr�r�rC�6zFeedback about keyresult: zfeedback/feedback_overview.html�feedback_overviewr�)rKrZr[r�rAr�r�r��feedback_answer�feedback_key_resultr�r�rVr��
question_typerhr)r^rtr�r�r��feedback_answersr�rr��answer_listr��kr_feedbackrcrcrd�get_feedback_overview�sJ�




����
�����rcCsftjj|d�}|jrd|_|��t�|td��tt	�S|js/d|_|��t�|td��tt	�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!.)
rKrZr�rWr~rrNr�rr�)r^r�r�rcrcrd�feedback_archives	�rc
Cs�z�|j�d�}|rtjjt|�d�nd}|r�tj��}|jr"|jjnd}|j�d�dkrI|��}|j	g}|r<|�
|j	�tjjd|d�j|d�}n7|j�d�d	kr\|r[tjj|j	d�}n$|j�d�d
krmtjjd|d�}n|j�d�dkr�t
jj|d
��dd�}dd�|D�}d|i}td|�}	t|	�WStddidd�WStjy�tddidd�YSty�}
ztdt|
�idd�WYd}
~
Sd}
~
ww)z9
    Get collegues and subordinates for the manager.
    rVr�Nr�r�T)�	is_active�!employee_work_info__department_id��id__inrr�)r
�(employee_work_info__reporting_manager_id�
keyresults�r�r��key_result_id__titlecSsg|]}|j|f�qSrcr�r�rcrcrdr�K�z!get_collegues.<locals>.<listcomp>r�zemployee/employees_select.htmlr�zEmployee not foundi��r\zInvalid Employee ID�i�)r�r�rrZrfr��employee_work_info�reporting_manager_id�get_departmentr�r�r[�excluderI�values_listrrrr��	Exceptionr�)r^rVr_�employees_queryset�reporting_manager�
department�exclude_idsr�rb�
employee_html�ercrcrd�
get_collegues!s\

���������

 ��r$cCs�|j�d�dk}|rK|jdkrC|j�d�}|j�d�}tjj|d�}tjj|d���}t	jj||d�}|r9t
d�nt
d	�}td
|i�Std
didd
�SdS)z�this function is used to un-archive the feedback
    args:
        id(int): primarykey of feedback
        emp_id(int): primarykey of feedback
    �X-Requested-With�XMLHttpRequestr�rVr�r�r��	Completedz
Not-completedr\zInvalid requestrrN)�headersr�r�r�rKrZrr[r�rEr�r)r^�is_ajaxrVr�r�r_r�r\rcrcrdr�Ws
�r�zpms.add_questionc
Cs|jdkr�t|j�}tjj|d�}tjj|d���}|r)t	�
|td��tt
|�S|��r||jdd�}||_|��|jdkro|j�d�}|j�d	�}|j�d
�}|j�d�}	t|||||	d���t	�|td
��tt
|�St	�|td
��tt
|�St	�|td��tt
|�SdS)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�r,r-r.r/zQuestion created successfully.z(Error occurred during question creation!N)r�r?r�rTrZr�rKr[r�rrNr�r�question_template_detailed_viewr�r~�template_idrrSr�r�)
r^r�r�r��feedback_ongoing�obj_questionr,r-r.r/rcrcrd�question_creationlsF

��

�


�r4cCsztjj|d�}tttdd�}|j��}||d�}g}gd�}|D]}tjj	|d�}	|�
|	�q |||||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)rTrZr�rrRr?r�r�rSr[rzr)r^r�r��question_formsetr�r=r�r<r�r;rbrcrcrd�
question_view�s(	

��r@zpms.change_questionc
Cs(|jdkr�tjj|d�}t|j|d�}|��r||jd}|dkr^|jd}|jd}|jd}|jd	}	tjj	|d
�\}
}||
_
||
_||
_|	|
_
|
��|��t�|td��tt|�S|��tjj|d
�}|ro|��t�|td��tt|�St�|d�d
d�|j��D���tt|�SdS)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�rr+r,r-r.r/r:zQuestion updated successfully.�
cS�(g|]\}}|D]	}|�d|���qqS�z: rc�r�r��errorsr�rcrcrdr������z#question_update.<locals>.<listcomp>N)r�rRrZr�r?r�r�rrSr�r,r-r.r/r~rrNr�rr0r[r�r��joinrE�items)
r^�temp_id�q_idr�r�rr,r-r.r/r��createdr;rcrcrd�question_update�sJ






�

���

�rLzpms.delete_questioncCs�z(tjj|d���}|jj}tjj|d���|��t�	|t
d��tt|�WSt
y9t�|t
d��Yn"tjyJt�|t
d��YntyZt�|t
d��Ynwtt|�S)z�
    This view is used to  delete  question object.
    Args:
        id (int): primarykey of question
    Returns:
        it will redirect to  question_template_detailed_view.
    r�r:zQuestion deleted successfully!z7Failed to delete question: Question template is in use.zQuestion not found.r�)rRrZr[r�r1r�rSr�rr�r�rr0r
r�r�r)r^r�r�rIrcrcrd�question_delete�s"��
rMzpms.add_questiontemplatecCsdt�}|jdkr0t|j�}|��r|��}tt|j�St�	|d�
dd�|j��D���tt
�SdS)z�
    This view is used to create a question template object.
    Args:
    Returns:
        It will redirect to question_template_detailed_view.
    r�rAcSrBrCrcrDrcrcrdr�)	rFz.question_template_creation.<locals>.<listcomp>N)r@r�r�r�r~rr0r�rr�rGrErH�question_template_view)r^r�r�rcrcrd�question_template_creation	s 	

���
�rOzpms.view_questiontemplatecCs tj��}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)rTrZr�r@r�r^rPrbrcrcrdrN3	s


�rNcC�tj��}d|i}t|d|�S)zH
    This view is used to  view  question template  object in htmx.
    rPz6feedback/question_template/question_template_list.html)rTrZr�rrQrcrcrd�question_template_hx_viewB	s

�rSc	Ks�tjj|d���}|st�|td��tt�S|j	�
��d�}gd�}tjj|d�}dd�|D�}||||t
|d�}t|d	|�S)
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�)r6r7r8z
multi-choicesr9)�question_id__incSsg|]}t|d��qS)r�)r?)r�r�rcrcrdr�e	rz3question_template_detailed_view.<locals>.<listcomp>)r�r�r;r<r��	form_listr>)rTrZr[r�rr�r�rrNr�r�r
rSr?r)	r^r1rvr�r�r<r��question_form_listrbrcrcrdr0P	s(��r0zpms.change_questiontemplatecCsptjj|d���}t|d�}d|i}|jdkr2t|j|d�}|��r.|��t	�
|td��||d<t|d|�S)z�
    This view is used to  update  question template object.
    Args:
        id (int): primarykey of question template
    Returns:
        it will redirect to  question_template_view.

    r�r��question_update_formr�zQuestion template updatedz8feedback/question_template/question_template_update.html)
rTrZr[r�r@r�r�r�r~rrNr�r)r^r1r�rWrbr�rcrcrd�question_template_updateu	s

�rXzpms.delete_questiontemplatecCs�z-tjj|d�}tjj|d�rt�|td��n|��t�	|td��Wt
d�SWt
d�Stj
yBt�|td��Yt
d�StyUt�|td��Yt
d�Sw)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�r*z$This template is using in a feedbackz0The question template is deleted successfully !.zquestion template not found.r�zquestion-template-hx-view)rTrZr�rKr[rrNr�r�r�r�r�rr)r^r1r�rcrcrd�question_template_delete�	s$
��
���rYzpms.view_periodcCrR)zg
    This view is used to view period objects.
    Returns:
        it will return to period_view.
    �periodszperiod/period_view.html�rQrZr�r�r^rZrbrcrcrd�period_view�	s
	�r]cCs tj��}d|i}t|d|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.
    rZzperiod/period_list.htmlr�r[r\rcrcrd�period_hx_view�	s

�r^zpms.add_periodcCsTdt�i}|jdkr$t|j�}|��r |��t�|td��n||d<t|d|�S)zk
    This view is used to create period objects.
    Returns:
        it will redirect to period_view.
    r�r�zPeriod creation was Successful zperiod/period_create.html)	r>r�r�r�r~rr�r�r)r^rbr�rcrcrd�
period_create�	s
	

r_zpms.change_periodcCsrtjj|d���}t|d�}d|i}|jdkr3t|j|d�}|��r/|��t	�
|td��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�zPeriod updated  Successfully. zperiod/period_update.html)
rQrZr[r�r>r�r�r�r~rr�r�r)r^�	period_id�periodr�rbrcrcrd�
period_update�	s

rbzpms.delete_periodcCs�ztjj|d�}|��t�|td��Wt
d�Stjy-t�|td��Yt
d�St	y@t�|td��Yt
d�Sw)z�
    This view is used to delete period objects.
    Args:
        id (int): primarykey of period
    Returns:
        it will redirect to period_view.
    r�zPeriod deleted successfully.zPeriod not found.r�zperiod-hx-view)rQrZr�r�rr�r�r�r�rr)r^r`�
obj_periodrcrcrd�
period_delete�	s
���rdcCsf|j�d�dk}|r.|jdkr(t�|�}tjj|d�}|j}|j}t	||d��St	ddi�St
dd�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��r)r(r�r�r��loadrQrZrgr�rr)r^r)r��
period_objrgr�rcrcrd�
period_change
s


ric
Cs(|j}tjj|d���}tjj|d�}tj����}|�d�r:|�d�r:t	j����}t
j����}t	jjdd�}nM|radd�|D�}t	jj|d	���}t
jj|d	���}t	jj|d	�jdd�}n&t	jj|d
���}tjj|d���}t
jj|d
���}t	jj|d
�jdd�}||||d�}	t|d
|	�S)zb
    This view is used to view dashboard.
    Returns:
        it will redirect to dashboard.
    r#)rrmr�zAt RiskrcSr�rcr�r�rcrcrdr�6
r�z"dashboard_view.<locals>.<listcomp>)�employee_id__inr�r)�count_objective�count_key_result�count_feedback�okr_at_riskzdashboard/pms_dashboard.html)
rXrrZr[r�rLr��countrrJrKrIr)
r^rXr_�
is_managerrlrkrmrn�
employees_idsrbrcrcrd�dashboard_view!
sR����������rrcCs�|j�d�dk}|rJ|jdkrLtj}dtd�i}|D]+}tjj|ddd�}t||d	d
��	�}|rE|�
dg��|d�|�
d
g��|�qt|�SdSdS)zobjective dashboard datar%r&r��message�#No records available at the moment.rF)r\rWrm�r�r��objective_labelrq�objective_valueN)
r(r�r�rJr>r�rZr[�filtersubordinatesro�
setdefaultr�r)r^r)r[r�r\r�objectives_countrcrcrd�dashboard_objective_statusP
s&�����r{cCs�|j�d�dk}|rJ|jdkrLtj}dtd�i}|D]+}tjj|dd�}t||dd	d
��	�}|rE|�
dg��|d�|�
d
g��|�qt|�SdSdS)zkey result dashboard datar%r&r�rsrtrrzpms.view_employeekeyresultr�)r�r�r��key_result_labelrq�key_result_valueN)
r(r�r�rIr>r�rZr[rxroryr�r)r^r)rVr�r��key_results�key_results_countrcrcrd�dashboard_key_result_statusd
s(����r�cCs�|j�d�dk}|rI|jdkrKtj}dtd�i}|D]*}tjj|dd�}t||dd	��	�}|rD|�
d
g��|d�|�
dg��|�qt|�Sd
Sd
S)zfeedback dashboard datar%r&r�rsrtrrr�ru�feedback_labelrq�feedback_valueN)
r(r�r�rKr>r�rZr[rxroryr�r)r^r)r�r�r��	feedbacks�feedback_countrcrcrd�dashboard_feedback_statusy
s"����r�cCs�|j}|�|�r
|Stjj|d���}|r@|dur2|jdi|�d�|i��|jdi||i��B}|S|j|d�|j|d�B}|S|j|jd�}|S)zJ
    This method is used to filter out subordinates queryset element.
    r#N�*__employee_work_info__reporting_manager_id)�5employee_id__employee_work_info__reporting_manager_idr�rc)rXrrrZr[r�rY)r^r�r�r�rXrrcrcrdrx�
s(
����
�rxcCsv|jdkrt�}|jdkr2t|j�}|��r'|��}t|j|j|j|j	d��S|j
��}td|i�St|dd|id�S)z
    This is an ajax method to return json response to create stage related
    to the project in the task-all form fields
    r�r�)r��namergr�rEzokr/create_period.htmlr�r�)
r�r>r�r�r~rr��period_namergr�rE�as_jsonr)r^r�r�rErcrcrd�
create_period�
s 


��
r�cCs�|jd}t�|�}d}td�}|j�d�dkrd}td�}|D]}tjj|d�}||_|�	�t
�|td	�j||d
��q t
ddi�S)
zB
    This method is used to archive/un-archive bulk objectivs
    �idsF�un-archivedr
�FalseT�archivedr�z{objective} is {message})r�rsrs�Success)r�r�r�r�r�r�rJrZrWr~rr��formatr)r^r�r
rsri�
objective_objrcrcrd�objective_bulk_archive�
s$

��r�c	Cs�|jd}t�|�}|D]J}z6tjj|d�}|jdks |jdkr4|��t�	|t
d�|j|jd��nt�
|t
d�|j|jd��WqtjyVt�|t
d	��Yqwtd
di�S)z6
    This method is used to bulk delete objective
    r�r�r�r^z$%(employee)s's %(objective)s deleted)r�r_z?You can't delete objective %(objective)s with status %(status)s)r�r\r�rsr�)r�r�r�rJrZr�r\r�rr�r�r�rVr�r�r�r)r^r�rir�rcrcrd�objective_bulk_delete�
s4

���	����r�cCs�|jd}|jd}t�|�}t�|�}d}td�}|j�d�dkr(d}td�}|D]}tjj|d	�}||_|�	�t
�|td
�j||d��q*|D]}t
jj|d	�}||_|�	�t
�|td
�j|j|d��qJtdd
i�S)zB
    This method is used to archive/un-archive bulk feedbacks
    r��announy_idsFr�r
r�Tr�r�z{feedback} is {message})r�rsrsr�)r�r�r�r�r�r�rKrZrWr~rr�r�rD�feedback_subjectr)r^r�r�r
rsr�rcrcrd�feedback_bulk_archive�
s8



���r�c	Cs�|jd}t�|�}|D]H}z4tjj|d�}|jdks |jdkr2|��t�	|t
d�d|ji�nt�|t
d�|j|jd��Wqtj
yTt�|t
d	��Yqwtd
di�S)z6
    This method is used to bulk delete feedbacks
    r�r�r^r�r�r�r�r�r�rsr�)r�r�r�rKrZr�r\r�rr�r�r�r�r�r�r)r^r�r�r�rcrcrd�feedback_bulk_deletes8

��������r�cCs�|j�d�}|j�d�}|jj}tjj|dd�}|dkrG|dkr?|j�d�r.tjjdd�}ntjj|jd�tjj|jd	�B}ntjj|dd�}d
d�|D�}|��}||d�}t	|dd
�S)z^
    This method is used to return all the id of the employees to select the employee row
    r��	tableNameFrUr�rmrS)�employee_id__employee_user_id��Gemployee_id__employee_work_info__reporting_manager_id__employee_user_idcS�g|]}t|j��qSrc�r�r�r�rcrcrdr�Urz$objective_select.<locals>.<listcomp>��employee_ids�total_count)�safe)
r�r�rXrYrJrZr[rror)r^r��tablerXr�r�r�rbrcrcrd�objective_select=s,����
r�cCs�|j�d�}|j�d�}|rt�|�ni}|j�d�}|jj}t|tj�	�d�}|dkro|dkrM|j�
d�r@t|tj�	�d�}nt|tjj|jd�d�}nt|tjj|d�d�}|j}d	d
�|D�}|�
�}	||	d�}
t|
�SdS)
zM
    This method is used to return all the ids of the filtered employees
    r�r[r�r�r�rmr�r�cSr�rcr�r�rcrcrdr�}rz+objective_select_filter.<locals>.<listcomp>r�N)r�r�r�r�rXrYr1rJrZr�rr[r�ror)r^r��filtered�filtersr�rX�employee_filter�filtered_employeesr�r�rbrcrcrd�objective_select_filter]s6
����
�r�cCs�|jdkrPt|j�}|jj}|��rO|jdd�}||_|��|jdkrKzt	j
tjj
dd���|jjddd	d
dtd�d
d�	Wtd�SYtd�Std�Snt�}|dd�}t|d|�S)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�r_zHorilla Bot)�usernamez#You received an anonymous feedback!u0لقد تلقيت تقييمًا مجهولًا!z%Sie haben anonymes Feedback erhalten!u&¡Has recibido un comentario anónimo!u$Vous avez reçu un feedback anonyme!z
feedback-viewz	bag-checkr�rJT�r�r��&anonymous/anonymous_feedback_form.html)r�r4r�rXr�r�r~r��based_onr)r�r	rZr[r�rVr�rrr)r^r��anonymous_idr�rbrcrcrd�anonymous_feedback_add�s8


�
��
r�cCs�tjj|d�}t|jj�|jks|j�d�rKt|d�}|jj}|j	dkr@t|j
|d�}|��r@|jdd�}||_|��t
d�S|dd�}t|d	|�St�|td
��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�zpms.change_anonymousfeedbackr�r�Fr�rJr�r��You are don't have permissions.r�)rDrZr�r�rXr�r�rr4r�r�r�r~rrrrNr�)r^rtr�r�r�rbrcrcrd�edit_anonymous_feedback�s"�


r�cCs�tjj|d�}t|jj�|jks|j�d�rB|jr,d|_|�	�t
�|td��t
t�S|js>d|_|�	�t
�|td��t
t�St
�|td��t
t�S)r	r�zpms.anonymousfeedbackFr
Trr�)rDrZr�r�rXr�r�rrWr~rrNr�rr��r^rtr�rcrcrd�archive_anonymous_feedback�s ���r�zpms.delete_anonymousfeedbackcCs�ztjj|d�}|��t�|td��Wtt�Sty,t�|td��Ytt�Stj	y@t�|td��Ytt�St
ySt�|td��Ytt�Sw)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�zFeedback deleted successfully!z7Failed to delete feedback: Feedback template is in use.r�r�)
rDrZr�r�rr�r�r
r�r�rrr�r�rcrcrd�delete_anonymous_feedback�s"

��
���r�cCstjj|d�}t|dd|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�zanonymous/single_view.htmlr�)rDrZr�rr�rcrcrd�view_single_anonymous_feedbacks
r�c	Cs&tjj|d�}|jj|jj��vs|j�d�r�|j	}|j
��}dd�|��D�}|�d�s1||d<t
|d�}|jdkr{t
|j�}|��r{|��|��|jd}|j�|�t�|td	��tj|jj|jd
ddd
dtdd|jjid�d�td�S||d�}t|d|d�St� |td��td�S)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�cSrorprrrsrcrcrdru9rvz/employee_keyresult_creation.<locals>.<dictcomp>rkrwr�rhz Key result assigned sucessfully.zYou 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é!rsrtrurwr�)r�r��okr/key_result/kr_form.htmlr�r�)!rJrZr�rXrYrir�r�rrVr�r�ryr5r�r�r�r~�update_objective_progressrrhr�rr�r�r)r�r�rr�rrrN)	r^r6r�r_r�r�emp_key_resultr�rbrcrcrd�employee_keyresult_creation&sP
�
�





��
�r�cCs�tjj|d�}|jj}|j��}t|�dkr&dd�|��D�}t	||d�}nt	|d�}|j
dkrit	|j|d�}|��ri|�
�|j��t�|td��tj|jj|jd	d
ddd
tdd|jjjid�d�td�S|dd�}t|d|d�S)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�rqcSrorprrrsrcrcrdruurvz-employee_keyresult_update.<locals>.<dictcomp>)rxr�r�r�zKey result Updated sucessfully.zYour 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.rsrtrurwr�T)r�r�r�r�)rIrZr�rkrVr�r�r�ryr5r�r�r�r~r�rr�r�r)r�rXrYr�rrir�rr)r^r�r�r_r�rr�rbrcrcrd�employee_keyresult_updatedsB
�


��
�r�zpms.delete_employeekeyresultcCs`tjj|d�}|jj}|j}|��|��t�|t	d��|j
�d�r(td�Std|j���S)��
    This function is used to delete the employee key result
        args:
            kr_id(int) : pimarykey of EmployeeKeyResult
        return:
            redirect to detailed of employee objective
    r�r��	dashboardz/pms/dashboard-viewz/pms/objective-detailed-view/)
rIrZr�rkrir�r�rr�r�r�rr�)r^r�r�r�r�rcrcrd�delete_employee_keyresult�s
r�cCs\tjj|d�}|j�d�}||_|��t�|td��	|��t
d|jj�d|jj
j���S)r�r�rVz Key result sattus changed to {}.z/pms/kr-table-view/z?&objective_id=)rIrZr�r�r\r~rr�r�r�rrkr�ri)r^r�r�r\rcrcrd� employee_keyresult_update_status�s	�r�cCs|z2t|j�d��}t|j�d��}tjj|d�}||jkr0||_|��|j�	�t
ddi�WSWdSt
ddi�YS)z?
    This method is used to update keyresult current value
    ra�emp_key_result_idr�rC�sucessr�N)rr�r�rIrZrmrar~rkr�r)r^ra�	emp_kr_idr�rcrcrd�key_result_current_value_update�s

�r�cCs�|j�d�r|j�d�nd}tjj|d���}|rQ|j�d�dkr*td|j�d��S|j�d�dkrOtj�	|j�d	�d
�}|t
|jd���}td|�d
��SdS|j�d�dkr]td�S|j�d�dkritd�SdS)zG
    Function to get the data of keyresult and return to the form.
    rhNr�zdata-updatermz0<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�rgz%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�rLrZr[r�rrmr
�strptimer�durationrA)r^�key_idr�rgr�rcrcrd�get_keyresult_data�s4���
��	���r�c	Cs�|j��}tjjdd�}|j�d�s%|jj}|�t|d�t|d�B��	�}|�
d�}t�}t||j�
d��}t�dd	�|jD��}t|�}tt|�tj��}|||j|d
�}t|d|�S)zo
    This view is used to view the meeting ,
    Returns:
        it will redirect to view_meetings.html .
    T�r
�pms.view_meetingsr��rr�r�cSr�rcr�r�rcrcrdr�
r�z!view_meetings.<locals>.<listcomp>)�all_meetings�meetings�filter_form�requests_idszmeetings/view_meetings.html)r�rrNrZr[rXrrYrr\r
r0rr�r�r�r�rrr�r)	r^rr�rVr�r�r�r�rbrcrcrd�
view_meetings�s,
��


�r�c	Cs�tt|j�d���}d}|jjdd�}|r%t|t�r%tj	j
|d���}i}t||d�}|j
dk�r8t|j|d�}|���r8|��}dd	�|jd
D�}dd	�|jdD�}|jd
}dd	�|j|jdd�D�}z/tj|jj|d|j��d|j��d|j�d�d|j��d|j��dtd�d|j��d�	Wnty�}zWYd}~nd}~wwz0tj|jj|d|j��d|j�d�d|j�d�d|j��d |j��dtd�d|j��d�	Wnty�}zWYd}~nd}~wwz/tj|jj|d!|j��d"|j��d#|j�d$�d%|j��d&|j��dtd�d|j��d�	Wnt�y/}zWYd}~nd}~wwt�|td'��t|d(d)|i�S)*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)rrVr�)r�rxr�r�cSr�rcr#)r�rrcrcrdr�*
s�z#create_meetings.<locals>.<listcomp>rcSr�rcr#)r��
answer_emprcrcrdr�-
����answer_employeesrVcSr�rcr#r�rcrcrdr�2
r�rz>You have been added as an answerable employee for the meeting uGلقد تمت إضافتك كموظف مسؤول عن الاجتماع u2Du wurden als Mitarbeiter zum Ausfüllen für das u-Meeting hinzugefügtu;Se le ha agregado como empleado responsable de la reunión uJVous avez été ajouté en tant que employé responsable pour la réunion �informationz
view-meetingsz?search=)rxryrzr{r|r}r�rz#You have been added to the meeting u/لقد تمت إضافتك إلى اجتماع r�zSie wurden zur u Besprechung hinzugefügtuTe 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ügtu4Se le ha agregado como administrador de la reunión u<Vous avez été ajouté en tant que responsable de réunion zMeeting added successfullyzmeetings/form.htmlr�)rr�r�r�rXrY�
isinstancerfrNrZr[r�r;r�r�r�r~rrr)r��titlerrrr�r�r)	r^r�r�rxr�r�r�r�r�rcrcrd�create_meetings
s�
��
��




���



���




�����r�)�Fzpms.change_meetingscCsFt�|�}|j|_|��|jrtd�ntd�}t�||�td�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 .
    zMeeting unarchived successfullyzMeeting archived successfullyr�)rN�findr
r~r�rr�r)r^rt�meetingrsrcrcrd�archive_meetingss
s


��r�cC�>tjj|d���}|j�|�|��t�|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�)rNrZr[r�rr�r~rr�r�r)r^�meet_idr�r�rcrcrd�meeting_manager_remove�
s�r�cCr�)z�
    This view is used to remove the employees from the meeting ,
    Args:
        meet_id(int) : primarykey of the meeting.
        employee_id(int) : primarykey of the employee
    Returns:
        it will redirect to view_meetings.html .
    r�z8Employee has been successfully removed from the meeting.r�)rNrZr[r�rVr�r~rr�r�r)r^r�rVr�rcrcrd�meeting_employee_remove�
s
�r�cCs�|j��}t|j�j}|j�d�s$|jj}|�t|d�t|d�B��	�}|j�
d�dus4|j�
d�dkr:|jdd�}|�d	�}t||d
�}t
||j�
d��}t�dd
�|jD��}t|�}tt|�t|d||||d��S)zn
    This view is used to filter the meeting ,
    Returns:
        it will render to meeting_list.html .
    r�r�r�r
N�unknownTr�r�rr�cSr�rcr�r�rcrcrdr��
r�z#filter_meetings.<locals>.<listcomp>zmeetings/meetings_list.html)r�r�r�r�)r�rr0r�rXrrYr[rr\r�r
rrr�r�r�rrrJr)r^r�
filter_objrVr�r�rcrcrd�filter_meetings�
s6
��

��r�cCsNt�|�}|jdkr|j�d�}||_|��t�|t	d��t
|dd|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�rdz7Minutes of Meeting (MoM) have been created successfullyzmeetings/mom_form.htmlr�)rNr�r�r�r�rdr~rr�r�r)r^rtr�rdrcrcrd�add_response�
s


�r�T)�
answerablecKs�|jj}|j�d�}rtjj|d���}tjj|d�}t	jj||d�}|j
j��}t
j��}|j��|j��B}	|sA|j�d�rJtd|j|jd�S||	vrZt�|td��tt�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_idrVzmeeting-answer-view)r�r�r�)r�r�r�zmeetings/meeting_answer.html)rXrYr�r�rrZr[r�rNrOr�r�r�rSrrVrr�rrNr�r�r)r^r�rvr_rVr�r�r�r��meeting_employeesrbrcrcrd�meeting_answer_get�
s$
�r�cCs�|jj}tjj|d�}|jj��}|jdkrL|D]"}|j	�d|j
���r:|j	�d|j
���}tjjd|i|||d�qt
�|td�d|ji�tt�SdS)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�r�rVzBQuestions for meeting %(meeting)s has been answered successfully!.r�N)rXrYrNrZr�r�r�r�r�r�r�rOr�rr�r�r�rr�)r^r�r_r�r�r�r�rcrcrd�meeting_answer_posts,
�����r�cKsFtjj|d���}tjj|d�}tjj||d�}||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�r�)r�r�z!meetings/meeting_answer_view.html)rrZr[r�rNr�rOr)r^r�r�rvr_r�r�rbrcrcrd�meeting_answer_view6s�r�cCsH|jj}tjj|d�}tjj||d�}d}|rd}||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�r�FT)�is_answeredr�z,meetings/meeting_question_template_view.html)rXrYrNrZr�rOr[r)r^r�r_r�r�r�rbrcrcrd�meeting_question_template_viewMs�r�cCsftjj|d���}d|i}|j�d�}|r-t�|�}t||�\}}||d<||d<||d<t	|d|�S)Nr�r�r��previousrz!meetings/meeting_single_view.html)
rNrZr[r�r�r�r�r�rr)r^r�r�rb�requests_ids_jsonr��previous_id�next_idrcrcrd�meeting_single_viewes
r�r�cCs2tjj|dd�}tj��}||d�}t|d|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

    FrU)r�rztabs/performance-tab.htmlr�)rKrZr[r
rWr)r^r�r�rWrbrcrcrd�performance_tabss
�r�cCs~|j��}|j�d�}|jj}tj�t|dd�t|dd�Bt|dd�B��	�}|j
|d�}t||�}t|d||t
j��d��S)	Nr�T)r��manager_id__is_active)r��colleague_id__is_active)r��subordinate_id__is_active)�feedback_answer__employee_idz(request_and_approve/feedback_answer.html)r�r�r)r�rr�rXrYrKrZr[rr\rrrr
rArW)r^rr�r_r�r�rcrcrd�dashboard_feedback_answer�s,


�
���
��r�zpms.delete_bonuspointsettingc
Cshztjj|d���t�|d�Wnty-}zt|�t�|d�WYd}~nd}~wwt	t
d��S)z$
    Delete bonus point setting
    r�zBonus Point Setting deleted�Something went wrongNzbonus-point-setting-list-view)rFrZr�r�rr�r�loggerr�rr)r^�pkr#rcrcrd�delete_bonus_point_setting�s��r�zpms.delete_employeebonuspointc
Cszztjj|d�}|��t�|t|�d���Wnty6}zt|�t�	|td��WYd}~nd}~wwt
td��S)z 
    Automation delete view
    r�z deletedr�Nzemployee-bonus-point-list-view)rHrZr�r�rr�r�rr�r�rr)r^r��bonusr#rcrcrd�delete_employee_bonus_point�s��r�csV|jd}	|jd}t|�\}}�G�fdd�dtj�}t|�d�}t|||d��S)N�modelcs"eZdZdZG�fdd�d�ZdS)z3bonus_setting_form_values.<locals>.InstantModelFormz"
        InstantModelForm
        cseZdZ�ZdZdS)z8bonus_setting_form_values.<locals>.InstantModelForm.Meta�__all__N)�__name__�
__module__�__qualname__r�rrc��model_classrcrd�Meta�srN)rrr�__doc__rrcrrcrd�InstantModelForm�sr�automation_multiple_)�choices�mail_details_choice�serialized_form)r�r'r�	ModelFormr(r)r^r��
model_path�	to_fieldsr
rrrcrrd�bonus_setting_form_values�s

	��rzpms.update_bonuspointsettingcCs`|j�d�}tjj|d�}|dkrd|_t�|td��nd|_t�|td��|��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�rFrZr
rr�r�r~r)r^rtr
�bonus_point_settingrcrcrd�"update_isactive_bonuspoint_setting�s	r)N)NN)�rr
r��logging�	itertoolsr�urllib.parserrr�dateutil.relativedeltar�djangor�django.contribr�django.contrib.auth.modelsr	�django.core.paginatorr
�django.db.modelsrr�django.db.utilsr
�django.formsr�django.httprrr�django.shortcutsrrr�django.template.loaderr�django.urlsr�django.utils.translationrr��base.methodsrrrrrr�employee.modelsrr�horilla.decoratorsr r!r"r#r$r%�horilla.group_byr&�#horilla_automations.methods.methodsr'�%horilla_automations.methods.serializer(�notifications.signalsr)�pms.filtersr*r+r,r-r.r/r0r1r2�	pms.formsr3r4r5r6r7r8r9r:r;r<r=r>r?r@�pms.methodsrArBrC�
pms.modelsrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrT�	getLoggerrr�rer�r�r�r�r�r�r�r�r�r�r�r�r]rrr9r?rQrRrTrZr]rergrlrnr~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr$r�r4r@rLrMrOrNrSr0rXrYr]r^r_rbrdrirrr{r�r�rxr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrcrcrcrd�<module>s�  ,@L

(S*+A8
2
4 -
/6P'@G-
85
/
+
"
1
,
&
*
5
-
!6
#

.





#!

'-$
<0


 
Z
("




Youez - 2016 - github.com/yon3zu
LinuXploit