o
    vf0                     @   s   d dl Z d dlZd dlZd dl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 d d
lmZ i fddZdd Zdd Zdd Zdd ZdS )    N)render)RequestContext)Http404HttpResponseHttpResponseRedirectsettings)
CourseSiteSecureCourseFile)LoadScheduleForm)Epoch)	get_epoch)Coursec                 C   sn   t d| j}|r(ztjj|dd}tjj|dj}|r"||d< W n   Y | j	j
r1| j	|d< t| ||S )Nz/c/([^/]*)/   )order_field)courselogouser)researchpathr   objectsgetgroupr	   r   r   is_authenticatedr   )requesttemplate
dictionarymr   r    r    /var/www/djphys/courses/views.pyr2r   s   
r!   c                 C   sR   dt jjddi}t| |d< |d | |d< |d |d |d< t| d|S )Nr   p117)course__order_fieldepochcalendar
course_reczcourses/p117home.html)r	   r   r   r   r%   course_recordr!   )r   dicr   r   r    home&   s
   r)   c                 C   s
   t | dS )Nzcourses/mathematica.html)r!   )r   r   r   r    mathematica.   s   
r*   c                 C   sd   | j dkr(t| j| j}| r$|jd }ddlm} ||}t	dS t| S ddl
m} || S )NPOSTsourcer   )Scripterz/c/p151/)load)methodr   r+   FILESis_validcleaned_datacourses.scriptr-   r.   r   courses.p151.viewsr)   )r   formr,   r-   scr.   r   r   r    load_schedule2   s   


r7   c                 C   s@  ddl m} |j}tj|}t| ztd| tj	j
|d}|| s0ddlm} | W n   t tj||}t|d }|d krXtj|d }	|	dv rXd}|jrtt|d	}
|d
krmt|
|d}nt|
dd}d| |d< tj||d< |S zt }||d< tj|d}||d< W |S    t)Nr   r   z$Looking for a document with path {0})document)PermissionDeniedr   )z.ipynbz.pdfzapplication/force-downloadrbz
image/jpeg)content_typezattachment; filename=zContent-DispositionzContent-LengthzContent-Typezutf-8z
X-Sendfile)django.confr   PRIVATE_ROOTurllibparseunquoteprintformatr
   r   r   
has_accessdjango.core.exceptionsr9   r   osr   join	mimetypes
guess_typesplitextDEBUGFileWrapperopenr   getsizequoteencode)r   fullpathr   document_rootdpathdocr9   	full_pathcontentTypeextwrapperresponseur   r   r    	xsendfile?   sJ   

rZ   )r   rE   rG   urllib.parser>   django.shortcutsr   django.templater   django.httpr   r   r   r<   r   courses.modelsr	   r
   courses.formsr   djphys.epochr   djphys.funcsr   djphys.modelsr   r!   r)   r*   r7   rZ   r   r   r   r    <module>   s$   