
    si                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZmZ dd
lmZmZ ddlmZmZ ddlmZmZ  eed       e ed      d       G d de                    Z eed       e ed      d       G d de                    Z eed       e ed      d       G d de                    Z eed       e ed      d       G d de                    Zy)z?
This page handles the cbv methods for recruitment survey page
    )Any)forms)messages)HttpResponse)render)method_decorator)gettext_lazy)login_requiredpermission_required)HorillaDetailedViewHorillaFormView)QuestionFormTemplateForm)RecruitmentSurveySurveyTemplatedispatch)namez!recruitment.add_recruitmentsurveyc                   R     e Zd ZdZeZeZ ed      Z	dZ
 fdZdedef fdZ xZS )QuestionFormViewz%
    form view for create button
    zSurvey Questions'cbv/recruitment_survey/survey_form.htmlc                     t        |   di |}| j                  j                  j                  rt        d      | j                  _        |S )NzUpdate Survey Questions )superget_context_dataforminstancepk_
form_classverbose_name)selfkwargscontext	__class__s      F/var/www/python-projects/worksol/recruitment/cbv/recruitment_survey.pyr   z!QuestionFormView.get_context_data"   s?    '*4V499  +,-F+GDOO(    r   returnc                    |j                         r|j                  j                  rt        d      }nt        d      }|j	                  d      }|j	                          |j
                  j                  |j                         |j                  j                  |j                  d          t        j                  | j                  t        |             t        d      S t        | =  |      S )NzSurvey question updated.New survey question created.Fcommittemplate_id)<script>window.location.reload()</script>)is_validr   r   r   saverecruitment_idssetrecruitmentr,   cleaned_datar   successrequestr   r   
form_validr!   r   messager   r$   s       r%   r6   zQuestionFormView.form_valid(   s    ==?}}67:;yyy.HMMO$$(()9)9:  $$T%6%6}%EFT\\1W:6 KLLw!$''r&   __name__
__module____qualname____doc__r   r   r   modelr   new_display_titletemplate_namer   r   r6   __classcell__r$   s   @r%   r   r      sB    
 JE,-=M(| ( ( (r&   r   c                   R     e Zd ZdZeZeZ ed      Z	dZ
 fdZdedef fdZ xZS )QuestionDuplicateFormViewz2
    form view for create duplicate for asset
    zDuplicate Survey Questionsr   c                    t        |   di |}t        j                  j	                  | j
                  d         }| j                  |      }|j                  j                         D ]{  \  }}t        |t        j                        s!|j                  r|j                  }n|j                  j	                  |d       d}||j                  |<   ||j                  |   _        } ||d<   t        d      | j                  _        |S )	Nobj_id)idr    z (copy)r   	Duplicater   )r   r   r   objectsgetr"   r   fieldsitems
isinstancer   	CharFieldinitialr   r    )	r!   r"   r#   original_objectr   
field_namefieldinitial_valuer$   s	           r%   r   z*QuestionDuplicateFormView.get_context_dataE   s    '*4V4+33774;;x;P7Q8!%!2!2!4 	@J%1==$)MMM'+||'7'7
B'G&H$PM+8Z(2?J'/	@ '(~$r&   r   r'   c                    |j                         rt        d      }|j                  d      }|j                          |j                  j	                  |j
                         |j                  j	                  |j                  d          t        j                  | j                  t        |             t        d      S t        | 5  |      S )Nr)   Fr*   r,   r-   )r.   r   r/   r0   r1   r2   r,   r3   r   r4   r5   r   r   r6   r7   s       r%   r6   z$QuestionDuplicateFormView.form_validU   s    ==?67Gyyy.HMMO$$(()9)9:  $$T%6%6}%EFT\\1W:6 KLLw!$''r&   r9   rB   s   @r%   rD   rD   7   sB    
 JE67=M 	(| 	( 	( 	(r&   rD   zrecruitment.add_surveytemplatec                   P     e Zd ZdZeZeZddZde	de
f fdZdede
f fdZ xZS )SurveyTemplateFormViewz8
    form view for create and edit survey templates
    c                    | j                   j                  j                  d      }t        j                  j                  |      j                         }| j                   j                  s#| j                  |      | _	        | j                  S | j                  | j                   j                  |      | _	        | j                  S )Ntitle)rZ   rH   )
r5   GETrL   r   rK   filterfirstPOSTr   r   )r!   r   rZ   r   s       r%   get_formzSurveyTemplateFormView.get_formm   s      $$W-!))00u0=CCE||  :DI yy (9(9HMDIyyr&   r   r'   c                     |j                         s>|j                  j                         }t        | j                  | j
                  ||d      S t        |   |      S )N)r   errors)r.   ra   as_datar   r5   r@   r   form_invalid)r!   r   ra   r$   s      r%   rc   z#SurveyTemplateFormView.form_invalidw   sS    }}[[((*Fd00462R  w#D))r&   c                     |j                         rOt        d      }|j                          t        j                  | j
                  t        |             t        d      S t        | !  |      S )NzTemplate savedz*<script>window.location.reload();</script>)	r.   r   r/   r   r4   r5   r   r   r6   )r!   r   r8   r$   s      r%   r6   z!SurveyTemplateFormView.form_valid   sT    ==?()GIIKT\\1W:6 LMMw!$''r&   )N)r:   r;   r<   r=   r   r   r   r>   r_   r   r   rc   r6   rA   rB   s   @r%   rX   rX   a   sD    
 JE* * *(| ( ( (r&   rX   c                       e Zd ZdZeZ ed      Z ed      df ed      df ed      df ed	      d
f ed      ddfgZddddZ	ddiZ
ddddddddgZy)RecruitmentSurveyDetailViewz!
    detail view of the page
    DetailsQuestionquestionzQuestion Typeget_question_typeSequencesequenceRecruitmentrecruitment_colOptionsoptions_colTrI   )rZ   subtitleavatar   Editzcreate-outlinea  
                     class="oh-btn oh-btn--info w-50"
                     hx-get="{get_edit_url}"
                     hx-target ="#genericModalBody"
                     data-target = "#genericModal"
                     data-toggle ="oh-modal-toggle"
                     )actioniconattrsDeleteztrash-outlinez
                    class="oh-btn oh-btn--danger w-50"
                    href ="{get_delete_url}"
                    onclick="return confirm(' Are you sure want to delete?')"
                    N)r:   r;   r<   r=   r   r>   r   rZ   bodyheadercolsactionsr   r&   r%   rf   rf      s    
 EiLE	
:
#	
?	01	
:
#	
=	,-	
9}d+D "rR@FD $
	
 #	
Gr&   rf   N) r=   typingr   djangor   django.contribr   django.httpr   django.shortcutsr   django.utils.decoratorsr   django.utils.translationr	   r   horilla_views.cbv_methodsr
   r   horilla_views.generic.cbv.viewsr   r   recruitment.formsr   r   recruitment.modelsr   r   r   rD   rX   rf   r   r&   r%   <module>r      s     # $ # 4 6 I P 8 @ .z2;<:( ( 3(> .z2;<:#( #( 3#(L .z289
 (_  ( 3 (F .z289
("5 ( 3(r&   