ó
¦QÊTc           @   sé   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 „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   render_to_response(   t   RequestContext(   t   Download(   t   StreamingHttpResponset   HttpResponset   Http404c         C   s   t  | i  d t |  ƒ ƒS(   Nt   context_instance(   R    R   (   t   requestt   template(    (    s   /var/www/djphys/igor/views.pyt   derp   s    c         C   s   t  |  d ƒ S(   Ns   igor/short.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   short_intro   s    c         C   s   t  |  d ƒ S(   Ns   igor/long.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt
   long_intro   s    c         C   s   t  |  d ƒ S(   Ns   igor/screencasts.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   videos   s    c         C   s   t  |  d ƒ S(   Ns   igor/faq.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   faq   s    c         C   s   t  |  d ƒ S(   Ns   igor/fitting.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   fitting   s    c         C   s   t  |  d ƒ S(   Ns   igor/power.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt	   power_law   s    c         C   s   t  |  d ƒ S(   Ns   igor/propagation.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   propagation   s    c         C   s   t  |  d ƒ S(   Ns   igor/statistics.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt
   statistics   s    c         C   s   t  |  d ƒ S(   Ns   igor/spreadsheets.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   spreadsheets   s    c         C   s   t  |  d ƒ S(   Ns   igor/HMCproc.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   menu   s    c         C   s   t  |  d ƒ S(   Ns   igor/hmc_menu.html(   R	   (   R   (    (    s   /var/www/djphys/igor/views.pyt   hmcmenu   s    c         K   s   t  d | d t |  ƒ ƒS(   Ns   igor/igor.htmlR   (   R    R   (   R   t   kwargs(    (    s   /var/www/djphys/igor/views.pyt   main   s    c         C   s  |  j  d k r t |  ƒ S|  j d } d d l m } | | ƒ } | ƒ  sh t |  i d j | ƒ d 6 S| j } t } | j ƒ  d k r’ t	 } n' | j ƒ  d k r¹ | j
 ƒ  j ƒ  } n  | sÜ t |  i d	 j | ƒ d 6 St j j d
 | ƒ } | j ƒ  t |  | ƒ S(   Nt   POSTt   nameiÿÿÿÿ(   t   IdentifyPersonu   I did not recognize â€˜{0}â€™t   errort   facultyt   studentu   {0} is not a valid usert   person(   t   methodR   R   t   people.identifierR   t   formatR   t   Falset   is_xt   Truet   subclasst	   is_activeR   t   objectst   createt   sendt   send_download_info(   R   R   R   t   pit   peept   legitt   d(    (    s   /var/www/djphys/igor/views.pyt   download   s$    
			
c         C   s&   t  |  ƒ } t d i | d 6d | ƒS(   Ns   igor/send_download_info.htmlR.   R   (   R   R    (   R   R.   t   c(    (    s   /var/www/djphys/igor/views.pyR)   1   s    c         C   sØ   |  j  d k r t |  ƒ Sy« t j j d t |  j d ƒ ƒ } | j r[ t |  i d d 6 Sd d  l } | j j	 ƒ  | _ | j
 ƒ  |  j d } d GH| d	 k r§ d
 n d } t |  d j | ƒ ƒ SWn n Xt |  ƒ S(   NR   t   pkR.   u   That key has already been used.R   iÿÿÿÿt   versions   saved the downloadt   wins   setupIgor6.exes	   Igor6.dmgs   /var/private/docs/igor/{0}(   R   R   R   R&   t   gett   intR   t	   retrievedt   datetimet   nowt   savet	   xsendfileR    (   R   t   the_downloadR6   R1   t   filename(    (    s   /var/www/djphys/igor/views.pyt   do_download6   s     
"	
c         C   sW  d j  | ƒ GHd d l } d d l } d d l m } | j | ƒ d } | j rÞ d d l m } | t	 | d ƒ ƒ } | d k r˜ t
 | d	 | ƒ} n, t
 | d	 d
 ƒ} d | j j | ƒ | d <| j j | ƒ | d <| Sye t d	 | ƒ } d | d <d d l }	 |	 j | j d ƒ ƒ }
 |
 | d <d | j j | ƒ | d <Wn t ‚ n X| S(   sï   
        This is a fake version of xsendfile that actually serves the file from
        within Django. Note that the directories up the line must be executable for
        www-data and that the file itself must be visible to www-data.
    s   xsendfile for {0}iÿÿÿÿN(   t   settingsi    (   t   FileWrappert   rbs
   image/jpegt   content_types   application/force-downloads   attachment; filename=s   Content-Dispositions   Content-Lengtht    s   Content-Types   utf-8s
   X-Sendfile(   R    t	   mimetypest   ost   django.confR=   t
   guess_typet   DEBUGt   django.core.servers.basehttpR>   t   openR   t   patht   basenamet   getsizeR   t   urllibt   quotet   encodeR   (   R   RI   RB   RC   R=   t   contentTypeR>   t   wrappert   responseRL   t   u(    (    s   /var/www/djphys/igor/views.pyR9   H   s0    	


N(   t   django.shortcutsR    t   django.templateR   t   igor.modelsR   t   django.httpR   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R.   R)   R<   R9   (    (    (    s   /var/www/djphys/igor/views.pyt   <module>   s(   																