a
    ¤Q•h  ã                   @   sÀ   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
mZmZ d dlmZmZmZ d dl mZmZ d dl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S )é    ©Úrender)
ÚVitrineMudasÚBannerIndexÚSustentabilidadeSectionÚCarrouselSectionIndexÚNossosProjetosSectionÚNossaGenteSectionÚPropositosIndexÚHistoriaIndexÚContatosIndexÚNoticia)Ú	PaginatorÚ	EmptyPageÚPageNotAnInteger)r   Úget_object_or_404)ÚHttpResponseRedirectc              
   C   sd   t jjdd�}tj ¡ }tj ¡ }tj ¡ }tj ¡ }t	j 
d¡d d… }t| d||||||dœƒS )NT)Ú	publicadaz-data_publicacaoé   úsite_ama/index.html)ÚbannersÚsustentabilidadeÚ
carrouselsÚprojetosÚnossa_genteÚnoticias)r   ÚobjectsÚfilterr   Úfirstr   Úallr   r	   r   Úorder_byr   )Úrequestr   r   r   r   r   r   © r"   ú+/var/www/sistema_ama/apps/site_ama/views.pyÚindex   s    



r$   c                 C   s"   t j ¡ d d… }t| dd|iƒS )Né
   r   r   )r   r   r   r   )r!   r   r"   r"   r#   Ú	carrousel   s    r&   c                 C   sˆ   t jjdd� d¡}d}t||ƒ}| j dd¡}z| |¡}W n8 tyZ   | d¡}Y n t	yv   | |j
¡}Y n0 t| dd|iƒS )	NT©ÚpublicarÚnomeé   Úpageé   zsite_ama/vitrine.htmlÚcards)r   r   r   r    r   ÚGETÚgetr+   r   r   Ú	num_pagesr   )r!   Údados_vitrineÚitems_por_paginaÚ	paginatorr+   r-   r"   r"   r#   Úvitrine   s    
r4   c                 C   s   t j ¡ }t| dd|iƒS )Nzsite_ama/contato.htmlÚcontatos_edit)r   r   r   r   )r!   r5   r"   r"   r#   Úcontato)   s    
r6   c                 C   sV   t j ¡ }g }g }d}|D ]$}|r.| |¡ n
| |¡ | }q||dœ}t| d|ƒS )NT)Ú
left_blockÚright_blockzsite_ama/historia.html)r   r   r   Úappendr   )r!   Zhistoria_editr7   r8   Zadd_to_leftZhistoria_instanceÚcontextr"   r"   r#   Úhistoria-   s    

þr;   c                 C   s*   | j  dd ¡}tj ¡ }t| d||dœƒS )NÚdetalhes_noticiazsite_ama/noticias.html)r   r<   )ÚsessionÚpopr   r   r   r   )r!   r<   r   r"   r"   r#   r   A   s    
r   c                 C   s   t j ¡ }t| dd|iƒS )Nzsite_ama/proposito.htmlÚproposito_edit)r
   r   r   r   )r!   r?   r"   r"   r#   Ú	propositoJ   s    
r@   c                 C   sª   t jjdd�}d| jv r6| jd  ¡ }|r6|j|d�}d}t||ƒ}| j dd¡}z| |¡}W n8 ty|   | d¡}Y n t	y˜   | |j
¡}Y n0 t| dd	|iƒS )NTr'   Úbuscar)Znome__icontainsé   r+   r,   zsite_ama/buscar.htmlr-   r4   )r   r   r   r.   Ústripr   r/   r+   r   r   r0   r   Úredirect)r!   r1   Znome_a_buscarr2   r3   r+   r-   r"   r"   r#   rA   N   s     

rA   c                 C   sJ   t t|d�}|j|jr|jjnd |j d¡|jdœ| jd< t	| dd|iƒS )N)Úpkz%d/%m/%Y %H:%M)ÚtituloZ
imagem_urlÚdata_publicacaoÚconteudor<   zsite_ama/detalhes_noticias.htmlÚnoticia)
r   r   rF   ÚimagemÚurlrG   ÚstrftimerH   r=   r   )r!   Z
noticia_idrI   r"   r"   r#   Údetalhes_noticiask   s    
ürM   c                 C   s
   t | dƒS )Nzsite_ama/manutencao.htmlr   )r!   r"   r"   r#   Ú
manutencaox   s    rN   N)Údjango.shortcutsr   Zapps.site_ama.modelsr   r   r   r   r   r	   r
   r   r   r   Údjango.core.paginatorr   r   r   r   Údjango.httpr   r$   r&   r4   r6   r;   r   r@   rA   rM   rN   r"   r"   r"   r#   Ú<module>   s   0		