
    vg                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZmZmZ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 ddlmZmZmZm Z m!Z! ddl"m#Z# ee ed      d                      Z$ee ed      d                      Z%ee ed      d                      Z&ee ed      d                      Z'ee ed      d                      Z(y)zH
search.py

This module is used to register search/filter views methods
    N)parse_qs)User)	Paginator)render)get_key_instancesget_paginationsortby)hx_request_requiredis_recruitment_managerlogin_requiredpermission_required)group_by_queryset)CandidateFilterRecruitmentFilterStageFilterSurveyFilterSurveyTemplateFilter)	CandidateRecruitmentRecruitmentSurveyStageSurveyTemplate)paginator_qryzrecruitment.view_recruitment)permc           
      N   | j                   s+| j                   j                         j                  ddi       t        j                  j                         }| j                   j                  d      s t        j                  j                  d      }t        | j                   |      }| j                   j                         }t        | |j                  d      }t        |      }t        t        |       t        | dt        || j                   j                  d            ||d      S )	z3
    This method is used to search recruitment
    	is_activeonTr   orderbyz&recruitment/recruitment_component.htmlpage)datapdfilter_dict)GETcopyupdater   objectsallgetfilterr   	urlencoder	   qsr   r   r   r   )requestqueryset
filter_objprevious_datarecruitment_obj	data_dicts         ,/var/www/horilla/recruitment/views/search.pyrecruitment_searchr4   (   s     ;;!!;"56""&&(H;;??;'&&---="7;;9JKK))+MWjmmY?O'Ik9-0!/7;;??63JK$	
     zrecruitment.view_stagec           
         t         j                  j                  d      }t        | j                  |      j
                  }| j                  j                         }t        | |d      }t        |      }t        t         |       t        |d| j                  j                  d      d      }t        | dt        || j                  j                  d            |||d      S )	z-
    This method is used to search stage
    T)recruitment_id__is_activer   recruitment_idrpagezstage/stage_group.htmlr    )r!   recruitmentsr"   r#   )r   r'   r*   r   r$   r,   r+   r	   r   r   r   r)   r   r   )r-   r.   stagesr0   r2   r:   s         r3   stage_searchr<   E   s     }}##d#CHh/22FKK))+MGVY/F'IeY'$ '++//'":GL  !&'++//&*AB($		
	 	r5   zrecruitment.view_candidatec           
         | j                   j                         }| j                   j                  d      }|d}t        j                  j                  |      }t        | j                   |      j                  }g }| j                   j                  d      st        |      }t        t        |       d}| j                   j                  d      dk(  rd	}t        | |d
      }| j                   j                  d      }|dk7  r,|*t        ||| j                   j                  d      d      }d}n'|D cg c]  }|j                   c}| j                  d<   t        || j                   j                  d            }t        t        j                  j!                  dd            }t        t"        j                  j                  |      j!                  dd            }	t%        | ||||||	d      S c c}w )zS
    This method is used to search candidate model and return matching objects
    search )name__icontainsr.   	dashboardcandidate/candidate_card.htmlviewlistcandidate/candidate_list.htmlr   fieldr    zcandidate/group_by.htmlfiltered_candidatesemailTflat)username__in)r!   r"   r#   rG   emp_list)r$   r+   r)   r   r'   r*   r   r,   r   r   r	   general_group_byidsessionr   rE   values_listr   r   )
r-   r0   r>   
candidatesr2   templaterG   	candidatemailsexisting_emailss
             r3   candidate_searchrW   b   s    KK))+M[[__X&F~""))&)AJ zBEEJI;;??;']+	)Y/.H{{v&(2Y7JKKOOG$E{u(%w{{v6

 - +52
&ILL2
-. z7;;??6+BCJ""..wT.BCE/;;G$;OO $'	

 
2
s   2G1c                    t         j                  j                  d      }d}| j                  j	                  d      dk(  rd}| j                  j                         }t        | j                  |      }t        |j                  d      }| j                  j	                  d	      }|j                  |      }t        | |||d
      S )zI
    This method is used for filter,pagination and search candidate.
    Tr   rC   rD   rE   rF   rA      r    )r!   r"   )r   r'   r*   r$   r)   r+   r   r   r,   get_pager   )r-   rR   rS   r0   r/   	paginatorpage_numberpage_objs           r3   candidate_filter_viewr^      s     ""))D)9J.H{{v&(2KK))+M zBJ*--,I++//&)K!!+.H/ r5   z"recruitment.view_recruitmentsurveyc                    t         j                  j                         }g }|D ]V  }|j                  j                         D ]7  }| j                  j
                  |k(  s|j                  |j                         9 X | j                  j                  d      rt        j                  j                         }n t        j                  j                  |      }| j                  j                         }t        | j                  |      }|j                  }t        |j                  d      j!                         d| j                  j#                  d      dt%                     }g }	|D ]  }
|	j                  |
        t'        | j                        j                  }|j)                  dd	
      }|j)                  dd	
      }t+        t-        |      t-        |      z
        }g }|D ]  }|j                  |g dd        |	|z   }	t/        |	| j                  j#                  d            }t/        || j                  j#                  d            }t1        j2                  t/        || j                  j#                  d            j4                  D cg c]  }|j                   c}      }t7        |      }t9        t        |       t;        | dt/        || j                  j#                  d            |||||d      S c c}w )zF
    This method is used to filter/search the recruitment surveys
    view_recruitmentsurvey)recruitment_ids__inF)template_id__isnulltemplate_id__titletemplate_page)r    	page_namerecords_per_pagetitleTrJ   r?   )grouperrE   dynamic_namesurvey_template_pager    zsurvey/survey_card.html)	questions	templatessurvey_templatesr"   r#   requests_ids)r   r'   r(   recruitment_managersuseremployee_getappendrO   has_permr   r*   r$   r+   r   r,   r   distinctr)   r   r   rQ   rE   setr   jsondumpsobject_listr   r   r   )r-   recsidsimanagerrk   r0   r/   rl   all_template_object_listrS   rm   all_templatesused_templatesunused_templatesunused_groupstemplate_nameinstancern   r2   s                       r3   filter_surveyr      s    ""$D
C !--113 	!G||((G3

144 	!! ||56%--113	%--444M	KK))+Mgkk95JI!U3<<>[[___-!')I  " 2 ''12 ,GKK8;;$00t0DM**+?d*KNC.^1DDEM) 
( "	

  8-G '++///"BI %'++//*@A :: *7;;??62k		
 KK	
L 'I'3!&y'++//&2IJ" 0$(	
 	
s   K9))__doc__rv   urllib.parser   django.contrib.auth.modelsr   django.core.paginatorr   django.shortcutsr   base.methodsr   r   r	   horilla.decoratorsr
   r   r   r   horilla.group_byr   rN   recruitment.filtersr   r   r   r   r   recruitment.modelsr   r   r   r   r   recruitment.views.paginator_qryr   r4   r<   rW   r^   r    r5   r3   <module>r      s"    ! + + # B B  / B   : 89 :  4 23 4  4 672 8  2j 67 8  * ABI C  Ir5   