B
    GDb*                 @   s    d dl mZ G dd deZdS )    )APIViewc               @   s   e Zd Zdd Zdd ZdS )APPCustomizeResponseModelMixinc          
   O   s   || _ || _| j|f||}|| _| j| _yR| j|f|| |j | j	krft
| |j | j}n| j}||f||}W n, tk
r } z| |}W dd}~X Y nX | j||f||| _|   | jS )z
        `.dispatch()` is pretty much the same as Django's regular dispatch,
        but with extra hooks for startup, finalize, and exception handling.
        N)argskwargsZinitialize_requestrequestZdefault_response_headersZheadersinitialmethodlowerZhttp_method_namesgetattrZhttp_method_not_allowed	ExceptionZhandle_exceptionZfinalize_responseresponse_add_customize_fields)selfr   r   r   Zhandlerr   exc r   AG:\easytimepro\master/mysite/mobile\api_rest\app_customize_mix.pydispatch	   s"    
z'APPCustomizeResponseModelMixin.dispatchc             C   s  t | jjtrRt| jjdr8| jj| jjd| j_n| jj| jjd| j_n<t | jjtrf| jj| jjd< t| jjdrg | jjd< nt| jjdrd| jjkr| jjd g| jjd< nd| jjkrt | jjd tsd| jjd g| jjd< n`g | jjd< x|| jj D ]B\}}t |tr|dkrd	||d	 }| jjd 
| qW n(t | jjtr| jj| jjg d
| j_d S )N2)status_coderesults)r   messager   r   4Zdetailz{}:{}r   )r   r   r   )
isinstancer   datastrr   
startswithdictlistitemsformatappend)r   kvZcurrent_msgr   r   r   r   '   s2    z4APPCustomizeResponseModelMixin._add_customize_fieldsN)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   N)Zrest_framework.viewsr   r   r   r   r   r   <module>   s   