U
    Vce                     @   s  d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z d dlmZmZ d dlm
Z d dlmZm
Z d dlm
Z G dd	 d	ejZG d
d dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZ G dd dejZ!G dd dejZ"G dd dejZ#G d d! d!ejZ$G d"d dejZG d#d$ d$ejZ%G d%d& d&ejZ&G d'd( d(ejZ'd)S )*    )serializers)MinValueValidatorMaxValueValidator)	Institute)6ListInstituteSerializerForCollaboratorsAndQuestionBank
validators)AccessInviteAccess)r   r   c                   @   s`   e Zd ZdZejejgdZejde	j
gddZejde	jgddZejejgdZdd Zd	S )
InviteInputSerializerz
    This serializer class takes institute_id, email & roles from user and passed it to
    InviteAPIView to do some works on it.
    r      F)
max_lengthr   required   c                 C   s   t | |S N)authenticate_validators&make_email_or_phone_required_validator)selfdata r   5/var/www/wikiazma_server/collaborators/serializers.pyvalidate   s    
zInviteInputSerializer.validateN)__name__
__module____qualname____doc__r   	CharFieldmain_validatorsuuid_validatorinstitute_idr   email_validatoremailphone_validatorphone	JSONFieldcollaborators_validatorsroles_validatorrolesr   r   r   r   r   r      s   r   c                   @   sF   e Zd ZejejgdZeje	dgdZ
eje	dedgdZdS )ListInvitationInputSerializerr   r      d   N)r   r   r   r   r   r   r   r   IntegerFieldr   skipr   taker   r   r   r   r(   !   s   r(   c                   @   s6   e Zd ZejedgdZejededgdZdS )ListMyInvitationInputSerializerr   r   r)   r*   N)	r   r   r   r   r+   r   r,   r   r-   r   r   r   r   r.   )   s   r.   c                   @   s.   e Zd ZejddZdd ZG dd dZdS )#InstituteSerializerForCollaborators
owner_infomethod_namec                 C   s
   t  jS r   )authenticate_serializersUserSerializerForCollaboratorsr   r   objr   r   r   r0   2   s    z.InstituteSerializerForCollaborators.owner_infoc                   @   s$   e Zd ZeZddddddddgZd	S )
z(InstituteSerializerForCollaborators.Metaidnamelogosandboxlogo_thumbnailposterposter_thumbnailownerN)r   r   r   r   modelfieldsr   r   r   r   Meta4   s   rA   N)r   r   r   r   SerializerMethodFieldr>   r0   rA   r   r   r   r   r/   /   s   r/   c                   @   s    e Zd Ze ZG dd dZdS )InvitationSerializerc                   @   s   e Zd ZeZdddgZdS )InvitationSerializer.Metar7   	instituter'   Nr   r   r   r
   r?   r@   r   r   r   r   rA   <   s   rA   N)r   r   r   r/   rE   rA   r   r   r   r   rC   9   s   rC   c                   @   s    e Zd ZdZejejgdZdS )AcceptInvitationInputSerializerx
    This serializer class takes key from user and passed it to
    AcceptInvitationAPIView to do some works on it.
    r   N	r   r   r   r   r   r   r   r   invitation_idr   r   r   r   rG   A   s   rG   c                   @   s    e Zd ZdZejejgdZdS )RejectInvitationInputSerializerrH   r   NrI   r   r   r   r   rK   J   s   rK   c                   @   s    e Zd ZdZejejgdZdS )DeleteInvitationInputSerializerz
    This serializer class takes invited_access_id from user and passed it to
    DeleteInvitationAPIView to do some works on it.
    r   N)	r   r   r   r   r   r   r   r   Zinvited_access_idr   r   r   r   rL   S   s   rL   c                   @   s    e Zd ZdZejejgdZdS )RemoveAccessInputSerializerzz
    This serializer class takes access_id from user and passed it to
    RemoveAccessAPIView to do some works on it.
    r   N)	r   r   r   r   r   r   r   r   	access_idr   r   r   r   rM   \   s   rM   c                   @   sN   e Zd ZdZe ZejedgdZ	ejede
dgdZejddZdS )	AllCollaboratorsInputSerializerz
    This serializer class takes institute_id, skip, take, sort_by & search_words from user and passed it to
    AllCollaboratorsAPIView to do some works on it.
    r   r   r)   r*   F)r   N)r   r   r   r   r   r   r   r+   r   r,   r   r-   search_wordsr   r   r   r   rO   d   s   rO   c                   @   s   e Zd ZejejgdZdS ) LeaveCollaboratorInputSerializerr   N)r   r   r   r   r   r   r   r   r   r   r   r   rQ   p   s   rQ   c                   @   sz   e Zd ZdZejddZejddZejddZej	ddZ
ejddZejddZejd	d
Zdd ZG dd dZdS )AccessibleInstituteSerializerzq
    This serializer class takes one or more Access records and serializes them to json with desired fields.
    zinstitute.id)sourceinstitute_namezinstitute.descriptionzinstitute.logozinstitute.sandboxinstitute_created_atr0   r1   c                 C   s   t |jjjS r   )r3   9UserSerializerForAuthenticateAndCollaboratorsAndInstituterE   userr   r5   r   r   r   r0      s    z(AccessibleInstituteSerializer.owner_infoc                   @   s$   e Zd ZeZddddddddgZd	S )
z"AccessibleInstituteSerializer.Metar7   r8   descriptionr9   r:   
created_atr'   r>   Nr   r   r   r	   r?   r@   r   r   r   r   rA      s      rA   N)r   r   r   r   r   r   r7   r8   rX   
ImageFieldr9   BooleanFieldr:   rY   rB   r>   r0   rA   r   r   r   r   rR   {   s   rR   c                   @   s"   e Zd Ze ZG dd dZdS )"AccessSerializerForAllCollabratorsc                   @   s   e Zd ZeZdddgZdS )z'AccessSerializerForAllCollabrators.Metar7   rW   r'   NrZ   r   r   r   r   rA      s   rA   N)r   r   r   r3   r4   rW   rA   r   r   r   r   r]      s   r]   c                   @   s(   e Zd Ze Ze ZG dd dZdS )rC   c                   @   s    e Zd ZeZddddddgZdS )rD   r7   r'   invited_emailinvited_phonerE   modifireNrF   r   r   r   r   rA      s   rA   N)	r   r   r   r/   rE   r3   r4   r`   rA   r   r   r   r   rC      s   c                   @   s    e Zd ZdZejejgdZdS )RemoveInvitationInputSerializerrH   r   NrI   r   r   r   r   ra      s   ra   c                   @   s,   e Zd ZejejgdZeje	j
gdZdS )EditInvitationInputSerializerr   N)r   r   r   r   r   r   r   rJ   r$   r%   r&   	new_rolesr   r   r   r   rb      s   rb   c                   @   s,   e Zd ZejejgdZeje	j
gdZdS )EditCollaboratorInputSerializerr   N)r   r   r   r   r   r   r   rN   r$   r%   r&   rc   r   r   r   r   rd      s   rd   N)(rest_frameworkr   Zdjango.core.validatorsr   r   institute.modelsr   Zinstitute.serializersr   utilsr   r   collaborators.modelsr	   r
   collaboratorsr%   authenticater3   r   rE   Zinstitute_validators
Serializerr   r(   r.   ModelSerializerr/   rC   rG   rK   rL   rM   rO   rQ   rR   r]   ra   rb   rd   r   r   r   r   <module>   s2   
				
