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/onboarding/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

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

hͦhq��@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZmZdd	lmZdd
lmZddlmZmZmZddlmZmZdd
lmZddl m!Z!ddl"m#Z$ddl"m%Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;m<Z<m=Z=m>Z>ddl?m@ZAddlBmCZCddlDmEZEmFZFmGZGddlHmIZImJZJddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRddlSmTZTmUZUmVZVmWZWmXZXddlYmZZZm[Z[m\Z\ddl]m^Z^dd l_m`Z`maZambZbddlcm@Z@e�dee�Z<e=e;eFd!�d"d#����Zfd$d%�Zge=e;eFd&�d'd(����Zhe=e>d)�eFd)�d*d+����Zie=e;eGd,�d-d.����Zje=e;eGd/�d0d1����Zke=e>d2�eGd2�d3d4����Zle=e>d5�d6d7���Zme=e>d8�d9d:���Zne=e>d;�d<d=���Zoe=e;eEd>�d?d@����ZpdAdB�Zqe=e>dC�dDdE���Zre=e>dFdG�dHdI���Zse=e;e>dC�dJdK����Zte=eEdL�dMdN���ZudOdP�Zve=eEd>�dQdR���Zwe=eEd>�dSdT���ZxiZydUdV�ZzdWdX�Z{dYdZ�Z|d[d\�Z}d]d^�Z~d_d`�Ze=dadb��Z�e=e(dcg�eEdd�dedf����Z�e=dgdh��Z�e=eEdd�didj���Z�e=e(dcg�eGdk�dldm����Z�e=e(dcg�eGdk�dndo����Z�e=e(dcg�eEdd�dpdq����Z�e=drds��Z�e=e>dC�dtdu���Z�e=e>dC�dvdw���Z�e=e>dC�dxdy���Z�e=eGd8�dzd{���Z�e=eGd|�d}d~���Z�e=e(dcg�e;dd�����Z�e=e;eGd8�d�d�����Z�e=eGd|�d�d����Z�e=e;eEd/�d�d�����Z�e=eEd��d�d����Z�e=eEdd�d�d����Z�e=e>d��d�d����Z�e=e;e>d��d�d�����Z�e=d�d���Z�e=e>dF�d�d����Z�d�d��Z�d�d��Z�dS)�a�
views.py

This module contains the view functions for handling HTTP requests and rendering
responses in your application.

Each view function corresponds to a specific URL route and performs the necessary
actions to handle the request, process data, and generate a response.

This module is part of the recruitment project and is intended to
provide the main entry points for interacting with the application's functionality.
�N)�parse_qs)�template)�messages)�login)�User)�EmailMessage�	send_mail)�	Paginator)�ProtectedError)�HttpResponse�HttpResponseRedirect�JsonResponse)�redirect�render)�render_to_string)�reverse)�gettext)�gettext_lazy)�require_http_methods)�ConfiguredEmailBackend)�closest_numbers�generate_pdf�get_key_instances�get_pagination�sortby)�HorillaMailTemplate�JobPosition)�Employee�EmployeeBankDetails�EmployeeWorkInformation)�settings)�hx_request_required�logger�login_required�permission_required)�group_by_queryset)�notify)�all_manager_can_enter�recruitment_manager_can_enter�stage_manager_can_enter)�OnboardingCandidateFilter�OnboardingStageFilter)�BankDetailsCreationForm�EmployeeCreationForm�OnboardingCandidateForm�OnboardingTaskForm�OnboardingViewStageForm�OnboardingViewTaskForm�UserCreationForm)�CandidateStage�
CandidateTask�OnboardingPortal�OnboardingStage�OnboardingTask)�CandidateFilter�CandidateReGroup�RecruitmentFilter)�RejectedCandidateForm)�	Candidate�Recruitment�RejectedCandidatezonboarding.add_onboardingstagecCsvt�}|jdkr2tjj|d�}t|j�}|��r2|��}|j�	t
jj|j�
d�d��t||||�St|d||d��S)a
    function used to create onboarding stage.

    Parameters:
    request (HttpRequest): The HTTP request object.
    obj_id : recruitment id

    Returns:
    GET : return onboarding stage creation form template
    POST : return stage save function
    �POST��id�employee_id��id__in�onboarding/stage_form.html��formrA)r0�methodr=�objects�getr?�is_valid�saverB�setr�filter�data�getlist�
stage_saver)�request�obj_idrG�recruitment�	stage_obj�rV� /var/www/erp/onboarding/views.py�stage_creationUs

�rXcCs�|jdd�}||_|��t�|td��dd�|j��D�}tj|j	j
|dddd	d
dtd�d
�	t|d||d��}t
|j�d�d�S)z�
    function used to save onboarding stage.

    Parameters:
    request (HttpRequest): The HTTP request object.
    recruitment : recruitment object
    rec_id : recruitment id

    Returns:
    GET : return onboarding view
    F��commitz New stage created successfully..cS�g|]}|j�qSrV��employee_user_id��.0�employeerVrVrW�
<listcomp>��zstage_save.<locals>.<listcomp>�*You are chosen as onboarding stage manager�@لقد تم اختيارك كمدير مرحلة التدريب.�4Sie wurden als Onboarding-Stage-Manager ausgewählt.�CHa sido seleccionado/a como responsable de etapa de incorporación.�MVous avez été choisi(e) en tant que responsable de l'étape d'intégration.�
people-circle�onboarding-view��	recipient�verb�verb_ar�verb_de�verb_es�verb_fr�iconrrErF�utf-8�#<script>location.reload();</script>)rL�recruitment_idr�success�_rB�allr&�send�user�employee_getrrr�content�decode)rGrTrR�rec_id�stage�users�responserVrVrWrQqs,���rQz!onboarding.change_onboardingstagecCs�tjj|d�}t|d�}|jdkrgt|j|d�}|��rg|��}|j�	t
jj|j�
d�d��t�|td��dd�|j��D�}tj|jj|d	d
ddd
dtd�d�	t|d|||d��}t|j�d�d�St|d|||d��S)a
    function used to update onboarding stage.

    Parameters:
    request (HttpRequest): The HTTP request object.
    stage_id : stage id
    recruitment_id : recruitment id

    Returns:
    GET : return onboarding stage update form template
    POST : return onboarding view
    r@��instancer?rBrCzStage is updated successfully..cSr[rVr\r^rVrVrWra�rbz stage_update.<locals>.<listcomp>rcrdrerfrgrhrirjzonboarding/stage_update.html)rG�stage_idrtrrrs)r6rIrJr0rHr?rKrLrBrMrrNrOrPrrurvrwr&rxryrzrrrr{r|)rRr�rt�onboarding_stagerGr~rr�rVrVrW�stage_update�sF

��
��
�r�z!onboarding.delete_onboardingstagecCs~ztjj|d���t�|td��Wn"tjy%t�|td��Ynt	y5t�|td��Ynwt
|j�dd��S)z�
    function used to delete onboarding stage.

    Parameters:
    request (HttpRequest): The HTTP request object.
    stage_id : stage id

    Returns:
    GET : return onboarding view
    r@z!The stage deleted successfully...zStage not found.z%There are candidates in this stage...�HTTP_REFERER�/)r6rIrJ�deleterrurv�DoesNotExist�errorr
r�META)rRr�rVrVrW�stage_delete�s�r�zonboarding.add_onboardingtaskc
CsD|j�d�}tjj|d�}td|id�}|jdkr�t|jd|id�}|��r�|jd}|jd}|jd}|jd}t	||d�}|�
�|j�|�|j
�|�|rb|D]
}	t|	||d	�}
|
�
�qTd
d�|j��D�}tj|jj|dd
ddddtd�d�	t|d||d��}t�|td��t|j�d�d�St|d||d��S)z�
    function used to create onboarding task.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return onboarding task creation form template
    POST : return onboarding view
    r�r@��initialr?�
candidates�managers�
task_title)r�r���candidate_idr��onboarding_task_idcSr[rVr\)r_�managerrVrVrWra���z!task_creation.<locals>.<listcomp>�,You are chosen as an onboarding task manager�>لقد تم اختيارك كمدير مهام التدريب.�6Sie wurden als Onboarding-Aufgabenmanager ausgewählt.�DHa sido seleccionado/a como responsable de tareas de incorporación.�MVous avez été choisi(e) en tant que responsable des tâches d'intégration.rhrirjzonboarding/task_form.html)rGr�z New task created successfully...rrrs)�GETrJr6rIr1rHr?rK�cleaned_datar7rLrBrMr�r4rwr&rxryrzrrrrurvrr{r|)
rRr�r~rG�	form_datar�r��title�onboarding_task�cand�taskrr�rVrVrW�
task_creation�s`




�
�����r�z onboarding.change_onboardingtaskcCstjj|d�}|jdkrzt|j|d�}|��rz|��}|j�	t
jj|j�
d�d��|j��D]}|j|j��vr>|��q/|j|_q/t�|td��dd�|j��D�}tj|jj|d	d
ddd
dtd�d�	t|d||d��}t|j�d�d�St|d�}t|d||d��S)z�
    function used to update onboarding task.

    Parameters:
    request (HttpRequest): The HTTP request object.
    task_id : task id

    Returns:
    GET : return onboarding task update form template
    POST : return onboarding view
    r@r?r�rBrCzTask updated successfully..cSr[rVr\r^rVrVrWraFrbztask_update.<locals>.<listcomp>r�r�r�r�r�rhrirjzonboarding/task_update.html)rG�task_idrrrs) r7rIrJrHr/r?rKrLrBrMrrNrOrP�candidatetask_setrwr�r�r�r�rrurvr&rxryrzrrrr{r|)rRr�r�rGr��	cand_taskrr�rVrVrW�task_update&sV
�

����
��r�z onboarding.delete_onboardingtaskcCs~ztjj|d���t�|td��Wt
t�Stjy+t�|td��Yt
t�St	y>t�|td��Yt
t�Sw)z�
    function used to delete onboarding task.

    Parameters:
    request (HttpRequest): The HTTP request object.
    task_id : task id


    Returns:
    GET : return onboarding view
    r@z The task deleted successfully...zTask not found.zKYou cannot delete this task because some candidates are associated with it.)r7rIrJr�rrurvr�r�r
r�onboarding_view)rRr�rVrVrW�task_deletehs 
�����r�zrecruitment.add_candidatecCsdt�}|jdkr*t|j|j�}|��r*|��}d|_|��t�|t	d��t
t�St|dd|i�S)z�
    function used to create hired candidates .

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return candidate creation form template
    POST : return candidate view
    r?Tz$New candidate created successfully..z"onboarding/candidate_creation.htmlrG)
r.rHr?�FILESrKrL�hiredrrurvr�candidates_viewr)rRrG�	candidaterVrVrW�candidate_creation�s
r�zrecruitment.change_candidatecCsltjj|d�}t|d�}|jdkr.t|j|j|d�}|��r.|��t	�
|td��tt
�St|dd|i�S)z�
    function used to update hired candidates .

    Parameters:
    request (HttpRequest): The HTTP request object.
    obj_id : recruitment id

    Returns:
    GET : return candidate update form template
    POST : return candidate view
    r@r�r?z*Candidate detail is updated successfully..z onboarding/candidate_update.htmlrG)r<rIrJr.rHr?r�rKrLrrurvrr�r)rRrSr�rGrVrVrW�candidate_update�s

r�zrecruitment.delete_candidatec
Cs�ztjj|d���t�|td��Wtt�Stjy+t�|td��Ytt�St	ya}z+t
�}|jD]}|�t
|jj��q8d�|�}t�|td�|���WYd}~tt�Sd}~ww)z�
    function used to delete hired candidates .

    Parameters:
    request (HttpRequest): The HTTP request object.
    obj_id : recruitment id

    Returns:
    GET : return candidate view
    r@z Candidate deleted successfully..zCandidate not found.�, zEYou cannot delete this candidate. The candidate is included in the {}N)r<rIrJr�rrurvr�r�r
rM�protected_objects�add�__�_meta�verbose_name�join�formatrr�)rRrS�e�models_verbose_name_sets�obj�models_verbose_name_strrVrVrW�candidate_delete�s.
��

�����r��onboarding.view_candidatestagec	Ks$tjj|d�}tjj|d���s_ztjj|jd��d�d}t||d��	�Wnt
y=t�|t
d�d|ji�Ynwtjj|jd�}r_|D]}tjj||d	���s^t||d	��	�qJ|j}tj}|||d
d�}	|j�d�}
|
r�t�|
�}t||�\}}
|
|	d<||	d
<|
|	d<t|d|	�S)zA
    Candidate individual view for the onboarding candidates
    r@�r�)rt�sequencer)r��onboarding_stage_idz%(recruitment)s has no stage..rT�r�r�T)rT�choicesr��single_view�requests_ids�previous�nextzonboarding/single_view.html)r<rIrJr3rN�existsr6rt�order_byrL�	Exceptionrr�rvr7r4�choicer��json�loadsrr)rRrA�kwargsr�r��tasksr�rTr��context�requests_ids_jsonr��previous_id�next_idrVrVrW�candidates_single_view�sj���
���
������
�r�cCst|t��}|�|�}|S)z-
    function used to paginate query set
    )r	r�get_page)�qryset�page_number�	paginatorrVrVrW�
paginator_qrys
r�zcandidate.view_candidatecCs|tjjdddd�}t|j|�}|j��}|j�d�}t|j|�}t	j�
�}t|�}tt|�t
|d||j|tj|||d��S)z�
    function used to view hired candidates .

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return candidate view  template
    TF��	is_activer��recruitment_id__closed�pagezonboarding/candidates_view.html)r�rG�pd�	gp_fields�mail_templates�hired_candidates�filter_dict)r<rIrNr8r��	urlencoderJr��qsrrwrrrrGr9�fields)rR�queryset�candidate_filter_obj�
previous_datar��page_objr��	data_dictrVrVrWr�s0�


��r�zrecruitment.view_candidate)�permcCsf|j��}tjjddd�}|j�d�dur|jdd�}t|j|d�j}t|dt	||j�d��|d	��S)
NTF)r�r�r��r��r�zcandidate/candidate_card.htmlr�)rOr�)
r�r�r<rIrNrJr8r�rr�)rRr�r�rVrVrW�hired_candidate_viewBs
���r�c	Cs�tjjdddd�}t|j|�j}|j��}|j�d�}t|�}t	t|�t
||d�}|j�d�}d}|dkrG|d	urGd
}t|||j�d�d�}t||�}t
|||||d��S)z�
    function used to filter hired candidates .

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return candidate view template
    TFr�r��orderby�fieldzonboarding/candidates.html�Nzonboarding/group_by.html)r�r�r�)r<rIrNr8r�r�r�rJrrr�general_group_byr�r)	rRr�r�r�r�r�r�rr�rVrVrW�candidate_filterWs0
�

�

�r�zrecruitment.view_recruitmentcCs�|��}|��r
dnd}|j�d�}|j�d�}|j�d�}t�}|s-t�|d�td�St	t
jj|d�j
d	d
d��}g}|D]}	|�|	j|	��|	jf�|	��q?|D]�}
t	t|�tg�B�}tjj|
d�}|jrvt�|t|�d
���qT|D]%}
t�|
�}t�||jjd��}|�|�}|�dt|iddd�jdf�qxt �!d�}t"jj|d�}|�#�r�|�$�}||_%d|_&d|_'d|_(|�)�nt"||d��)�t*d|�d|�d|��|||d��}t+d|j�d�||j,gd�}d|_-||_.z|�/�t�0|d �Wn"t1�y}zt2�3|�t�3|d!|j���WYd}~nd}~wwd
|_4|�)�zt5�}|j6j7�$�|_8||_9|�)�WqTt1�yR}zt2�3|�WYd}~qTd}~wwtd�S)"z�
    function used to send onboarding portal for hired candidates .

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return json response
    �https�http�ids�other_attachments�template_attachment_idszPlease choose candidates�)<script>window.location.reload()</script>rC�bodyT��flatr@z( has already been converted to employee.)r��self�DocumentF)�pathr�zapplication/pdf�r�rN)r��tokenz&onboarding/mail_templates/default.htmlz://z/onboarding/user-creation/)�portalr��host�protocolzHello z$, Congratulations on your selection!)�subjectr��to�htmlz!Portal link sent to the candidatezMail not send to ):�get_host�	is_securer?rPr�rr�infor�listrrIrN�values_list�append�name�read�content_type�closerMr<rJ�converted_employee_idrvr�Template�Contextryrzrrr{�secrets�	token_hexr5r��firstr�used�count�profilerLrr�email�content_subtype�attachmentsrxrur�r"r��
start_onboardr3rtr�r�r�)rRrrr�r�r��
email_backend�bodys�attachments_other�file�cand_idrr�r�template_bdyr��
render_bdyr�existing_portal�
new_portal�html_messagerr��onboarding_candidaterVrVrW�
email_send~s���
�
�
��

��	�
 ��
���r)cCs6g}|D]�}g}t|j|j��d�j�d�}g}|gd�}|D]C}|�|gd��t|j|jj	dd��j�d�}	d|j
t|j�}
t
|	d|j�|
�|
�j}|d	||d	<|d
d�|j��D�}qg}|d	}
|D]!}d}|
D]}|d
|kr�|�|�d}nqq|s�|�d
|i�qk|||d�}|�|�q|S)zE
    This method is used to make group of the onboarding records
    r�r�)rT�stages)�grouperr
T)�candidate_id__is_activer�r�r*cSsg|]}|jj�qSrV)r�rAr^rVrVrWras�z,onboarding_query_grouper.<locals>.<listcomp>Fr+)rTr*�employee_ids)r+r�r�rwr�r�rr*r�rN�stage_title�strrAr%rJ�object_list)rRr��groups�rec�	employeesr*�all_stages_grouperrOr~�stage_candidates�	page_namer+�ordered_data�groupers�foundrVrVrW�onboarding_query_grouper�sh��
���
��
�
���r:cCs�t|j�}|j}|j�d�s!|jd|jjgd�|j|jjgd�B}|jjj��}|D]}|j	rA|j	j
|vrA||jj|j	j
jd�B}q*|jdd���}|j�
d�}|sX|jdd	�}tj��}tj}|j��}t|�d
�d�}	|j�
d�}
|	�|
�}t||�}|D]}
t|
d
d|
d�t|
d
d|
d�qt|j���}|����D]\}}|ddks�|dkr�||=q�t|d|||||||d��S)z�
    function used to view onboarding main view.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return onboarding view template
    r�T�r��recruitment_managers__in��!onboarding_stage__employee_id__inr@r��closedF�r?rA�r�rTr*r-r�unknown�viewzonboarding/onboarding_view.html)�recruitments�rec_filter_obj�onboarding_stagesr�r��statusr�)r:r�r�ry�has_permrNrzr�rwr�rtrA�distinctrJr6rIr4r�r�r	r�r�r:�setattrr�copy�itemsr)rR�
filter_objrD�employee_tasksr�rGrFr�r�r�r�r�r1�itemr��key�valrVrVrWr�s`

�����



���r�cCs�t|j�}|j}|j�d�s!|jd|jjgd�|j|jjgd�B}|jjj��}|D]}|j	rA|j	j
|vrA||jj|j	j
jd�B}q*|jdd���}|j�
d�}|sX|jdd	�}tj��}tj}t�}|j��}	t|j|d
�}t|d�}
|j�
d�}|
�|�}t||�}
|
D]}t|d
d|d�q�t|j���}|����D]\}}|ddks�|dkr�||=q�t|d|||||||||	dd�
�S)Nr�Tr;r=r@r�r?Fr@r�rAr�rTr*rrBrCzonboarding/kanban/kanban.html)
rDrErFr�r��
stage_formrGr�r��card)r:r�r�ryrHrNrzr�rwr�rtrArIrJr6rIr4r�r0r�r	r�r:rJrrKrLr)rRrMrDrNr�rGrFr�rRr�r�r�r�r1rOr�rPrQrVrVrW�kanban_viewWsh

�����




���rTc
Cszktjj|d�}|r|jdurt|d�WS|jdkr td|�WS|j}tjj	|j
d���}t|d�}z|j
dkrLt|j|d�}|��rLt||||�WWSWnty^t�|td	��Ynwt|d
||jjjd��WSty�}z
t|�WYd}~Sd}~ww)
a
    function used to create user account in onboarding portal.

    Parameters:
    request (HttpRequest): The HTTP request object.
    token : random generated onboarding portal token

    Returns:
    GET : return user creation form template
    POST : return user_save function
    �rT�404.html��employee-bank-details��usernamer�r?z#User with email-id already exists..zonboarding/user_creation.html�rG�companyN)r5rIrJrrrrr�rrNrrr2rHr?rK�	user_saver�rr�rvrt�
company_idr)rRr�onboarding_portalr�ryrGr�rVrVrW�
user_creation�s:


������r`cCsN|jdd�}|jj|_|jj}|t|<d|_|��t�	|t
d��td|�S)z�
    function used to save user.

    Parameters:
    request (HttpRequest): The HTTP request object.
    onboarding_portal : onboarding portal object
    token : random generated onboarding portal token

    Returns:
    GET : return profile view
    FrY�zAccount created successfully..zprofile-view)rLr�rrZ�session�session_key�portal_userrrrurvr)rGr_rRrryrcrVrVrWr]�s

r]cCs�tjj|d���}|durt|d�S|j}|jdkr9|j�d�}|dur9||_	||_	d|_
|��t�
|td��t|d||j	||jjd	��S)
a
    function used to view user profile.

    Parameters:
    request (HttpRequest): The HTTP request object.
    token : random generated onboarding portal token

    Returns:
    GET : return user profile template
    POST : update profile image of the user
    rUNrVr?r�z&Profile picture updated successfully..zonboarding/profile_view.html)r�rrr\)r5rIrNrrr�rHr�rJrrrLrrurvrtr^)rRrr_r�rrVrVrW�profile_view�s*

��rfcCs�tjj|d���}|durt|d�S|j}|j|j|j|j	d�}|j
j}t|}t
jj|d���r=t�|td��td�St
jj|d���durjt
jj|d���}|jr`t�|td	��td�St
jj|d���j}t|d
�}|jdkr�t
jj|d���}	t|j|	d�}|��r�|��t||�|jd
d�}
||
_|j|
_|j|
_d|
_|
��|jj }t!jj|
d���}|r�|nt!�}
|
|
_"||
_ |j#|
_$|j|
_|
��d|_%|��t�|td��td|�St|d||j&j'd��S)a#
    function used to create employee.

    Parameters:
    request (HttpRequest): The HTTP request object.
    token : random generated onboarding portal token.

    Returns:
    GET : return employee creation profile template.
    POST : return employee bank detail creation template.
    rUNrV)�employee_first_name�phone�address�dob)rz&Employee with email id already exists.rr\zEmployee already exists..r�r?r�FrYT�rBrWz0Employee personal details created successfully..rXz!onboarding/employee_creation.html)rGr`)(r5rIrNrrr�r
�mobilerirjrbrcrdrr�rrurvr�employee_bank_details�__dict__r-rHr?rKrLrr]rr�employee_profile�is_from_onboarding�job_position_idrrB�joining_date�date_joiningrrtr^)rRrr_r�r�rcryr`rGr��employee_personal_info�job_position�existing_work_info�	work_inforVrVrW�employee_creation�s|
��
�
����
�rxcCs�tjj|d�}tjj|jjd���}tjj|d���}t	jj|d���}t
|d�}|jdkrCt
|j|d�}|�
�r?t|||�Stt�St|d||jjjd��S)	a/
    function used to create employee bank details creation.

    Parameters:
    request (HttpRequest): The HTTP request object.
    token : random generated onboarding portal token

    Returns:
    GET : return bank details creation template
    POST : return employee_bank_details_save function
    rUrYr\rkr�r?z%onboarding/employee_bank_details.htmlr[)r5rIrJrrNr�rrrrr,rHr?rK�employee_bank_details_saver�welcome_aboardrrtr^)rRrr_ryr`�	bank_inforGrVrVrWrmJs(

���rmcCsj|jdd�}tjj|jd�}||_|j}||_|��|��d|_d|_	|��t
�|td��t
t�S)z�
    function used to save employee bank details.

    Parameters:
    request (HttpRequest): The HTTP request object.
    form : Form object.
    onboarding_portal : Onboarding portal object.

    Returns:
    GET : return welcome onboard view
    FrYr\rATz,Employee bank details created successfully..)rLrrIrJryrBr�rrrrrurvrrz)rGrRr_�employee_bank_detailr`r�rVrVrWrymsrycCs
t|d�S)z�
    function used to view welcome aboard.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return welcome onboard view
    zonboarding/welcome_aboard.html)r)rRrVrVrWrz�s
rzr?zonboarding.change_candidatetaskcCs@|j�d�}|j�d�rtjj|d�}n|j�d�}tjj|d�}tjj|d�}tjj||d���}||_|�	�dd�|j
j��D�}t
j|jj|d|j
�d	|j�d
|j�d�d|j
�d
|j�d|j�d�d|j
�d|j�d|j�d�d|j
�d|j�d|j�d�d|j
�d|j�d|j�d�dtd�d�	ttd�dd��S)z�
    function used to update candidate task.

    Parameters:
    request (HttpRequest): The HTTP request object.
    obj_id : candidate task id

    Returns:
    POST : return candidate task template
    rGr�r@�candIdr�cSr[rVr\r^rVrVrWra�r�z)candidate_task_update.<locals>.<listcomp>z	The task z of            z was updated to �.uتم تحديث المهمة u للمرشح � إلى zDie Aufgabe z des Kandidaten � wurde auf � aktualisiert.z	La tarea z del candidato � se ha actualizado a u
La tâche z
 du candidat � a été mise à jour à rhrirjz!Candidate onboarding task updatedru��message�type)r?rJr4rIr7r<rNrrGrLr�rBrwr&rxryrzr�rr
rv)rR�taskIdrG�candidate_task�canIdr�r�rrVrVrW�candidate_task_update�sD��
�
����r�c		Csv|j�d�}|j�d�}tjj|d�}tjj|d�}tjj|d�}tjj||d���}|j	}t
|d|||dtjd��S)z�
    htmx function that return the status of candidate task

    Parameters:
    request (HttpRequest): The HTTP request object.
    task_id : Onboarding task id

    Returns:
    POST : return candidate task template
    r"�
cand_stager@r��onboarding/candidate_task.htmlT�rGr�r��second_loadr�)r�rJr3rIr7r<r4rNrrGrr�)	rRr�r"r��cand_stage_objr�r�r�rGrVrVrW�
get_status�s*����r�c	Cs�|j�d�}|j�d�}|j�d�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}tjj|||d�\}	}
|	�	�|j
�|�t|d|	j
||dtjd��S)	z�
    htmx function that used to assign a onboarding task to candidate

    Parameters:
    request (HttpRequest): The HTTP request object.
    task_id : Onboarding task id

    Returns:
    POST : return candidate task template
    r�r"r�r@r�r�Tr�)r�rJr3rIr7r<r6r4�
get_or_createrLr�r�rrGr�)rRr�r�r"r�r�r�r�r�r��createdrVrVrW�assign_task�s0

���r�z onboarding.change_candidatestagec
Cs^|j�d�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}||_|�	�tj�
�}tj}	dd�|jj
�
�D�}
|j�d�dur�tj|jj|
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
�dtd�d�	t||�}|D]}t|dd|d�t|d|dd||	d��Sttd�dd��S)z�
    function used to update candidate stage.

    Parameters:
    request (HttpRequest): The HTTP request object.
    candidate_id : Candidate id
    recruitment_id : Recruitment id

    Returns:
    POST : return candidate task template
    r~r@r�cSr[rVr\r^rVrVrWra'r�z*candidate_stage_update.<locals>.<listcomp>�is_ajaxNz
The stage of z                  was updated to r~u(تم تحديث مرحلة المرشح rzDie Phase des Kandidaten r�r�zLa etapa del candidato r�uL'étape du candidat r�rhrirjrTr*� onboarding/onboarding_table.htmlr�rTrFr��"Candidate onboarding stage updatedrur�)r?rJr=rIrNr6r<r3r�rLrwr4r�rBr&rxryrzr�rr:rJrr
rv)
rRr�rtr�rDr~r��candidate_stagerFr�rr1rOrVrVrW�candidate_stage_updatesP

�
��

��	�r�c
Cs�|jd}|jd}t�|�}|jd}tj��}tjjt|�d�}t	j
}tjj|d�j|d�d}d}	|r:d	}d
}	t
||�}
|
D]}t|dd|d�qAt|d|
d
d||d��}t|j�d�d|�d|	�d��S)Nr�rTr~r@)�candidate_id__id__in)r�r	zNo candidates selectedruz$Candidate stage updated successfullyr*r�rr�rrzW<div><div class="oh-alert-container"><div class="oh-alert oh-alert--animated oh-alert--z">z</div> </div></div>)r?r�r�r6rIrwr=rN�intr4r�r3�updater:rJrrr{r|)
rR�candiate_ids�
recrutment_id�candidate_id_listr~rFrDr�r�r�r1rOr�rVrVrW�candidate_stage_bulk_updateIs>




�

��

��r�cCsR|jd}t�|�}|jd}|jd}tjj||d�j|d�}ttd�dd��S)	Nr�r�rG)r�r��rGr�rur�)	r?r�r�r4rIrNr�r
rv)rRr�r�r�rGrrVrVrW�candidate_task_bulk_updateqs



���r�c

Cs�g}g}g}g}tjjddd�}|D]D}t�dd�}t�dd�}t�dd�}	|�d|�d|�d|	�d��|�d	|�d|�d|	�d
��|�|j�|�|jjdd����qt	||||t
d�d
�dd�S)z�
    function used to show onboard started candidates in recruitments.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return Json response labels, data, background_color, border_color.
    FT)r?r�r��rgba(r�z, 0.2�rgb(�)�rz#No records available at the moment.)�labelsrO�background_color�border_colorr���safe)r=rIrN�random�randintrr�r�rr
rv)
rRr�rOr�r�rDrT�red�green�bluerVrVrW�onboard_candidate_chart�s,��r�cCsL|jd}|jd}tjj|d�}||_|��tdtd�j|j	d�d��S)z+
    Ajax method to update joinng date
    r}�dater@ruz0{candidate}'s Date of joining updated sussefully)r��r�r�)
r?r<rIrJrrrLr
rvr�r
)rRr"r��
candidate_objrVrVrW�update_joining�s

���r�cCsptj��jddd�}tj��}|jdd�}tjjdd�}|jddd�}t|�|||tt|��d�}t|d|d�S)	Nr�Tr�r��job_position_id__job_position)rTr�r��onboard_candidates�
job_positionszonboarding/dashboard.html)r�)	r=rIrwrr<rNr
rMr)rRrTr�r�r�r�r�rVrVrW�view_dashboard�s
�
�r�c
Cs�|j�d�}tjj|d�jddd�}t|�}g}g}g}|D]A}t�dd�}t�dd�}t�dd�}	|�	d|�d	|�d	|	�d
��|�	d|�d	|�d	|	�d��t
jj||d
���}
|�	|
�q|||||td�d�}t
|�S)NrT)�recruitment_id__titler.Tr�rr�r�r�z, 0.3r�r�)� onboarding_stage_id__stage_title�*onboarding_stage_id__recruitment_id__titlez$No candidates started onboarding....)r�rOrTr�r�r�)r�rJr6rIrNrr
r�r�rr3rrvr
)rRrTr��candidate_countsr�r��labelr�r�r�rr�rVrVrW�dashboard_stage_chart�s>�����r�cCsrt�|jd�}d}|��D]\}}tjj|d�}|j|kr'||_|��d}q|r3t	t
d�dd��St	dd	i�S)
zA
    This method is used to update the sequence of candidate
    �sequenceDataFr@TzCandidate sequence updatedr	r�r��fail)r�r�r?rLr3rIrJr�rLr
rv)rR�
sequence_data�updatedr"�seqr�rVrVrW�candidate_sequence_update�s
��r�zrecruitment.change_stagecCsrt�|jd�}d}|��D]\}}tjj|d�}|j|kr'||_|��d}q|r3t	dt
d�d��St	dd	i�S)
zB
    This method is used to update the sequence of the stages
    r�Fr@TruzStage sequence updatedr�r�r�)r�r�r?rLr6rIrJr�rLr
rv)rRr�r�r�r�r~rVrVrW�stage_sequence_update	s
�r�cCs:tjj|d�}|jd|_|��td�}td|�d��S)zE
    This method is used to update the name of recruitment stage
    r@r~z-The stage title has been updated successfullyz[<div class="oh-alert-container"><div class="oh-alert oh-alert--animated oh-alert--success">z</div></div>)r6rIrJr?r.rLrvr)rRr�rUr�rVrVrW�stage_name_updates
�r�c
Cstjj|d�}|j}t|dd|i�}t�}|j}|r5z|jj�	��d|jjj�d�}Wn	t
�t�Y|j
dkr�|jd}|jd}t�t��'t||||gd	d
�}	|	dkrat�|td��nt�|td
��Wd�n1sswYt|j�d�d�S|S)zP
    This method is used to send mail to the candidate from onboarding view
    r@zonboarding/send_mail_form.htmlr�z <�>r?rr�F)�
fail_silentlyrazMail sent successfullyzSomething went wrongNrrrs)r<rIrJrrr�$dynamic_from_email_with_display_nameryrz�
get_full_namer"r�r�rHr?�
contextlib�suppressrrrurvrr{r|)
rRr�r��candidate_mailr�r�display_email_namerr��resrVrVrW�onboarding_send_mail.s@
�"


����r�cCs:|j�d�}|jd}tjj|d�j|d�tddd��S)z>
    This method is used to update the probotion end date
    r��
probation_endrC)r�zProbation end date updatedrur�)r�rPr<rIrNr�r
)rRr�r�rVrVrW�update_probation_endXs
r�cCs�|j�d�}|s
|jjj}tjj|ddd���}g}|D]5}|�	||j
��|j
jdd���|j
jdd���|j
jdd���|j
jd	d���|j
jd
d���d��qt|dd
|i�S)z6
    This method is used to show the task report.
    rBTF)�employee_id__id�candidates__is_active�"candidates__recruitment_id__closed�todor��	scheduled�ongoing�stuck�done)r��total_candidatesr�r�r�r�r�z%onboarding/dashboard/task_report.htmlr�)
r�rJryrzrAr7rIrNrIrr�rr)rRrB�my_tasksr�r�rVrVrW�task_reportds.
����r�zonboarding.view_candidatetaskcCs(|jd}tjj|d�}t|dd|i�S)zM
    This method is used to render template to show the onboarding tasks
    r�)�onboarding_task_id__idz%onboarding/dashboard/status_list.html�candidate_tasks)r�r4rIrNr)rRr�r�rVrVrW�candidate_tasks_status�s
�r�cCs@|jd}tjj|d�}|jd}|dvr||_|��td�S)z5
    This method is to update the candidate task
    r�r@rG)r�r�r�r�r��Success)r�r4rIrJrGrLr)rRr�r�rGrVrVrW�change_task_status�s

r�zrecruitment.change_recruitmentcCs@|jd}|jd}tjj|d�}|dvr||_|��td�S)z?
    This method is used to update the offer letter status
    r�rGr@)�not_sent�sent�accepted�rejected�joinedr�)r�r<rIrJ�offer_letter_statusrLr)rRr�rGr�rVrVrW�update_offer_letter_status�s

r�z!recruitment.add_rejectedcandidatecCs�|j�d�}d}|rtjj|d���}td|i|d�}|jdkr<t|j|d�}|�	�r<|�
�t�}t�|d�t
d�St|d	d
|i�S)zF
    This method is used to add candidates to rejected candidates
    r�Nr�)r�r�r?r�zCandidate reject reason savedr�zonboarding/rejection/form.htmlrG)r�rJr>rIrNrr;rHr?rKrLrrurr)rRr�r�rGrVrVrW�add_to_rejected_candidates�s�
r�cCsN|j�d�}tjjdddd�}}dd�|D�}|��}||d�}t|dd�S)	z9
    This method is used for select all in candidate
    r�TF�r�r�r�cS�g|]}t|j��qSrV�r/rA�r_�emprVrVrWra��z$candidate_select.<locals>.<listcomp>�r-�total_countr�)r�rJr<rIrNrr
)rRr�r3r�r-r�r�rVrVrW�candidate_select�s
�
r�c	Cs~|j�d�}|j�d�}|rt�|�ni}|dkr=t|tjjdddd�d�}|j}dd	�|D�}|�	�}||d
�}t
|�SdS)z?
    This method is used to select all filtered candidates
    r�rNrwTFr�r�cSr�rVr�r�rVrVrWra�r�z+candidate_select_filter.<locals>.<listcomp>r�N)r�rJr�r�r8r<rIrNr�rr
)	rRr��filtered�filtersr��filtered_candidatesr-r�r�rVrVrW�candidate_select_filter�s$��

�r�cCs�t�|j�dg��}|j�d�}|D]6}z)tjjt|�d���}|j	|kr3||_	|�
�t�|d�n	t�
|d�|��Wqt�
|d�Yqtddd	�S)
zE
    This function is used to bulk update the offerletter status
    r�rGr@z(offer letter status updated successfullyzStatus already in {} status�Candidate doesnot existruFr�)r�r�r�rJr<rIrNr�rr�rLrrur�r�r
�rRr�rGrAr�rVrVrW�offer_letter_bulk_status_updates
�r�cCszt�|j�dg��}|j�d�}|D]$}ztjjt|�d���}|�	�t
�|d�Wqt
�|d�Yqt
ddd�S)	zD
    This function is used to bulk delete onboarding candidates
    r�rGr@zcandidate deleted successfullyr�ruFr�)r�r�r�rJr<rIrNr�rr�rrur�r
r�rVrVrW� onboarding_candidate_bulk_deletesr�)��__doc__r�r��loggingr�r�urllib.parser�djangor�django.contribr�django.contrib.authr�django.contrib.auth.modelsr�django.core.mailrr�django.core.paginatorr	�django.db.modelsr
�django.httprrr
�django.shortcutsrr�django.template.loaderr�django.urlsr�django.utils.translationrr�rrv�django.views.decorators.httpr�
base.backendsr�base.methodsrrrrr�base.modelsrr�employee.modelsrrr�horillar �horilla.decoratorsr!r"r#r$�horilla.group_byr%r��notifications.signalsr&�onboarding.decoratorsr'r(r)�onboarding.filtersr*r+�onboarding.formsr,r-r.r/r0r1r2�onboarding.modelsr3r4r5r6r7�recruitment.filtersr8r9r:�recruitment.formsr;�recruitment.modelsr<r=r>�recruitment.pipeline_grouper�	getLogger�__name__rXrQr�r�r�r�r�r�r�r�r�r�r�r�r�r)r:r�rTrdr`r]rfrxrmryrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rVrVrVrW�<module>sf
$	
$2@? 5	%$e5;>($N#

,
"&7%
# 
'





Youez - 2016 - github.com/yon3zu
LinuXploit