B
    b&                 @   s   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 d dlmZ G d	d
 d
ejZG dd de	ejejZdS )    )mixins)serializers)status)Response)viewsets)APPCustomizeResponseModelMixin)PriceStrategy)gettext_lazyc               @   sZ   e Zd Ze Ze Ze Ze Zdd Z	dd Z
dd Zdd ZG d	d
 d
ZdS )SubscriptionsSerializerc             C   s,   |j  }i }x|D ]}|j||j< qW |S )N)featureallnameid)selfinstancer   Zfeature_name_dictf r   GG:\easytimepro\master/mysite/mobile\api_rest\views\view_subscription.pyget_feature_name   s
    

z(SubscriptionsSerializer.get_feature_namec             C   s   |  }|S )N)Zget_type_display)r   r   	type_namer   r   r   get_type_name   s    z%SubscriptionsSerializer.get_type_namec             C   s   |j j}|S )N)Zcreate_userZusername)r   r   Zcreate_user_namer   r   r   get_create_user_username   s    z0SubscriptionsSerializer.get_create_user_usernamec             C   s   |j jS )N)Zdiscountdiscount_ratio)r   r   r   r   r   get_discount_ratio#   s    z*SubscriptionsSerializer.get_discount_ratioc               @   sB   e Zd ZeZddddddddd	d
dddddddddddddgZdS )zSubscriptionsSerializer.Metar   r   feature_nameZ*subscription_duration_unit_price_pre_monthZemployee_thresholdZemployee_unit_priceZdevice_thresholdZdevice_unit_priceZ!whatsapp_push_counts_limit_statusZwhatsapp_push_thresholdZwhatsapp_push_unit_priceZmobile_app_counts_limit_statusZmobile_applications_thresholdZmobile_applications_unit_priceZtransaction_counts_limit_statusZtransaction_thresholdZtransaction_unit_priceZcountryZcurrencyZcreate_timecreate_user_usernamer   Zeffective_statusN)__name__
__module____qualname__r   ZmodelZfieldsr   r   r   r   Meta&   s   r   N)r   r   r   r   ZSerializerMethodFieldr   r   r   r   r   r   r   r   r   r   r   r   r   r
      s   r
   c                   s<   e Zd Zej ZeZeedZ	dd Z
 fddZ  ZS )SubscriptionsViewSet)listcreatec             C   s   | j | jd S )N)serializer_class_dictgetaction)r   r   r   r   get_serializer_class=   s    z)SubscriptionsViewSet.get_serializer_classc       	         s   |j }|jr*td}d|i}t|tjdS tt| j|f||}x,|j	d D ]}|d dkrN|
ddi qNW t|j	tjdS d S )	NZaccess_for_only_adminZResult)r   resultsr   z
Free TrialZ	log_limitip  )userZis_employee_r   r   ZHTTP_406_NOT_ACCEPTABLEsuperr    r!   dataupdateZHTTP_200_OK)	r   Zrequestargskwargsr(   msgZresponseZresult_listr+   )	__class__r   r   r!   @   s    zSubscriptionsViewSet.list)r   r   r   r   Zobjectsr   Zquerysetr
   r   r#   r&   r!   __classcell__r   r   )r0   r   r    2   s   
r    N)Zrest_frameworkr   r   r   Zrest_framework.responser   Zmysite.mobile.api_restr   Z(mysite.mobile.api_rest.app_customize_mixr   Zmysite.cloud.modelsr   Zdjango.utils.translationr	   r)   ZModelSerializerr
   ZListModelMixinZGenericViewSetr    r   r   r   r   <module>   s   &