o
    )c                     @   s   d 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 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 )(a  
211111 The strategy was to log requests and to serve the binaries from
the server. Wavemetrics has changed their licensing structure, so that
licenses now expire. I don't think that there is any further need to
maintain records. Therefore, once a person has successfully been identified
as a legitimate HMC member, they are sent an email message with all the 
necessary information to download and install.
    )renderredirect)RequestContext)timezone)Download)StreamingHttpResponseHttpResponseHttp404c                 C   
   t | dS )Nzigor/short.htmlr   request r   /var/www/djphys/igor/views.pyshort_intro      
 r   c                 C   r
   )Nzigor/long.htmlr   r   r   r   r   
long_intro   r   r   c                 C   r
   )Nzigor/screencasts.htmlr   r   r   r   r   videos   r   r   c                 C   r
   )Nzigor/faq.htmlr   r   r   r   r   faq   r   r   c                 C   r
   )Nzigor/fitting.htmlr   r   r   r   r   fitting   r   r   c                 C   r
   )Nzigor/power.htmlr   r   r   r   r   	power_law   r   r   c                 C   r
   )Nzigor/propagation.htmlr   r   r   r   r   propagation   r   r   c                 C   r
   )Nzigor/statistics.htmlr   r   r   r   r   
statistics   r   r   c                 C   r
   )Nzigor/spreadsheets.htmlr   r   r   r   r   spreadsheets   r   r   c                 C   r
   )Nzigor/HMCproc.htmlr   r   r   r   r   menu   r   r   c                 C   r
   )Nzigor/hmc_menu.htmlr   r   r   r   r   hmcmenu   r   r   c                 K   s   t | d|S )Nzigor/igor.htmlr   )r   kwargsr   r   r   main    s   r   c                 C   s   | j dkr	tdS | jd }ddlm} ||}| s$t| d|dS |j}d}| d	kr2d
}n| dkr>|	 
 }|sIt| d|dS tjj|d}|  t| dd|jiS )NPOSTigornamer   )identify_personu   I did not recognize ‘{0}’errorFfacultyTstudentz{0} is not a valid user)personzigor/check_email.htmlemail)methodr   r   people.identifierr!   r   formatr&   is_xsubclass	is_activer   objectscreatesendr   r'   )r   r    r!   pipeeplegitdr   r   r   download$   s$   

r5   c                 C   s   t | }t| dd|iS )Nzigor/send_download_info.htmlr5   )r   r   )r   r5   cr   r   r   send_download_info=   s   r7   c              
   C   s   | j dkr	t| S zX| jd }tjj|d}| dkr#t| ddW S |d }|jr5t| fi ddiW S t	 |_|
  | jd	 }|d
rQd|d  d}nd|d  d}t| d|W S  ty} } zt| d| ddW  Y d }~S d }~ww )Nr   key)r8   r   zEntered key was incorrect.r"   r#   zThat key has already been used.versionmacIgor   z.dmg	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   r8   	downloadsthe_downloadr9   filenameeepsr   r   r   do_downloadC   s*   




 rJ   c                 C   s   t d| ddl}ddl}ddlm} ||d }|jrQddlm	} |t
|d}|dkr7t||d}nt|d	d}d
|j| |d< |j||d< |S z't|d}d|d< ddl}	|	j|d}
|
|d< d
|j| |d< W |S    t)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.confrK   
guess_typeDEBUGwsgiref.utilrL   openr   pathbasenamegetsizer   urllib.parseparsequoteencoder	   )r   rX   rQ   rR   rK   contentTyperL   wrapperresponseurllibur   r   r   rD   [   s@   



rD   N)__doc__django.shortcutsr   r   django.templater   django.utilsr   igor.modelsr   django.httpr   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r5   r7   rJ   rD   r   r   r   r   <module>   s,   	