3
d9\                 @   sz   d dl mZ d dlmZ d dlZd dlmZmZ ddl	m
Z
 d dl mZ edd	ZG d
d dejZG dd dejZdS )    )	get_class)viewsN)datedatetime   )get_template)	get_model	catalogueCategoryc               @   s   e Zd Zdd ZdS )ProductCategoryViewc             C   s$   | j  }|js| jgS t|jdgS )Nlist)get_categorytemplatetemplate_namer   )selfobj r   //var/www/html/oscar2019/apps/catalogue/views.pyget_template_names   s    z&ProductCategoryView.get_template_namesN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   s@   e Zd ZdZ fddZ fddZ fddZdd	 Z  ZS )
ProductDetailViewTc          
      s0   t t| j }|jddjddddddd	d
d	S )NT)liveattribute_valuesZattribute_values__attributechildrenproduct_classimagesstockrecordsZchildren__stockrecordsZchildren__attribute_valuesZ%children__attribute_values__attribute)superr   get_querysetfilterprefetch_related)r   qs)	__class__r   r   r       s    zProductDetailView.get_querysetc                s>   t jjd| j dj }|r0|jr0t|jdgS tt| j	 S )NT)Zproduct_categories__primaryZproduct_categories__productdetail)
r
   objectsr!   
get_objectfirstr   r   r   r   r   )r   primary_category)r$   r   r   r      s
    
z$ProductDetailView.get_template_namesc                s  t t| jf |}| jjjddj }||d< tj| j	 |d< t
tdd |D |d< tdd	}|jjd|d
jdj }g }x\|D ]T}t }x|jj D ]}	|j|	j qW t|}
|
jdd |j|j|j|
d qW ||d< dd |D |d< | jjjddrdnd|d< |S )NT)r   r   Zchildren_datac             S   s   g | ]
}|j qS r   )subscription).0itemr   r   r   
<listcomp>0   s    z6ProductDetailView.get_context_data.<locals>.<listcomp>r*   zcatalogue.modelsProductAttribute)use_for_variationsZattribute_values__product__inr   r   zPlease Select)namecodevaluesvariation_attributesc             S   s   g | ]}|d  qS )r1   r   )r+   r,   r   r   r   r-   G   s    Zvariation_attributes_jspreviewF)r   r   get_context_dataobjectr   r!   alljsondumps_children_attributesboolsumr   r&   r"   distinctsetr   addvalue_as_htmlr   insertappendr0   r1   requestGETget)r   kwargscdr   r.   
attributesr3   	attributer2   valuevalues_list)r$   r   r   r5   '   s2    


z"ProductDetailView.get_context_datac       	      C   s   i }t dd}| j| j| jjd}t dd}| jjjddj }x8|D ]0}|j|j	}|j
|j|j|j|jd||j< qHW x:|jj|dd	jd
j D ]}t|j||j |jj< qW t|j S )Nzpartner.strategySelector)rC   userzcatalogue.modelsProductAttributeValueT)r   )priceprice_currencychild_idr*   points)Zproduct__inZattribute__use_for_variationsrI   )r   strategyrC   rM   r6   r   r!   r7   fetch_for_productrO   incl_taxcurrencypkr*   loyalty_pointsr&   r"   strr@   
product_idrI   r1   r   r2   )	r   retrL   rS   rN   r   childrO   Zattribute_valuer   r   r   r:   N   s"    



z&ProductDetailView._children_attributes)	r   r   r   enforce_parentr    r   r5   r:   __classcell__r   r   )r$   r   r      s
   'r   )oscar.core.loadingr   oscar.apps.cataloguer   base
simplejsonr8   r   r   helpersr   r   r
   r   r   r   r   r   r   <module>   s   
	