o
    g?                     @   sx   d dl 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mZmZ dd Zd	d
 Zdd Zdd Zdd ZdS )    )renderget_object_or_404)	Paginator)QCount)timezone   )ArticleCategoryTagc                 C   s   t jjdt dddd}|jdddd	 }tj j	t
d
d}tj j	t
d
dddd }t|d}| jd}||}||||d}t| d|S )z3Display list of published articles with pagination.	publishedstatuspublished_date__lteauthorcategorytagsT)is_featuredN   articles)article_countz-article_count
      page)r   featured_articles
categoriesr   znews/article_list.html)r	   objectsfilterr   nowselect_relatedprefetch_relatedr
   allannotater   r   order_byr   GETgetget_pager   )requestr   r   r   r   	paginatorr   context r*   /var/www/html/gwz/news/views.pyarticle_list   s0   



r,   c                 C   s   t tjddd|dt d}| jd7  _|  tj	t
|jdt
|j dB j|jd	 d
d }||d}t| d|S )zDisplay a single article.r   r   r   r   )slugr   r   r   )r   )tags__in)idNr   )articlerelated_articlesznews/article_detail.html)r   r	   r   r   r    r   r   views_countsaver   r   r   r   r!   excluder/   distinctr   )r'   r-   r0   r1   r)   r*   r*   r+   article_detail)   s&   
r6   c                 C   ^   t t|d}tjj|dt dd}t|d}| j	
d}||}||d}t| d|S )	z(Display articles in a specific category.r-   r   )r   r   r   r   	   r   )r   r   znews/category_articles.html)r   r
   r	   r   r   r   r   r   r   r$   r%   r&   r   )r'   r-   r   r   r(   r   r)   r*   r*   r+   category_articlesA      

r:   c                 C   r7   )	z%Display articles with a specific tag.r8   r   )r   r   r   r   r9   r   )tagr   znews/tag_articles.html)r   r   r	   r   r   r   r   r   r   r$   r%   r&   r   )r'   r-   r<   r   r(   r   r)   r*   r*   r+   tag_articlesU   r;   r=   c                 C   s   | j dd}g }|r9tjjt|dt|dB t|dB dt ddd		 }t
|d
}| j d}||}||d}t| d|S )z+Search articles by title, content, or tags.q )title__icontains)content__icontains)tags__name__icontainsr   r   r   r   r9   r   )queryr   znews/search_results.html)r$   r%   r	   r   r   r   r   r   r   r5   r   r&   r   )r'   rC   r   r(   r   r)   r*   r*   r+   search_articlesi   s*   
	
rD   N)django.shortcutsr   r   django.core.paginatorr   django.db.modelsr   r   django.utilsr   modelsr	   r
   r   r,   r6   r:   r=   rD   r*   r*   r*   r+   <module>   s    !