3
^[                 @   s   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 Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(S ))    )renderredirect)RequestContext)timezone)Download)StreamingHttpResponseHttpResponseHttp404c             C   s
   t | |S )N)r   )requesttemplate r   /var/www/djphys/igor/views.pyderp	   s    r   c             C   s
   t | dS )Nzigor/short.html)r   )r
   r   r   r   short_intro   s    r   c             C   s
   t | dS )Nzigor/long.html)r   )r
   r   r   r   
long_intro   s    r   c             C   s
   t | dS )Nzigor/screencasts.html)r   )r
   r   r   r   videos   s    r   c             C   s
   t | dS )Nzigor/faq.html)r   )r
   r   r   r   faq   s    r   c             C   s
   t | dS )Nzigor/fitting.html)r   )r
   r   r   r   fitting   s    r   c             C   s
   t | dS )Nzigor/power.html)r   )r
   r   r   r   	power_law   s    r   c             C   s
   t | dS )Nzigor/propagation.html)r   )r
   r   r   r   propagation   s    r   c             C   s
   t | dS )Nzigor/statistics.html)r   )r
   r   r   r   
statistics   s    r   c             C   s
   t | dS )Nzigor/spreadsheets.html)r   )r
   r   r   r   spreadsheets   s    r   c             C   s
   t | dS )Nzigor/HMCproc.html)r   )r
   r   r   r   menu   s    r   c             C   s
   t | dS )Nzigor/hmc_menu.html)r   )r
   r   r   r   hmcmenu   s    r   c             K   s   t | d|S )Nzigor/igor.html)r   )r
   kwargsr   r   r   main   s    r   c             C   s   | j dkrtdS | jd }ddlm} ||}| sHt| dj|dS |j}d}|j d	krdd
}n|j dkr||j	 j
 }|st| dj|dS tjj|d}|j  t| |S )NPOSTigornamer   )IdentifyPersonu   I did not recognize ‘{0}’)errorFfacultyTstudentz{0} is not a valid user)person)methodr   r   people.identifierr   r   formatr#   is_xsubclass	is_activer   objectscreatesendsend_download_info)r
   r   r   pipeepZlegitdr   r   r   download   s$    

r1   c             C   s   t | }t| dd|iS )Nzigor/send_download_info.htmlr1   )r   r   )r
   r1   cr   r   r   r-   2   s    r-   c             C   s   | j dkrt| S y| jd }tjj|d}|j dkrDt| ddS |d }|jrbt| fddiS tj	 |_|j
  | jd	 }|jd
rd|d  d}nd|d  d}t| dj|S  tk
r } zt| d| ddS d }~X nX t| S )Nr   key)r3   r   zEntered key was incorrect.)r    r    zThat key has already been used.versionmacZIgor   z.dmgZ	setupIgorz.exez/var/private/docs/igor/{0}zEncountered error z. Please try again.)r$   r   r   r   r*   filtercount	retrievedr   nowsave
startswith	xsendfiler&   	Exception)r
   r3   Z	downloadsZthe_downloadr4   filenameeepsr   r   r   do_download7   s(    




 rA   c          	   C   s  t dj| ddl}ddl}ddlm} |j|d }|jrddlm	} |t
|d}|dkrnt||d}n t|d	d}d
|jj| |d< |jj||d< |S yLt|d}d|d< ddl}	|	jj|jd}
|
|d< d
|jj| |d< W n   tY nX |S )z
        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.
    zxsendfile for {0}r   N)settings)FileWrapperrbz
image/jpeg)content_typezapplication/force-downloadzattachment; filename=zContent-DispositionzContent-Length zContent-Typezutf-8z
X-Sendfile)printr&   	mimetypesosdjango.confrB   
guess_typeDEBUGwsgiref.utilrC   openr   pathbasenamegetsizer   urllib.parseparsequoteencoder	   )r
   rO   rH   rI   rB   contentTyperC   wrapperresponseurllibur   r   r   r=   N   s0    

r=   N)django.shortcutsr   r   django.templater   django.utilsr   Zigor.modelsr   django.httpr   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r1   r-   rA   r=   r   r   r   r   <module>   s*   