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 d d	lmZ d d
lmZ d dlmZ G dd dejejejejejeZdS )    )mixins)status)Response)action)permissions)gettext_lazy)UtilGenericViewSet)LocationListFilter)Location)serializers)get_api_company_idc               @   sh   e Zd ZdZeZej Ze	Z
dZejfZejejejejejejejdZdd Zdd Zdd	 Zd
S )LocationViewSetz8
    LocationList pagination, search, filter, order
    )Zlocation_codeZlocation_name)listZretrievecreateupdateZpartial_updater   Zexportc             C   s   | j | jtjS )N)serializer_dictgetr   r   ZNoneSerializer)self r   AG:\easytimepro\master/mysite/personnel\api\views\view_location.pyget_serializer_class*   s    z$LocationViewSet.get_serializer_classc             C   s&   t | jj}| jj|d}|ddS )N)
company_idZparent_locationZcompany)r   requestuserquerysetfilterZselect_related)r   r   Zqsr   r   r   get_queryset.   s    zLocationViewSet.get_querysetc             O   sL   y"|   }| | ddi}t|S  tk
rF   td}td|iS X d S )NmessageZdeletedZ&location_default_id_can_not_be_deletedZdetail)Z
get_objectZperform_destroyr   	Exception_)r   r   argskwargsinstanceZresponser   r   r   r   destroy>   s    
zLocationViewSet.destroyN)__name__
__module____qualname____doc__r
   ZmodelZobjectsallr   r	   Zfilter_classZsearch_fieldsr   ZIsAuthenticatedZpermission_classesr   ZLocationSerializerZLocationCreateSerializerZLocationEditSerializerZLocationActionSerializerZLocationExportSerializerr   r   r   r#   r   r   r   r   r      s    

r   N)Zrest_frameworkr   r   Zrest_framework.responser   Zrest_framework.decoratorsr   r   Zdjango.utils.translationr   r   Z mysite.personnel.api.utils_classr   Zmysite.personnel.api.filtersr	   Z&mysite.personnel.models.model_locationr
   Zmysite.personnel.apir   Zmysite.api.utilsr   ZListModelMixinZCreateModelMixinZRetrieveModelMixinZUpdateModelMixinZDestroyModelMixinr   r   r   r   r   <module>   s    