o
    Gg6                     @   sh   d dl mZmZ d dlmZ d dlmZ ddlmZm	Z	 d dl
mZmZmZ dd Zd	d
 Zdd ZdS )    )renderget_object_or_404)FileResponse)F   )CategoryPublication)	Paginator	EmptyPagePageNotAnIntegerc           	      C   s   t j }tjjdd}| jd}|r|j|d}| jd}|r(|j|d}| jdd}t|d	}z||}W n t	yI   |d}Y n t
yW   ||j}Y nw ||||d
}t| d|S )Nactive)statuscategory)category__slugyear)published_date__yearpager      )
categoriespublicationsselected_categoryselected_yearz"publications/publication_list.html)r   objectsallr   filterGETgetr	   r   r   r
   	num_pagesr   )	requestr   publication_listcategory_slugr   r   	paginatorr   context r#   '/var/www/html/gwz/publications/views.pyr      s.   

r   c                 C   s   t t|dd}t| dd|iS )Nr   slugr   z$publications/publication_detail.htmlpublication)r   r   r   )r   r&   r'   r#   r#   r$   publication_detail(   s   r(   c                 C   sF   t t|dd}tdd |_|  t|j}d|jj d|d< |S )Nr   r%   download_countr   zattachment; filename=""zContent-Disposition)r   r   r   r)   saver   documentname)r   r&   r'   responser#   r#   r$   download_publication,   s   
r/   N)django.shortcutsr   r   django.httpr   django.db.modelsr   modelsr   r   django.core.paginatorr	   r
   r   r   r(   r/   r#   r#   r#   r$   <module>   s    !