ó
£dYc           @   s{  d  d l  m Z m Z d  d l m Z m Z m Z d  d l m Z 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 d  d	 l m Z m Z d  d
 l m Z d  d l m Z d  d l m Z m Z m Z d  d l  Z  d  d l! m" Z" d  d l# Td  d l$ Td  d l% Td  d l& Td  d l' Td  d l( Z( d „  Z) d „  Z* e+ d „ Z, d „  Z- d S(   iÿÿÿÿ(   t   render_to_responset   get_object_or_404(   t   RequestContextt   loadert   Context(   t   login_requiredt   permission_required(   t   Q(   t   Site(   t   settings(   t   HttpResponseRedirectt   Http404t   HttpResponse(   t   reverse(   t   Usert   Group(   t   messages(   t   slugify(   t   datetimet   datet   timeN(   t   superuser_only(   t   *c         C   sº   t  } | j j ƒ  rH |  r? |  j | j j ƒ  k rE t } qE qH t } n  | j j ƒ  r¶ |  r­ t } x5 | j j ƒ  D]$ } |  | j j ƒ  k rs t  } qs qs W| s³ t } q³ q¶ t } n  | S(   N(   t   Truet   member_types_allowedt   allt   member_typet   Falset   member_groups_allowedt   members(   t   membert   abstract_requestt   allowedt	   in_groupst   group(    (    s5   /var/www/svtgbi.org/svtgbi/modules/abstracts/views.pyt   can_view   s     		c   
      C   s–  t  t d | ƒ} yK t j j d |  j ƒ } | j d k r\ t j |  d ƒ t	 t
 d ƒ ƒ SWn t } n X| j s– t d i | d 6d t |  ƒ ƒSt | | ƒ sÅ t d	 i | d 6d t |  ƒ ƒS| j ƒ  d
 k r÷ t d i | d 6d t |  ƒ ƒS| j ƒ  d k r)t d i | d 6d t |  ƒ ƒS| rvt d i | j d 6| j d 6| j d 6| j j d 6| j d 6ƒ } n	 t ƒ  } |  j rot |  j ƒ } | j ƒ  ro| j d t ƒ } | | _ | rÐ| | _ n8y% t j j d | j ƒ } | | _ Wnt j k
 ry t j j d | j ƒ } Wny t j k
 rŸt d | j d | j d | j ƒ } t d t d ƒ | _ t  d ƒ } | j! | ƒ | j ƒ  t" | _# n Xt d | d d d | j d | j d | j ƒ }	 | j# rå| |	 _$ n  t% ƒ  |	 _& |	 j ƒ  |	 | _ n Xt d t' d ƒ | _( | j ƒ  | j) ƒ  | _* | j ƒ  | j( |  j+ d <t	 t
 d d  | j, g ƒƒ Sn  t d! i | d 6| d" 6d t |  ƒ ƒS(#   Nt   slugt   usert   lapsedss   Sorry your membership has lapsed, you will need to renew your membership to be able to access this submission form.t   account_renews   public/abstracts/disabled.htmlR   t   context_instances$   public/abstracts/content-denied.htmlt   pendings%   public/abstracts/content-pending.htmlt   completes&   public/abstracts/content-finished.htmlt   initialt   titlet
   given_namet   surnamet   emailt	   telephonet   committ   user__emailt
   first_namet	   last_namei   t   usernamei
   t	   user_types
   non-membert
   unique_keyt   content_submission_keyt   abstract_submission_contentt   argss%   public/abstracts/submit-abstract.htmlt   content_submission_form_details(-   R   t   AbstractRequestt   Membert   objectst   getR%   t   member_statusR   t   warningR
   R   R   t   enabledR    R   R#   t
   get_statust   AbstractSubmissionFormDetailsR,   R-   R.   R/   R0   t   POSTt   is_validt   saveR   R   t   DoesNotExistR   t   random_string_uniqueR5   t   generate_random_passwordt   set_passwordR   t   member_registeredt   raw_passwordt   get_next_membership_numbert   membership_numbert   AbstractSubmissionR7   t   get_unique_codet   unique_codet   sessionR$   (
   t   requestt   abstract_request_slugR   R   R;   t   content_submissiont   abstract_memberR%   t   passwordt
   non_member(    (    s5   /var/www/svtgbi.org/svtgbi/modules/abstracts/views.pyt
   submission7   sh    
	    G			$
0	


c   #      C   sþ  t  t d | ƒ} y t j j d |  j ƒ } Wn t } n X| rY t  t d | ƒ} n7 |  j j d t ƒ rŠ t  t d |  j d ƒ} n t	 ‚ | j
 rµ t t d d | j g ƒƒ St d | d t ƒ } t d | d t ƒ } t d | ƒ } t j j d	 | ƒ j d
 ƒ }	 d0 }
 g  } |	 r˜xÔ |	 D]l } t d | d d | j ƒ } | j | ƒ | j d k rp|
 d2 }
 q%|
 d | j d | j f f }
 q%Wn] d | j | j f } t d d d i | d 6| j d 6| j d 6ƒ } | j | ƒ |
 d4 }
 |
 | j d j _ t j j d	 | ƒ j d
 ƒ } g  } | rxf | D]? } t  d | d d | j ƒ } d | j d _! | j | ƒ q9Wn t  d d ƒ } | j | ƒ |  j" r­t |  j" d | d t ƒ} t |  j" d | d t ƒ} t |  j" d | ƒ} x |	 D] } | j# ƒ  qöW|  j" j$ d ƒ } g  } d } t } d5 }
 xµ | D]­ } t |  j" d d | ƒ} | j | ƒ | d k r€|
 d7 }
 n |
 d | d | f f }
 | j% ƒ  s°t } q;| j& d t ƒ } | | _' | | _ | j& ƒ  | d } q;W|
 | j d j _ |  j" j$ d ƒ } g  } t } g  } d } x‰| D]} yœ t j j d	 | d
 | ƒ } t  |  j" |  j( d | d d | ƒ} | j& d t ƒ } | | _ | j& ƒ  t  d | d d | ƒ } | j | ƒ | j | ƒ WnÒ t j) k
 r¦|  j( j d | ƒ rqt  |  j" |  j( d d | ƒ} | j& d t ƒ } | | _' | | _ | j& ƒ  t  d | d d | ƒ }  | j |  ƒ q§t } t  |  j" |  j( d d | ƒ} | j | ƒ n X| d } q0Wx' | D] } | | k r¼| j# ƒ  q¼q¼W|  j" j d  ƒ rØ| j% ƒ  rØ| j% ƒ  rØ| j% ƒ  rØ| rØ| j& ƒ  | j& ƒ  | j& ƒ  t | _
 | j& ƒ  t* j+ d! |  d	 | ƒ | j, r—t- j. d" d  d! |  d# | j0 d$ | j1 ƒ n  |  j j d t ƒ r¹|  j d =n  t t d d | j g ƒƒ Sn  |  j" j d% ƒ r­t |  j" d | d t ƒ}! |! j% ƒ  r|! j& ƒ  n  t |  j" d | d t ƒ}" |" j% ƒ  rR|" j& ƒ  n  | j2 r—t* j3 d! |  d	 | ƒ t | _2 | j& ƒ  t4 j5 |  d& ƒ qªt4 j5 |  d' ƒ q­n  t6 d( i | d) 6| d	 6| d* 6|	 d 6| d+ 6| d, 6| d- 6| d. 6d/ t7 |  ƒ ƒS(8   NR$   R%   R7   R8   t   abstract_submission_completeR:   t   instancet   fields_requiredRV   t   ordert   prefixs	   author_%si   u    First Author and Primary Contactu	   Author %ss   %s %st   author_1R+   t   nameR/   R0   t	   presenters   file_%st   Imaget   filet   file_1t   authorst   1R1   t   filess   file_%s-filet   submitRT   t   senderR   R,   RG   sn   Your data has been saved. You should receive an email detailing how to resume this submission at a later date.s   Your data has been saved.s$   public/abstracts/submit-content.htmlR   t   content_submission_title_formt   author_formst   content_submission_data_formt   confirmation_formt
   file_formsR(   (    (   u    First Author and Primary Contactu    First Author and Primary Contact(   (   u    First Author and Primary Contactu    First Author and Primary Contact(   u    First Author and Primary Contactu    First Author and Primary Contact(   (   u    First Author and Primary Contactu    First Author and Primary Contact(    (   u    First Author and Primary Contactu    First Author and Primary Contact(   (   u    First Author and Primary Contactu    First Author and Primary Contact(8   R   R<   R=   R>   R?   R%   R   RP   RS   R   R*   R
   R   R$   t   AbstractSubmissionTitleFormR   t   AbstractSubmissionDataFormt   ConfirmationFormt   AbstractSubmissionAuthort   filtert   order_byt   AbstractSubmissionAuthorFormR^   t   appendR-   R.   R/   R0   t   fieldst   widgett   choicest   AbstractSubmissionFilet   AbstractSubmissionFileFormt   labelRE   t   deletet   getlistRF   RG   RV   t   FILESRH   t   emailst   abstract_content_submittedRL   t   non_member_registeredt   sendt   NoneR   Ra   t
   first_savet   abstract_content_savedR   t   successR    R   (#   RT   RU   R8   R   R   RV   Rk   Rm   Rn   Rf   Rz   Rl   t   authort   author_formt   submission_nameRh   Ro   Rd   t	   file_formt   posted_authorst   author_ordert   author_errorst   posted_authort   submitted_authort   posted_filest   file_errorst   current_filest
   file_ordert   posted_filet   existing_filet   existing_file_formt   submitted_filet   new_file_formt"   content_submission_title_form_tempt!   content_submission_data_form_temp(    (    s5   /var/www/svtgbi.org/svtgbi/modules/abstracts/views.pyt   submission_content‡   sô    
	(0
				
%	
		
+


	
	+		
c         C   s8   t  t d | d t ƒ} t d i | d 6d t |  ƒ ƒS(   NR$   RB   s-   public/abstracts/submit-content-complete.htmlR   R(   (   R   R<   R   R    R   (   RT   RU   R   (    (    s5   /var/www/svtgbi.org/svtgbi/modules/abstracts/views.pyt   submission_complete;  s    (.   t   django.shortcutsR    R   t   django.templateR   R   R   t   django.contrib.auth.decoratorsR   R   t   django.db.modelsR   t   django.contrib.sites.modelsR   t   django.confR	   t   django.httpR
   R   R   t   django.core.urlresolversR   t   django.contrib.auth.modelsR   R   t   django.contribR   t   django.template.defaultfiltersR   R   R   R   t   csvt   modules.core.decoratorsR   t   modules.core.functionst   modules.members.functionst   formst   modelst   modules.members.modelsR   R#   RZ   R   R   Rž   (    (    (    s5   /var/www/svtgbi.org/svtgbi/modules/abstracts/views.pyt   <module>   s.   




		P´