U
    sc 7                     @   s  d dl mZmZ 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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'G d*d+ d+ej!Z(G d,d- d-ej!Z)G d.d/ d/ej!Z*G d0d1 d1ejZ+d2S )3    )MinValueValidatorMaxValueValidator)serializers)
validatorsr   )Userr   )confr   )	InstituteInstituteStudentc                   @   s`   e Zd ZdZe ZejddZejddZ	ejddZ
ejddZdd Zdd Zdd	 Zd
S )CreateInstituteInputSerializerz
    This serializer class takes name & description from user and passed it to
    InstituteCreateAPIView to do some works on it.
    note that description is optional
    Frequiredc                 C   s   t j|tjtjtjd |S N)imageimage_size_as_MBformatmax_sidemain_validatorsimage_validetorr   maximum_size_institute_logo_MG"allowed_formats_for_institute_logo$maximum_side_size_for_institute_logoselfvalue r   1/var/www/wikiazma_server/institute/serializers.pyvalidate_logo   s
    
z,CreateInstituteInputSerializer.validate_logoc                 C   s   t j|tjtjtjd |S r   r   r   r    maximum_size_institute_poster_MG$allowed_formats_for_institute_poster&maximum_side_size_for_institute_posterr   r   r   r   validate_poster#   s
    
z.CreateInstituteInputSerializer.validate_posterc                 C   s   t j|ddd |S N   d   )name
min_length
max_lengthr   name_validatorr   r   r   r   validate_name)   s      z,CreateInstituteInputSerializer.validate_nameN)__name__
__module____qualname____doc__r   	CharFieldr'   description
ImageFieldlogoposter	JSONFieldinfor   r#   r,   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZejejgdZe Z	ejd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d
d Zdd ZdS )EditInstituteInputSerializerz
    This serializer class takes name, description & institute_id from user and passed it to
    InstituteEditAPIView to do some works on it.
    note that description is optional
    r   FT)r   allow_blankr   )defaultc                 C   s   t j|tjtjtjd |S r   r   r   r   r   r   r   ?   s
    
z*EditInstituteInputSerializer.validate_logoc                 C   s   t j|tjtjtjd |S r   r   r   r   r   r   r#   E   s
    
z,EditInstituteInputSerializer.validate_posterc                 C   s   t j|ddd |S r$   r*   r   r   r   r   r,   K   s      z*EditInstituteInputSerializer.validate_nameN)r-   r.   r/   r0   r   r1   r   uuid_validatorinstitute_idr'   r2   r6   r7   r3   r4   r5   BooleanFieldZdelete_logodelete_posterr   r#   r,   r   r   r   r   r8   /   s   r8   c                   @   s    e Zd ZdZejejgdZdS )DeleteInstituteInputSerializerz
    This serializer class takes institute_id from user and passed it to
    InstituteDeleteAPIView to do some works on it.
    r   N)	r-   r.   r/   r0   r   r1   r   r;   r<   r   r   r   r   r?   Q   s   r?   c                   @   sV   e Zd ZdZejddZejedgdZ	ejede
dgdZejejgdZdS )	AllInstitutesInputSerializerz
    This serializer class takes skip, take, sort_by & search_words from user and passed it to
    AllInstitutesAPIView to do some works on it.
    Fr   r   r      r&   N)r-   r.   r/   r0   r   r1   search_wordsIntegerFieldr   skipr   takeinstitute_validatorsaccess_sort_by_validatorsort_byr   r   r   r   r@   Z   s   r@   c                   @   s\   e Zd ZdZejdejgdZej	e
dgdZej	e
dedgdZejejgdZdS )	%IntersectionInstitutesInputSerializerz
    This serializer class takes skip, take, sort_by & email from user and passed it to
    IntersectionInstitutesAPIView to do some works on it.
       )r)   r   r   r   rA   r&   N)r-   r.   r/   r0   r   r1   authenticate_validatorsemail_validatoremailrC   r   rD   r   rE   rF   rG   rH   r   r   r   r   rI   u   s   rI   c                   @   s   e Zd ZejejgdZdS )GetInstituteInputSerializerr   Nr-   r.   r/   r   r1   r   r;   r<   r   r   r   r   rN      s   rN   c                   @   s   e Zd ZejejgdZdS )InstituteAccessGetSerializerr   NrO   r   r   r   r   rP      s   rP   c                   @   s@   e Zd ZejddZejejgdZej	e
jgdZe ZdS )GenerateAPIKeyInputSerializer  r)   r   N)r-   r.   r/   r   r1   tokenr   r;   r<   r6   collaborators_validatorroles_validatorrolesDateTimeField	expire_atr   r   r   r   rQ      s   rQ   c                   @   s(   e Zd ZejddZejejgdZdS )APIKeysListInputSerializerrR   rS   r   N)	r-   r.   r/   r   r1   rT   r   r;   r<   r   r   r   r   rZ      s   rZ   c                   @   s(   e Zd ZejddZejejgdZdS )DeleteAPIKeyInputSerializerrR   rS   r   N)	r-   r.   r/   r   r1   rT   r   r;   
api_key_idr   r   r   r   r[      s   r[   c                   @   s   e Zd ZejddZdS )GetTokenInputSerializerrR   rS   N)r-   r.   r/   r   r1   api_keyr   r   r   r   r]      s   r]   c                   @   s2   e Zd ZdZejddZdd ZG dd dZdS )	5InstituteSerializerForExamAndInstituteAndQuestionBankt
    This serializer class takes one or more Institute records and serializes them to json with desired fields.
    
owner_infomethod_namec                 C   s   t |jjS N)authenticate_serializers9UserSerializerForAuthenticateAndCollaboratorsAndInstituteuserdatar   objr   r   r   ra      s    z@InstituteSerializerForExamAndInstituteAndQuestionBank.owner_infoc                   @   s.   e Zd ZeZddddddddd	d
dddgZdS )z:InstituteSerializerForExamAndInstituteAndQuestionBank.Metaidr'   r2   r4   logo_thumbnailr5   poster_thumbnailr7   on_exam_finished_redirect_urlsandbox
created_atmodified_atownerNr-   r.   r/   r	   modelfieldsr   r   r   r   Meta   s       rv   N	r-   r.   r/   r0   r   SerializerMethodFieldrr   ra   rv   r   r   r   r   r_      s   r_   c                   @   s   e Zd ZdZG dd dZdS )UserSerializerForExamzo
    This serializer class takes one or more User records and serializes them to json with desired fields.
    c                   @   s   e Zd ZeZdddgZdS )zUserSerializerForExam.Meta
first_name	last_nameimage_thumbnailN)r-   r.   r/   r   rt   ru   r   r   r   r   rv      s   rv   N)r-   r.   r/   r0   rv   r   r   r   r   ry      s   ry   c                   @   sl   e Zd ZejddZejdddddZejdddddZejdddddZejdddddZ	ej
dd	Zd
S )!SetInstituteStudentInputValidatorr&   rS   .   FT)r)   r   r9   
allow_nullrJ      r   N)r-   r.   r/   r   r1   "referer_institute_student_identityrz   r{   rM   phoner6   r7   r   r   r   r   r}     s4               r}   c                   @   s,   e Zd ZejddZejddZdd ZdS )!GetInstituteStudentInputValidatorFr   c                 C   sB   ddg}d}|D ],}||kr|r8t dd| d d}q|S )z;
        One out of many fields should be present.
        wikiazma_institute_student_idr   FzOne of z and z is required.T)r   ValidationErrorjoin)r   rh   ru   Zone_field_foundfieldr   r   r   validate  s    z*GetInstituteStudentInputValidator.validateN)r-   r.   r/   r   r1   r   r   r   r   r   r   r   r     s   r   c                   @   sF   e Zd ZejedgdZejededgdZej	e
jgdZdS )"ListInstituteStudentInputValidatorr   r   rA   r&   N)r-   r.   r/   r   rC   r   rD   r   rE   r1   rF   Z#institute_student_sort_by_validatorrH   r   r   r   r   r   %  s   r   c                   @   s   e Zd ZG dd dZdS )%InstituteStudentSerializerForExamStatc                   @   s   e Zd ZeZddddgZdS )z*InstituteStudentSerializerForExamStat.Metarz   r{   rM   r   Nr-   r.   r/   r
   rt   ru   r   r   r   r   rv   .  s   rv   N)r-   r.   r/   rv   r   r   r   r   r   -  s   r   c                   @   s>   e Zd ZedZedZG dd dZdd Zdd Z	d	S )
GetInstituteStudentSerializerrename_referer_identity	rename_idc                   @   s"   e Zd ZeZdddddddgZdS )	z"GetInstituteStudentSerializer.Meta#wikiazma_institute_student_identityr   rz   r{   rM   r   r7   Nr   r   r   r   r   rv   9  s   rv   c                 C   s   |j S rd   )referer_identityri   r   r   r   r   >  s    z5GetInstituteStudentSerializer.rename_referer_identityc                 C   s   |j S rd   )rk   ri   r   r   r   r   A  s    z'GetInstituteStudentSerializer.rename_idN)
r-   r.   r/   r   rx   r   r   rv   r   r   r   r   r   r   r   3  s   r   c                   @   s.   e Zd ZejddZdd ZG dd dZdS )6ListInstituteSerializerForCollaboratorsAndQuestionBankra   rb   c                 C   s   t |jjS rd   ry   rg   rh   ri   r   r   r   ra   I  s    zAListInstituteSerializerForCollaboratorsAndQuestionBank.owner_infoc                   @   s.   e Zd ZeZddddddddd	d
dddgZdS )z;ListInstituteSerializerForCollaboratorsAndQuestionBank.Metark   r'   r2   r4   rl   r5   rm   r7   rn   ro   rp   rq   rr   Nrs   r   r   r   r   rv   L  s      rv   N)r-   r.   r/   r   rx   rr   ra   rv   r   r   r   r   r   E  s   r   c                   @   s2   e Zd ZdZejddZdd ZG dd dZdS )	SafeInstituteSerializerForExamr`   ra   rb   c                 C   s   t |jjS rd   r   ri   r   r   r   ra   Z  s    z)SafeInstituteSerializerForExam.owner_infoc                   @   s    e Zd ZeZddddddgZdS )z#SafeInstituteSerializerForExam.Metark   r'   r2   r4   ro   rr   Nrs   r   r   r   r   rv   ]  s   rv   Nrw   r   r   r   r   r   S  s   r   c                   @   s   e Zd ZejejgdZdS )InstituteBalanceInputSerializer   NrO   r   r   r   r   r   b  s   r   N),django.core.validatorsr   r   rest_frameworkr   authenticater   rK   re   authenticate.modelsr   collaboratorsrU   	instituter   rF   institute.modelsr	   r
   utilsr   
Serializerr   r8   r?   r@   rI   rN   rP   rQ   rZ   r[   r]   ModelSerializerr_   ry   r}   r   r   r   r   r   r   r   r   r   r   r   <module>   s8   "	#		%