ó
2í¬fc           @   sæ  d  d l  m Z m Z d  d l m Z m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l Td  d	 l Td  d	 l Td  d	 l Td  d
 l m Z d  d	 l Td  d l m Z d  d l m Z d  d	 l Te d „  ƒ Z e d „  ƒ Z  e d „  ƒ Z! e d „  ƒ Z" e d „  ƒ Z# e d „  ƒ Z$ e d „  ƒ Z% e d „  ƒ Z& e d „  ƒ Z' e d „  ƒ Z( e d „  ƒ Z) e d „  ƒ Z* e d „  ƒ Z+ d „  Z, d „  Z- e d „  ƒ Z. d S(   iÿÿÿÿ(   t   rendert   get_object_or_404(   t   HttpResponseRedirectt   Http404t   HttpResponse(   t   reverse(   t   messages(   t   slugify(   t   permission_required(   t   csrf_exempt(   t   default_storage(   t   *(   t   Payment(   t   ContentBlock(   t   datetimec         C   s   t  t d | ƒ} t  t d |  j ƒ} y t j j d | d | ƒ } Wn t j k
 rb t } n Xt	 |  d i | d 6| d 6ƒ S(   Nt   slugt   usert   membert   exams(   public/exam_application/application.htmlt	   exam_formt   exam_application(
   R   t   ExamFormt   MemberR   t   ExamApplicationt   objectst   gett   DoesNotExistt   FalseR    (   t   requestt	   form_slugR   R   R   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyR      s    
c         C   sà   t  t d | ƒ} t  t d |  j ƒ} yg t j j d | d | ƒ } | j ra t j	 |  d ƒ n t j	 |  d ƒ t
 t d d | j g ƒƒ SWn3 t j k
 rÃ t d | d | ƒ } | j ƒ  n Xt
 t d	 d | j g ƒƒ S(
   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.sP   You have an application in progress, you can resume this using the button below.R   t   argst   exam_application_applicant(   R   R   R   R   R   R   R   t   completeR   t   errorR   R   R   R   t   save(   R   R   R   R   R   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   start_application)   s    	 c         C   sí   t  t d | ƒ} t  t d |  j ƒ} yt t j j d | d | ƒ } | j ra t j	 |  d ƒ n9 | j
 ƒ  t d | d | ƒ } | j ƒ  t j |  d ƒ Wn3 t j k
 rÐ t d | d | ƒ } | j ƒ  n Xt t d d | j g ƒƒ S(	   NR   R   R   R   s9   Sorry, you cannot restart an already complete applications   Application has been Restarted.R   R   (   R   R   R   R   R   R   R   R    R   R!   t   deleteR"   t   successR   R   R   R   (   R   R   R   R   R   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   restart_application<   s    	

c         C   s/  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ St d | ƒ } |  j r
t |  j d | ƒ} | j ƒ  r
yM | j ƒ  t j |  d	 ƒ d
 | _ | j ƒ  t t	 d d | j
 g ƒƒ SWqqXq
n  t |  d i | d 6| d 6| d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   t   instances   Information Savedi   t   exam_application_academics.   public/exam_application/applicant-details.htmlR   t   applicant_details_form(   R   R   R   R   R   R    R   R!   R   R   R   t   ApplicantDetailsFormt   POSTt   is_validR"   R%   t   statusR    (   R   R   R   R   R   R)   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   applicant_detailsQ   s&    		
	
 
c         C   sÏ  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ St d | ƒ } t d | ƒ } |  j r£t |  j |  j d | ƒ} t |  j |  j d | ƒ} |  j j d	 ƒ r;| j ƒ  r | j ƒ  t j |  d
 ƒ d | _ | j ƒ  t t	 d d | j
 g ƒƒ Sq£| j ƒ  r| j ƒ  t j |  d
 ƒ d | _ | j ƒ  t t	 d d | j
 g ƒƒ St j |  d ƒ n  t |  d i | d 6| d 6| d 6| d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   R'   t   non_degree_applicants   Information Savedi   t   exam_application_theorys   Form is not valids-   public/exam_application/academic-details.htmlR   t   academic_details_formt   non_degree_evidence_form(   R   R   R   R   R   R    R   R!   R   R   R   t   AcademicDetailsFormt   NonDegreeEvidenceFormR+   t   FILESR   R,   R"   R%   R-   R    (   R   R   R   R   R   R1   R2   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   academic_detailsm   s4    		
	

	
c   
      C   sè  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ S| j } g  } x. t d d	 ƒ D] } | j | ƒ | d
 } q“ Wt d | ƒ } t d | ƒ }	 |  j r¼t |  j d | ƒ} t |  j |  j d | ƒ}	 | j ƒ  r¼y• | j ƒ  |	 j ƒ  t j |  d ƒ | j d k r|d	 | _ | j ƒ  t t	 d d | j
 g ƒƒ Sd | _ | j ƒ  t t	 d d | j
 g ƒƒ SWq¹q¹Xq¼n  t |  d i | d 6| d 6| d 6|	 d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   i    i   i   R'   s   Information Saveds   re-validationt   exam_application_examineri   t   exam_application_modalitiess)   public/exam_application/theory-exams.htmlR   t   yearst   exam_results_form(   R   R   R   R   R   R    R   R!   R   R   R   t
   start_yeart   ranget   appendt
   TheoryFormt   TheoryResultsLetterFormR+   R5   R,   R"   R%   t   typeR-   R    (
   R   R   R   R   R   t   yearR9   t   it   theory_formR:   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   theory_exams™   s>    			

	
	
 
c      
   C   s«  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ St j j d | ƒ } |  j r†t j j d | ƒ } | j ƒ  t j j d | ƒ } | j ƒ  t } xe| D]]}	 t d | d	 |	 ƒ }
 |
 j ƒ  |  j j d
 |	 j ƒ rŸy] t |  j d
 |	 j ƒ } | |
 _ |
 j ƒ  | |	 j k  rwt j |  d |	 ƒ t } n  Wq¹t j |  d |	 ƒ t } q¹Xn t j |  d |	 ƒ t } |	 j së|  j j d |	 j ƒ sô|  j j d |	 j ƒ rÎ|  j j d |	 j ƒ rªt j j d |  j d |	 j ƒ \ } } d |
 j | f } t |  j d |	 j | d t ƒ} | rd | |
 _  |
 j ƒ  qËt j |  d |	 ƒ t } qè|  j d |	 j |
 _  |
 j ƒ  qët j |  d |	 ƒ t } n  |  j j d |	 j ƒ rt|  j d |	 j } y) t! j" | d ƒ } | |
 _# |
 j ƒ  WqŽt$ k
 rp} t j |  d |	 ƒ t } qŽXn t j |  d |	 ƒ t } x© |	 j% ƒ  D]› } | j& d k ré|  j j d | j ƒ sét j |  d | ƒ t } qén  |  j j d | j ƒ rt } n t } t d | d | d | ƒ } | j ƒ  q›WqÝ W| s†t j' |  d ƒ d  | _( | j ƒ  t t	 d! d | j
 g ƒƒ Sn  t) |  d" i | d 6| d 6| d# 6ƒ S($   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   R   t   modality_categorys   category_%ss9   You have not entered enough Scans for <strong>%s</strong>s@   Please ensure the Scan Number is correct for <strong>%s</strong>s2   You have not entered Scans for <strong>%s</strong>s   file_%ss   hidden_file_%ss   %ss
   scans_%s%st   privates   exam_applications/%ss:   Sorry, could not upload your Scans for <strong>%s</strong>s8   You have not uploaded your Scans for <strong>%s</strong>s   training_began_%ss   %m/%Ys9   Please ensure the date is correct for <strong>%s</strong>sI   You have not entered the Date your Training Began for <strong>%s</strong>t
   compulsorys   scans_%ss^   Please tick to confirm you have completed the required number of scans for <strong>%s</strong>t   modality_itemR    s   Information Savedi   t   exam_application_experiences'   public/exam_application/modalities.htmlt   modality_categories(*   R   R   R   R   R   R    R   R!   R   R   R   t   ModalityCategoryR   t   filterR+   t   ExamApplicationModalityCategoryR$   t   ExamApplicationModalityItemR   R"   R   t   idt   intt   total_scanst   minimum_scanst   Truet   upload_disabledR5   t   ost   patht   splitextt   handle_uploaded_filet
   scans_fileR   t   strptimet   training_begant	   Exceptiont	   get_itemsR@   R%   R-   R    (   R   R   R   R   R   RJ   t   application_modality_categoriest   application_modality_itemst   errorst   categoryt   application_modality_categoryt   category_scanst   namet   extt   filenamet   file_uploadR[   t   training_began_datet   et   itemR    t   application_modality_item(    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt
   modalitiesÅ   sŽ    		


	
	2*#					
c         C   sE  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ St d | ƒ } |  j d	 k r t |  j d | ƒ} | j ƒ  ryM | j ƒ  t j |  d
 ƒ d | _ | j ƒ  t t	 d d | j
 g ƒƒ SWqqXq t j |  d ƒ n  t |  d i | d 6| d 6| d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   R'   R+   s   Information Savedi   R7   s;   Please ensure you click the box to confirm your experience.s'   public/exam_application/experience.htmlR   t   experience_form(   R   R   R   R   R   R    R   R!   R   R   R   t   ExperienceFormt   methodR+   R,   R"   R%   R-   R    (   R   R   R   R   R   Rm   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt
   experience$  s(    	
	
 c         C   s/  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ St d | ƒ } |  j r
t |  j d | ƒ} | j ƒ  r
yM | j ƒ  t j |  d	 ƒ d
 | _ | j ƒ  t t	 d d | j
 g ƒƒ SWqqXq
n  t |  d i | d 6| d 6| d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   R'   s   Information Savedi   t   exam_application_referencess%   public/exam_application/examiner.htmlR   t   examiner_form(   R   R   R   R   R   R    R   R!   R   R   R   t   ExaminerFormR+   R,   R"   R%   R-   R    (   R   R   R   R   R   Rr   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   examinerD  s&    		
	
 
c         C   s@  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ Sg  } t d | ƒ } |  j s› |  j rt |  j |  j d | ƒ} | GH|  j GH| j ƒ  r| j ƒ  t j |  d	 ƒ d
 | _ | j ƒ  t t	 d d | j
 g ƒƒ Sn  t |  d i | d 6| d 6| d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   R'   s   Information Savedi   t   exam_application_declarations'   public/exam_application/references.htmlR   t   reference_upload_form(   R   R   R   R   R   R    R   R!   R   R   R   t   ReferenceUploadFormR+   R5   R,   R"   R%   R-   R    (   R   R   R   R   R   t   reference_formsRv   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt
   referencesa  s(    	

	
 c         C   s¶  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ St d | ƒ } |  j r‘t |  j d | ƒ} | j ƒ  r‘| j ƒ  | j rÿ t j |  d	 ƒ d
 | _ | j ƒ  t t	 d d | j
 g ƒƒ St | _ t | _ | j ƒ  t |  | ƒ t d | d d d d d d | t	 d d | j g ƒf ƒ } | j ƒ  t t	 d d | j
 g ƒƒ Sq‘n  t |  d i | d 6| d 6| d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   R'   s   Information Savedi	   t   exam_application_paymentR@   s   exam-notificationt   titles   Exam Application Completedt   textsx   You have completed an exam application for <strong>%s</strong>, to view this submission please go <a href="%s">here</a>.t   account_view_exam_applicationt   exam_application_completes(   public/exam_application/declaration.htmlR   t   declaration_form(   R   R   R   R   R   R    R   R!   R   R   R   t   DeclarationFormR+   R,   R"   t   payment_amountR%   R-   RS   t   paidt   application_form_completedt   UserActivityRO   R    (   R   R   R   R   R   R   t   activity(    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   declaration©  s0    		
		
		
=
"c         C   s3  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j rt t j |  d ƒ t t	 d d | j
 g ƒƒ S| j s© t j |  d ƒ t t	 d	 d | j
 g ƒƒ St d | d
 d d | ƒ } | j ƒ  t j rê d | j | _ n d | j | _ | j ƒ  t j } t j } d t j t	 d d | j
 g ƒf } d t j t j | j | j | f }	 d d  l }
 |
 j |	 ƒ j ƒ  } |  j r |  j j d ƒ r |  j d } | | _ t | _ t j ƒ  | _ | j ƒ  t  |  | ƒ t t	 d d | j
 g ƒƒ Sn  t! |  d i | d 6| d 6| d 6| d 6| d 6ƒ S(   NR   R   R   R   s\   Sorry, you have already made an application, you can review this application in your locker.R   R   s*   There is no payment required for this ExamRu   R@   s   Exam_Application_Payment_%sDs   Exam_Application_Payment_%ss   %s%st    exam_application_payment_processs   %s:%s:%s:GBP:%s:%siÿÿÿÿt   payment_methodR~   s$   public/exam_application/payment.htmlR   t   paymentt   redirect_urlt   encrypted_string("   R   R   R   R   R   R    R   R!   R   R   R   R   t   warningR   R"   t   settingst   DEVELOPMENTRO   t   invoicet   WORLD_PAY_SECRET_KEYt   WORLD_PAY_INSTALLATION_IDt   PAYMENT_URLt   hashlibt   md5t	   hexdigestR+   R   t   payment_typeRS   R   t   nowt   completed_timet!   application_form_completed_unpaidR    (   R   R   R   R   R   R‰   t
   secret_keyt   installation_idRŠ   t   stringR“   R‹   Rˆ   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyR‰   Ô  s>    		
	
		%%			
c         C   sa  t  t d | ƒ} |  j j d d ƒ } |  j j d d ƒ } |  j j d d ƒ } |  j j d d ƒ } t  t d | ƒ} g  } t }	 | s  | s  | s  | r¶ t }	 | j d ƒ n  | t j	 k rÛ t }	 | j d	 ƒ n  | s| d
 k r×| j
 d k r¯d | _
 | | _ | j ƒ  | j }
 t |
 _ d |
 _ t |
 _ t j ƒ  |
 _ |
 j ƒ  t |  |
 ƒ t d |
 j d d d d d d | t d d |
 j g ƒf ƒ } | j ƒ  n  d t j t d d | j g ƒf } qJd | _
 | j ƒ  d t j t d d | j g ƒf } n8 d | _
 | j ƒ  d t j t d d | j g ƒf } t |  d i | d 6ƒ S(   NR   t
   callbackPWt    t   transStatust
   authAmountt   cartIdR   s   Missing a Required Variables   World Pay Password Incorrectt   Yt   pendingR    t   credit_cardR   R@   s   exam-notificationR{   s   Exam Application CompletedR|   sx   You have completed an exam application for <strong>%s</strong>, to view this submission please go <a href="%s">here</a>.R}   R   s   %s%st!   exam_application_payment_completet   rejectedt    exam_application_payment_failures   public/payment-redirect.htmlt   next(   R   R   R+   R   R   R   RS   R=   R   t   WORLD_PAY_PASSWORDR-   t   amountR"   R   R‚   R–   R    R   R—   R˜   Rƒ   R„   R   R   RO   t   URLR   R    (   R   R   R   R   RŸ   R    R¡   R‰   R`   R!   R   R…   R¨   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   payment_process  sJ    		
				
@(	
(	
%c         C   sV   t  t d | ƒ} y t  t d d ƒ} Wn t } n Xt |  d i | d 6| d 6ƒ S(   NR   t   exam_payment_completes-   public/exam_application/payment-complete.htmlR   t   content_block(   R   R   R   R   R    (   R   R   R   R®   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   payment_complete@  s    
c         C   s>   t  t d | ƒ} t j |  d ƒ t t d d | j g ƒƒ S(   NR   sF   Sorry, we could not take payment at this time, please try again below.Rz   R   (   R   R   R   R!   R   R   R   (   R   R   R   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   payment_failureK  s    c         C   sŠ   t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} y t  t d d ƒ} Wn t } n Xt |  d i | d 6| d 6| d	 6ƒ S(
   NR   R   R   R   t   exam_other_completes%   public/exam_application/complete.htmlR   R   R®   (   R   R   R   R   R   R   R   R    (   R   R   R   R   R   R®   (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyR    R  s    
N(/   t   django.shortcutsR    R   t   django.httpR   R   R   t   django.core.urlresolversR   t   django.contribR   t   django.template.defaultfiltersR   t   django.contrib.auth.decoratorsR   t   django.views.decorators.csrfR	   t   django.core.files.storageR
   t   modules.core.functionst   modules.core.decoratorst   formst   modelst   modules.payments.modelsR   t   modules.members.modelst   modules.blocks.modelsR   R   t   emailst   members_onlyR   R#   R&   R.   R6   RD   Rl   Rp   Rt   Ry   R†   R‰   R¬   R¯   R°   R    (    (    (    s<   /var/www/svtgbi.org/svtgbi/modules/exam_application/views.pyt   <module>   s@   





,,_ H+1;		