
    Si                     X    d dl mZmZ d dlmZ d dlmZ ddlmZm	Z	m
Z
 d Zd Zd Zd	 Zy
)    )renderget_object_or_404)	Paginator)Q   )ProductCategoryBrandc                 t   t         j                  j                  t         j                  j                        j                  dd      }t        j                  j                  d      }t        j                  j                  d      }| j                  j                  d      }|r|j                  |      }| j                  j                  d      }|r|j                  |      }| j                  j                  d      }|rB|j                  t        |	      t        |
      z  t        |      z  t        |      z        }| j                  j                  dd      }|dk(  r|j                  d      }nr|dk(  r|j                  d      }n[|dk(  r|j                  d      }nD|dk(  r|j                  d      }n-|dk(  r|j                  d      }n|dk(  r|j                  d      }t        |d      }| j                  j                  d      }	|j                  |	      }|||||||d}
t        | d|
      S )NstatuscategorybrandT)	is_activecategory__slugbrand__slugqname__icontainssku__icontainspart_number__icontainsdescription__icontainssortnewest-created_atoldest
created_atname_ascname	name_desc-name	price_lowprice
price_high-price   page)products
categoriesbrandscurrent_categorycurrent_brandquerycurrent_sortzproducts/product_list.html)r   objectsfilterStatusACTIVEselect_relatedr	   r
   GETgetr   order_byr   get_pager   )requestr-   r.   r/   category_slug
brand_slugr2   r   	paginatorr,   contexts              '/var/www/alwasay/apps/products/views.pyproduct_listrC      s   %%~~$$ & nZ)  !!((4(8J]]!!D!1FKKOOJ/M??-?@)J??z?:KKOOC E??e$U#$U+, U+,
 ;;??68,Dx$$]3		$$\2		$$V,		$$W-		$$W-		$$X.(B'I;;??6"D!!$'H  )#G '7AA    c                    t        t        |d      }t        j                  j	                  t        j
                  j                  |      j                  dd      }t        j                  j	                  d|      j                         }| j                  j                  d      }|r|j	                  |      }| j                  j                  d      }|r5|j	                  t        |	      t        |
      z  t        |      z        }| j                  j                  dd      }|dk(  r|j                  d      }nr|dk(  r|j                  d      }n[|dk(  r|j                  d      }nD|dk(  r|j                  d      }n-|dk(  r|j                  d      }n|dk(  r|j                  d      }t        |d      }| j                  j                  d      }	|j                  |	      }||||||d}
t!        | d|
      S )NTslugr   )r   r   r   r   )r   products__categoryr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r   r-   r/   r1   r2   r3   zproducts/category_products.html)r   r	   r   r4   r5   r6   r7   r8   r
   distinctr9   r:   r   r;   r   r<   r   )r=   rG   r   r-   r/   r?   r2   r   r@   r,   rA   s              rB   category_productsrJ   >   s    EH%%~~$$ &  nZ) 
 ]]!!# "  hj 
 )J??z?:KKOOC E??e$U#$U+,
 ;;??68,Dx$$]3		$$\2		$$V,		$$W-		$$W-		$$X.(B'I;;??6"D!!$'H #G '<gFFrD   c                    t        t        |d      }t        j                  j	                  t        j
                  j                  |      j                  dd      }t        j                  j	                  d|      j                         }| j                  j                  d      }|r|j	                  |      }| j                  j                  d      }|r5|j	                  t        |	      t        |
      z  t        |      z        }| j                  j                  dd      }|dk(  r|j                  d      }nr|dk(  r|j                  d      }n[|dk(  r|j                  d      }nD|dk(  r|j                  d      }n-|dk(  r|j                  d      }n|dk(  r|j                  d      }t        |d      }| j                  j                  d      }	|j                  |	      }||||||d}
t!        | d|
      S )NTrF   )r   r   r   r   )r   products__brandr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r   r-   r.   r0   r2   r3   zproducts/brand_products.html)r   r
   r   r4   r5   r6   r7   r8   r	   rI   r9   r:   r   r;   r   r<   r   )r=   rG   r   r-   r.   r>   r2   r   r@   r,   rA   s              rB   brand_productsrM   s   s   e$$?E%%~~$$ &  nZ) 
 !!(( )  hj 
 KKOOJ/M??-?@KKOOC E??e$U#$U+,
 ;;??68,Dx$$]3		$$\2		$$V,		$$W-		$$W-		$$X.(B'I;;??6"D!!$'H  )G '97CCrD   c                    | j                   j                  dd      }t        j                  j	                  t        j
                  j                        }|rS|j	                  t        |      t        |      z  t        |      z  t        |      z        j                  dd	      }n|j                         }t        |d
      }| j                   j                  d      }|j                  |      }||d}t        | d|      S )Nr    r   r   r   r   r   r   r   r+   r,   )r-   r2   zproducts/search_results.html)r9   r:   r   r4   r5   r6   r7   r   r8   noner   r<   r   )r=   r2   r-   r@   r,   rA   s         rB   product_searchrQ      s    KKOOC$E%%W^^-B-B%CH??e$U#$U+, U+,

 .W
- 	 ==?(B'I;;??6"D!!$'H G '97CCrD   N)django.shortcutsr   r   django.core.paginatorr   django.db.modelsr   modelsr   r	   r
   rC   rJ   rM   rQ    rD   rB   <module>rW      s/    6 +  , ,4Bn2Gj2DjDrD   