B
    DDb  ã               @   s\   d dl mZ d dlmZ d dlmZ d dlmZmZ G dd„ dejƒZ	G dd„ dej
ƒZd	S )
é    )ÚResponse)Úviewsets)Úserializers)Úconvert_ip2geolocationÚcheck_ip_is_privatec               @   s*   e Zd Ze ¡ Ze ¡ Ze ¡ ZejZdS )ÚDeviceLocationSerializerN)	Ú__name__Ú
__module__Ú__qualname__r   Z	CharFieldÚ	device_ipÚlatitudeÚ	longitudeÚtype© r   r   úDG:\easytimepro\master/mysite/iclock\api\views\view_devicelocation.pyr      s   r   c               @   s   e Zd ZeZdZdd„ ZdS )ÚDeviceLocationViewSetÚ c             O   sò   | j j dd ¡}y| d¡}W n   g }Y nX g }xžtt|ƒƒD ]Ž}t|| ƒ}|sžt|| ƒ}i }	|| |	d< |d |	d< |d |	d< d|	d< | |	¡ qBi }
|| |
d< d|
d< d|
d< d|
d< | |
¡ qBW |}d	dt|ƒ|d
œ}t	|ƒS )Nr   ú,r   r   Zpublicr   r   ZPrivater   )ÚcodeÚmsgÚcountÚdata)
ÚrequestZquery_paramsÚgetÚsplitÚrangeÚlenr   r   Úappendr   )Úselfr   ÚargsÚkwargsr   r   ÚxZcheck_device_typeZgeo_locationZpublic_dataZprivate_dataÚquerysetÚcontextr   r   r   Úlist   s8    
zDeviceLocationViewSet.listN)r   r	   r
   r   Zserializer_classr"   r$   r   r   r   r   r      s   r   N)Zrest_framework.responser   Zrest_frameworkr   r   Zmysite.cloud.utilsr   r   Z
Serializerr   ZModelViewSetr   r   r   r   r   Ú<module>   s
   