B
    Acr                 @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ G d	d
 d
ejZe
ejeddd Ze
ejeddd Zdde j  ddZdS )    N)models)cache)settings)signals)receiver)gettext_lazy)MyUserc               @   sX   e Zd ZejddZejdddZejddZ	ej
eejdZG dd dZd	d
 ZdS )DiscountT)defaultF)ZnullZblank)Zauto_now_add)Z	on_deletec               @   s   e Zd ZedZdZdS )zDiscount.Metar	   ZcloudN)__name__
__module____qualname___Zverbose_nameZ	app_label r   r   ;G:\easytimepro\master/mysite/cloud\models\model_discount.pyMeta   s   r   c             C   s
   t | jS )N)strdiscount_ratio)selfr   r   r   __str__   s    zDiscount.__str__N)r   r   r   r   ZBooleanFieldeffective_statusZ
FloatFieldr   ZDateTimeFieldcreate_timeZ
ForeignKeyr   ZCASCADEZcreate_userr   r   r   r   r   r   r	      s   r	   )senderc             K   s   t jrddlm} |r@|j|jd}d}|||d d}| }	q|j}
d|
}||d d d}| }	t	d}|	d d	 }x\|D ]J}|d }||kr|t
 }|j|jd}d
|}|||d d}| }	qW d S nd S d S )Nr   )!HttpRequestInterfaceForIoTService)r   r   z8https://subscriptiondev.minervaiot.com/api/v1/discounts/)bodyparamszGhttps://subscriptiondev.minervaiot.com/api/v1/discounts/?discount_ratioapplication_iddataresultsz;https://subscriptiondev.minervaiot.com/api/v1/discounts/{}/)r   CLOUD_VERSION"mysite.cloud.minerva_iot_interfacer   r   r   Zpostformatgetr   idZput)r   instanceZcreatedrawkwargsr   r   urlinterface_objectcontentr   current_application_idr   discountresult_application_iddiscount_idr   r   r   /save_or_update_discount_to_subscription_service   s4    





r.   c             K   s   t jrddlm} |j}d|}||d d d}| }td}|d d }	xD|	D ]<}
|
d }||krT|
t }d|}||d d d}|	 }qTW d S )	Nr   )r   zGhttps://subscriptiondev.minervaiot.com/api/v1/discounts/?discount_ratio)r   r   r   r   r   z;https://subscriptiondev.minervaiot.com/api/v1/discounts/{}/)
r   r   r    r   r   r!   r"   r   r#   delete)r   r$   r&   r   r   r'   r(   r)   r*   r   r+   r,   r-   r   r   r   'delete_discount_to_subscription_serviceA   s     


r0   Tg        z%Y-%m-%d %H:%M:%S)r   r   r   )ZdatetimeZ	django.dbr   Zdjango.core.cacher   Zdjango.confr   Zdjango.db.modelsr   Zdjango.dispatch.dispatcherr   Zdjango.utils.translationr   r   Zmysite.accounts.modelsr   ZModelr	   Z	post_saver.   Zpost_deleter0   ZnowstrftimeZDEFAULT_DISCOUNT_PARAMSr   r   r   r   <module>   s   &