ó
£dYc           @   sV  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 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 Te d
 „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z 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   *(   t   Payment(   t   ContentBlockc         C   s‰   t  t d | ƒ} | j s5 t j |  d ƒ t d ƒ St  t d |  j ƒ} t j	 j
 d | d | d t ƒ } t |  d i | d	 6| d
 6ƒ S(   Nt   slugs$   Sorry, this exam form is not enableds   /my-locker/t   usert   membert   examt   completes$   public/theory_exams/application.htmlt	   exam_formt   th_applications(   R   t   TheoryExamFormt   enabledR   t   errorR   t   MemberR   t   TheoryExamApplicationt   objectst   filtert   FalseR    (   t   requestt	   form_slugR   R   R   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyt   theory_exam   s    	
!c      #   C   s  t  t d | ƒ} | j s5 t j |  d ƒ t d ƒ St  t d |  j ƒ} t d | d | d | j	 d | j
 d	 | j d
 | j d | j j d | j d | j d | j d | j d | j d | j d | j d | j d | j d | j ƒ } | j ƒ  t t d d | j | j g ƒƒ S(   NR   s$   Sorry, this exam form is not enableds   /my-locker/R   R   R   t   membership_numbert   titlet
   first_namet   surnamet   email_addresst   contact_numbert   dobt	   job_titlet   current_employert   mailing_address_1t   mailing_address_2t   mailing_townt   mailing_countyt   mailing_postcodet   mailing_countryt   theory_exam_applicantt   args(   R   R   R   R   R   R   R   R   R   R   R   t
   given_nameR!   t   emailt	   telephonet   date_of_birthR%   t   institution_companyt	   address_1t	   address_2t   townt   countyt   postcodet   countryt   saveR   R   t   id(   R   R   R   R   t   exam_application(    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyt   start_application$   s    	
Ÿ
c      #   C   sc  t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} | j sb t j |  d ƒ t d ƒ S| j	 r~ t j |  d ƒ nÃ | j
 ƒ  t d | d | d	 | j d
 | j d | j d | j d | j j d | j d | j d | j d | j d | j d | j d | j d | j d | j d | j ƒ } | j ƒ  t j |  d ƒ t t d d | j | j g ƒƒ S(   NR   R   R;   R   s$   Sorry, this exam form is not enableds   /my-locker/s:   Sorry, you cannot restart an already complete application.R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   s   Application has been Restarted.R-   R.   (   R   R   R   R   R   R   R   R   R   R   t   deleteR   R   R/   R!   R0   R1   R2   R%   R3   R4   R5   R6   R7   R8   R9   R:   t   successR   R   R;   (   R   R   t   application_idR   R   R<   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyt   restart_application2   s    	
	
Ÿ
c         C   s“   t  t d | ƒ} t  t d |  j ƒ} t  t d | d | ƒ} y | j ƒ  t j |  d ƒ Wn t j |  d ƒ n Xt	 t
 d d | j g ƒƒ S(	   NR   R   R;   R   s   Application Removeds(   Sorry, could not delete this applicationR   R.   (   R   R   R   R   R   R>   R   R?   R   R   R   R   (   R   R   R@   R   R   R<   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyt   delete_applicationI   s    
c         C   sÇ  t  t d | ƒ} t  t d |  j ƒ} y t j j d | d | ƒ } Wn= t j k
 r… t j	 |  d ƒ t
 t d d | j g ƒƒ SX| j r» t j	 |  d ƒ t
 t d d | j g ƒƒ S| j d	 k rû t d
 | ƒ } t j j d | ƒ | j d _ n. t d
 | ƒ } t j j d | ƒ | j d _ |  j r¢| j d	 k rxt |  j d
 | ƒ} t j j d | ƒ | j d _ n4 t |  j d
 | ƒ} t j j d | ƒ | j d _ | j ƒ  r¢| j ƒ  | j ƒ  t j |  d ƒ | j ƒ  d k rt
 t d d | j | 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, could not find this application.R   R.   sc   Sorry, you have already completed this application, you can review this application in your locker.t   applicationt   instanceR   t   exam_choicess   Information Savedi    t   theory_exam_paymentt   types   exam-notificationR   s!   Theory 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_theory_exam_applicationt   theory_exam_completes*   public/theory_exams/applicant-details.htmlR<   t   applicant_details_form(    R   R   R   R   R   R   t   gett   DoesNotExistR   R   R   R   R   R   RG   t   TheoryApplicantDetailsFormt
   ExamChoiceR   t   fieldst   querysett   TheoryApplicantDetailsFormResitt   POSTt   is_validR:   R?   t   get_payment_amountR;   t   Truet   paidt!   theory_application_form_completedt   UserActivityR    (   R   R   R@   R   R   R<   RK   t   activity(    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyt   applicant_detailsY   sF    	"	"

"		
=
"c         C   sN  t  t d | ƒ} t  t d |  j ƒ} y t j j d | d | ƒ } Wn= t j k
 r… t j	 |  d ƒ t
 t d d | j g ƒƒ SX| j r» 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 | 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, could not find this application.R   R.   sc   Sorry, you have already completed this application, you can review this application in your locker.RG   s   Theory_Exam_Payment_%sDs   Theory_Exam_Payment_%ss   %s%st   theory_exam_payment_processs   %s:%s:%s:GBP:%s:%siÿÿÿÿt   payment_methodRJ   s    public/theory_exams/payment.htmlR   R<   t   paymentt   redirect_urlt   encrypted_string(#   R   R   R   R   R   R   RL   RM   R   R   R   R   R   R   R
   R:   t   settingst   DEVELOPMENTR;   t   invoicet   WORLD_PAY_SECRET_KEYt   WORLD_PAY_INSTALLATION_IDt   PAYMENT_URLRU   t   hashlibt   md5t	   hexdigestRS   t   payment_typeRV   t   datetimet   nowt   completed_timet(   theory_application_form_completed_unpaidR    (   R   R   R@   R   R   R<   R^   t
   secret_keyt   installation_idR_   t   stringRg   R`   R]   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyR^      s@    	
	
		+(			
c         C   sm  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 | j g ƒf } qVd | _
 | j ƒ  d t j t d d | j | g ƒf } n; d | _
 | j ƒ  d t j t d d | j | g ƒf } t |  d i | d 6ƒ S(   NR   t
   callbackPWt    t   transStatust
   authAmountt   cartIdRc   s   Missing a Required Variables   World Pay Password Incorrectt   Yt   pendingR   t   credit_cardR   RG   s   exam-notificationR   s   Exam Application CompletedRH   sx   You have completed an exam application for <strong>%s</strong>, to view this submission please go <a href="%s">here</a>.RI   R.   s   %s%st   theory_exam_payment_completet   rejectedt   theory_exam_payment_failures   public/payment-redirect.htmlt   next(   R   R   RS   RL   R
   R   RV   t   appendRa   t   WORLD_PAY_PASSWORDt   statust   amountR:   R   RW   Rj   R   Rk   Rl   Rm   RX   RY   R   R   R;   t   URLR   R    (   R   R   R@   R   Rr   Rt   Ru   Rv   R^   t   errorsR   R<   RZ   R}   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/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   Rz   s)   public/theory_exams/payment-complete.htmlR   t   content_block(   R   R   R   R   R    (   R   R   R@   R   R…   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/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.t   exam_application_paymentR.   (   R   R   R   R   R   R   R   (   R   R   R@   R   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyt   payment_failure  s    c         C   sk   t  t d | ƒ} t  t d |  j ƒ} y t  t d d ƒ} Wn t } n Xt |  d i | d 6| d 6ƒ S(   NR   R   t   theory_exam_other_completes!   public/theory_exams/complete.htmlR   R…   (   R   R   R   R   R   R   R    (   R   R   R   R   R…   (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyR     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   modules.core.functionst   modules.core.decoratorst   formst   modelst   modules.payments.modelsR
   t   modules.members.modelst   modules.blocks.modelsR   t   emailst   members_onlyR   R=   RA   RB   R[   R^   R„   R†   Rˆ   R   (    (    (    s7   /var/www/svtgbi.org/svtgbi/modules/theory_exam/views.pyt   <module>   s.   





D2	:		