
    	]j                        d 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 ddlmZ dd	lmZ  G d
 deej$                        Z G d deej$                        Z G d de      Z G d dej,                        Z eddg       G d de             Z G d deej$                        Z G d deej$                        Z G d dej,                        Zy)zThis file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
    )	TypedDict)DynamicFieldsMixin)extend_schema_serializer)OrganizationOrganizationMember)Project)serializers)
Annotation)UserSerializerc                        e Zd Z G d d      Zy)OrganizationIdSerializerc                       e Zd ZeZg dZy)OrganizationIdSerializer.Meta)idtitlecontact_info
created_atN__name__
__module____qualname__r   modelfields     P/root/env/lib/python3.12/site-packages/label_studio/organizations/serializers.pyMetar      s    >r   r   Nr   r   r   r   r   r   r   r   r      s    ? ?r   r   c                        e Zd Z G d d      Zy)OrganizationSerializerc                       e Zd ZeZdZy)OrganizationSerializer.Meta__all__Nr   r   r   r   r   r"      s    r   r   Nr   r   r   r   r    r       s     r   r    c                   "    e Zd ZU eed<   eed<   y)ProjectInfor   r   N)r   r   r   int__annotations__strr   r   r   r%   r%   !   s    GJr   r%   c                   \    e Zd Z ej                  dd      Z ej                  dd      Zy)&OrganizationMemberListParamsSerializerF)requireddefaultN)r   r   r   r	   BooleanFieldactivecontributed_to_projectsr   r   r   r*   r*   &   s+    %[%%ueDF6k66uUr   r*   created_projectsr/   )deprecate_fieldsc                       e Zd Z ej                  d      Z ej                  d      Zdee   dz  fdZ	dee   dz  fdZ
 G d dej                        Zy)	$UserOrganizationMemberListSerializerT	read_onlyreturnNc                     | j                   j                  dd      sy | j                   j                  di       }|j                  |j                  g       S Nr/   Fcreated_projects_mapcontextgetr   )selfuserr9   s      r   get_created_projectsz9UserOrganizationMemberListSerializer.get_created_projects5   sI    || 95A#||//0FK#''44r   c                     | j                   j                  dd      sy | j                   j                  di       }|j                  |j                  g       S Nr/   Fcontributed_to_projects_mapr:   )r=   r>   rB   s      r   get_contributed_to_projectsz@UserOrganizationMemberListSerializer.get_contributed_to_projects;   sJ    || 95A&*ll&6&67TVX&Y#*..tww;;r   c                   >    e Zd Zej                  j
                  dz   Zy))UserOrganizationMemberListSerializer.Meta)r0   r/   N)r   r   r   r   r   r   r   r   r   r   rE   A   s    $$++.]]r   r   )r   r   r   r	   SerializerMethodFieldr0   r/   listr%   r?   rC   r   r   r   r   r   r3   r3   +   sj     9{884H?k??$O5D,=,D 5<43Dt3K <^~"" ^r   r3   c                       e Zd Z e       Z ej                  d      Z ej                  d      Z G d d      Z	de
e   dz  fdZde
e   dz  fdZy)	 OrganizationMemberListSerializerTr4   c                       e Zd ZeZg dZy)%OrganizationMemberListSerializer.Meta)r   organizationr>   r0   r/   Nr   r   r   r   r   r   r   r   r   r   rK   J   s    "^r   r   r6   Nc                     | j                   j                  dd      sy | j                   j                  di       }|j                  |j                  j                  g       S r8   r;   r<   r>   r   )r=   memberr9   s      r   r?   z5OrganizationMemberListSerializer.get_created_projectsN   sM    || 95A#||//0FK#'';;r   c                     | j                   j                  dd      sy | j                   j                  di       }|j                  |j                  j                  g       S rA   rO   )r=   rP   rB   s      r   rC   z<OrganizationMemberListSerializer.get_contributed_to_projectsT   sN    || 95A&*ll&6&67TVX&Y#*..v{{~~rBBr   )r   r   r   r3   r>   r	   rF   r0   r/   r   rG   r%   r?   rC   r   r   r   rI   rI   E   sj    /1D8{884H?k??$O_ _<d;.?$.F <CT+5F5M Cr   rI   c                       e Zd Z ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      Zde	fdZ
de	fdZdee   dz  fdZdee   dz  fdZ G d	 d
      Zy)OrganizationMemberSerializerTr4   r6   c                     | j                   j                  d      }|j                  j                  j	                  |      j                         S )NrL   project__organization)r;   r<   r>   annotationsfiltercountr=   rP   orgs      r   get_annotations_countz2OrganizationMemberSerializer.get_annotations_counta   s=    ll~.{{&&--C-HNNPPr   c                     | j                   j                  d      }|j                  j                  j	                  |      j                  d      j                         j                         S )NrL   rU   project)r;   r<   r>   rW   rX   valuesdistinctrY   rZ   s      r   get_contributed_projects_countz;OrganizationMemberSerializer.get_contributed_projects_counte   sR    ll~.{{&&--C-HOOPYZccekkmmr   Nc                 .   | j                   j                  dd      sy | j                   j                  d      }t        j                  j	                  |j
                  |      j                  dd      }|d d }|D cg c]  }|d   |d   d c}S c c}w )	Nr/   FrL   )
created_byrL   r   r   d   r   r   )r;   r<   r   objectsrX   r>   r_   )r=   rP   rL   projectsr^   s        r   r?   z1OrganizationMemberSerializer.get_created_projectsi   s    || 95A||''7??))V[[|)\ccdhjqrDS> $

  dm )
 	
 
s   =Bc                 J   | j                   j                  dd      sy | j                   j                  d      }t        j                  j	                  |j
                  |      j                  dd      j                         }|d d }|D cg c]  }|d   |d   d c}S c c}w )	Nr/   FrL   )completed_byrV   project__idproject__titlerd   re   )r;   r<   r
   rf   rX   r>   r_   r`   )r=   rP   rL   rW   
annotations        r   rC   z8OrganizationMemberSerializer.get_contributed_to_projectsw   s    || 95A||''7%%6;;Vb%cVM#34XZ 	
 "$3' *

  !/#$45
 	
 
s   B c                       e Zd ZeZg dZy)!OrganizationMemberSerializer.Meta)r>   rL   contributed_projects_countannotations_countr   r0   r/   NrM   r   r   r   r   rn      s    "
r   r   )r   r   r   r	   rF   rp   ro   r0   r/   r&   r\   ra   rG   r%   r?   rC   r   r   r   r   rS   rS   [   s    999DI!B!B!BT!R8{884H?k??$OQs Qn n
d;.?$.F 

T+5F5M 
$

 

r   rS   c                   X    e Zd Z ej                  d      Z ej                  d      Zy)OrganizationInviteSerializerF)r+   N)r   r   r   r	   	CharFieldtoken
invite_urlr   r   r   rr   rr      s&    !K!!51E&&&6Jr   rr   N)__doc__typingr   drf_dynamic_fieldsr   drf_spectacular.utilsr   organizations.modelsr   r   projects.modelsr   rest_frameworkr	   tasks.modelsr
   users.serializersr   ModelSerializerr   r    r%   
Serializerr*   r3   rI   rS   rr   r   r   r   <module>r      s     1 : A # & # ,?1;3N3N ?/1L1L ) 
V[-C-C V
 !^> ^^(C'9;;V;V C,8
#5{7R7R 8
|7;#9#9 7r   