
    h3                         S r SSKJr  SSKJr  SSKJr  SSKJr	  SSK
Jr  SSKJr  S rS	 rS
 r " S S5      r " S S5      r " S S5      r " S S5      r " S S\5      r " S S\5      r " S S\5      rg)aK  
We perform uniqueness checks explicitly on the serializer class, rather
the using Django's `.full_clean()`.

This gives us better separation of concerns, allows us to use single-step
object creation, and makes it possible to switch between using the implicit
`ModelSerializer` class and an equivalent explicit `Serializer` class.
    )
FieldError)	DataError)Exists)gettext_lazy)ValidationError)
smart_reprc                 Z     U R                  5       $ ! [        [        [        4 a     gf = fNF)exists	TypeError
ValueErrorr   )querysets    K/var/www/html/env/lib/python3.13/site-packages/rest_framework/validators.py	qs_existsr      s-      z9- s    **c                     Uc  [        U 5      $  U[        U R                  U5      5      -  R                  U5      $ ! [        [
        [        [        4 a     gf = fr
   )r   r   filtercheckr   r   r   r   )r   	conditionagainsts      r   qs_exists_with_conditionr      sY    "" F8??9#=>>EEgNNz9j9 s   +< AAc                 ~     U R                   " S0 UD6$ ! [        [        [        4 a    U R	                  5       s $ f = f)N )r   r   r   r   none)r   kwargss     r   	qs_filterr   '   s;    (((z9- }}s    %<<c                   T    \ rS rSrSr\" S5      rSrSS jrS r	S r
S	 rS
 rS rSrg)UniqueValidator.   z|
Validator that corresponds to `unique=True` on a model field.

Should be applied to an individual field on the serializer.
zThis field must be unique.TNc                 P    Xl         U=(       d    U R                  U l        X0l        g N)r   messagelookup)selfr   r!   r"   s       r   __init__UniqueValidator.__init__7   s     .$,,    c                 D    U< SU R                   < 3U0n[        U40 UD6$ )zD
Filter the queryset to all instances matching the given attribute.
__)r"   r   )r#   valuer   
field_namefilter_kwargss        r   filter_querysetUniqueValidator.filter_queryset<   s'     &0=uE3]33r&   c                 >    Ub  UR                  UR                  S9$ U$ ze
If an instance is being updated, then do not include
that instance itself as a uniqueness conflict.
)pkexcluder0   )r#   r   instances      r   exclude_current_instance(UniqueValidator.exclude_current_instanceC   '    
 ##x{{#33r&   c                     UR                   S   n[        UR                  SS 5      nU R                  nU R	                  XU5      nU R                  XT5      n[        U5      (       a  [        U R                  SS9eg )Nr3   uniquecode)	source_attrsgetattrparentr   r,   r4   r   r   r!   )r#   r)   serializer_fieldr*   r3   r   s         r   __call__UniqueValidator.__call__L   su     &2226
+22JE==''D00DX!$,,X>> r&   c                 f    SU R                   R                  < S[        U R                  5      < S3$ )N<
(queryset=)>)	__class____name__r   r   r#   s    r   __repr__UniqueValidator.__repr__Y   s%    NN##t}}%
 	
r&   c                 4   [        XR                  5      (       d  [        $ U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R
                  UR
                  :H  =(       a    U R                  UR                  :H  $ r    )
isinstancerF   NotImplementedr!   requires_contextr   r"   r#   others     r   __eq__UniqueValidator.__eq___   sq    %00!!- 0))U-C-CC0MMU^^30 KK5<</	r&   )r"   r!   r   )Nexact)rG   
__module____qualname____firstlineno____doc___r!   rN   r$   r,   r4   r@   rI   rQ   __static_attributes__r   r&   r   r   r   .   s8    
 ,-G
4?
r&   r   c                   j    \ rS rSrSr\" S5      r\" S5      rSrSS jr	S r
S	 rS
 rS rS rS rSrg)UniqueTogetherValidatori   z
Validator that corresponds to `unique_together = (...)` on a model class.

Should be applied to the serializer class, not to an individual field.
z0The fields {field_names} must make a unique set.This field is required.TNc                 t    Xl         X l        U=(       d    U R                  U l        Uc  / OUU l        XPl        g r    )r   fieldsr!   condition_fieldsr   )r#   r   r_   r!   r`   r   s         r   r$    UniqueTogetherValidator.__init__s   s1     .$,,&6&>DT"r&   c                     UR                   b  g/ U R                  QU R                  Q7 Vs0 s H.  nUR                  U   R                  U;  d  M"  X0R                  _M0     nnU(       a
  [        USS9egs  snf )zf
The `UniqueTogetherValidator` always forces an implied 'required'
state on the fields it applies to.
Nrequiredr:   )r3   r_   r`   sourcemissing_messager   )r#   attrs
serializerr*   missing_itemss        r   enforce_required_fields/UniqueTogetherValidator.enforce_required_fieldsz   s    
 * EDd.C.CD
D
  ,335@ -J,,,D 	 

 !-jAA 
s   !A5A5c                 (   U R                    Vs/ s H  nUR                   U   R                  PM     nnUR                  b(  U H"  nXa;  d  M
  [        UR                  U5      X'   M$     U Vs0 s H  nXaU   _M
     nn[	        U40 UD6$ s  snf s  snf )zE
Filter the queryset to all instances matching the given attributes.
)r_   rd   r3   r=   r   )r#   rf   r   rg   r*   sourcesrd   r+   s           r   r,   'UniqueTogetherValidator.filter_queryset   s     #kk
)
 j)00) 	 
 *!&$+J,?,?$HEM " "
! &M!! 	 
 3]33#

s   #B
-Bc                 >    Ub  UR                  UR                  S9$ U$ r/   r1   r#   rf   r   r3   s       r   r4   0UniqueTogetherValidator.exclude_current_instance   r6   r&   c                    U R                  X5        U R                  nU R                  XU5      nU R                  XUR                  5      nU R
                   Vs/ s H  oBR
                  U   R                  PM     nnUR                  c  U Vs/ s H  oAU   PM	     nnO2U Vs/ s H%  nX   [        UR                  U5      :w  d  M!  X   PM'     nnU R                   Vs0 s H  owX   _M	     nnU(       aa  S U;  aZ  [        X0R                  U5      (       a>  SR                  U R
                  5      n	U R                  R                  U	S9n
[        U
SS9eg g g s  snf s  snf s  snf s  snf )N, )field_namesr9   r:   )ri   r   r,   r4   r3   r_   rd   r=   r`   r   r   joinr!   formatr   )r#   rf   rg   r   r*   checked_nameschecked_valuesrd   condition_kwargsrs   r!   s              r   r@    UniqueTogetherValidator.__call__   s   $$U7==''D00*BUBUV DH;;
CNZj)00; 	 
 &BOP-JJ/-NPN
 #0"/J$
0C0CZ(PP "!"/   AE@U@UV@UfEM1@UVd.8=UV^`n`n  qA  >B  >B))DKK0Kll))k)BG!'99 >B8>

 Q Ws   "EE$ E#E# E(c                    ^  SR                  T R                  R                  SR                  U 4S jS 5       5      5      $ )Nz<{}({})>rr   c           	   3   v   >#    U  H.  n[        TU5      c  M  U S[        [        TU5      5       3v   M0     g 7f)N=)r=   r   ).0attrr#   s     r   	<genexpr>3UniqueTogetherValidator.__repr__.<locals>.<genexpr>   s<      4?D4& <4&*WT4%89:;?s   9!9)r   r_   r   )ru   rF   rG   rt   rH   s   `r   rI    UniqueTogetherValidator.__repr__   s<      NN##II 4?4 4
 	
r&   c                 t   [        XR                  5      (       d  [        $ U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R
                  UR
                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r    )rL   rF   rM   r!   rN   re   r   r_   rO   s     r   rQ   UniqueTogetherValidator.__eq__   s    %00!!- 0))U-C-CC0((E,A,AA0 MMU^^30 KK5<</		r&   )r   r`   r_   r!   r   )NNN)rG   rT   rU   rV   rW   rX   r!   re   rN   r$   ri   r,   r4   r@   rI   rQ   rY   r   r&   r   r[   r[   i   sI    
 BCG12O#B 40:4
r&   r[   c                   4    \ rS rSr\" S5      rSrS rS rSr	g)$ProhibitSurrogateCharactersValidator   z7Surrogate characters are not allowed: U+{code_point:X}. surrogate_characters_not_allowedc                     S [        U5       5        H6  nU R                  R                  [        U5      S9n[	        X0R
                  S9e   g )Nc              3   ^   #    U  H#  nS [        U5      s=::  a  S::  d  M  O  M  Uv   M%     g7f)i   i  N)ord)r}   chs     r   r   @ProhibitSurrogateCharactersValidator.__call__.<locals>.<genexpr>   s/      $D2'-R'BF'B %''B %'s   --	-)
code_pointr:   )strr!   ru   r   r   r;   )r#   r)   surrogate_characterr!   s       r   r@   -ProhibitSurrogateCharactersValidator.__call__   sI    $DU $Dll))S9L5M)NG!'		::$Dr&   c                     [        XR                  5      (       d  [        $ U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r    )rL   rF   rM   r!   r;   rO   s     r   rQ   +ProhibitSurrogateCharactersValidator.__eq__   sA    %00!!- ,II+	r&   r   N)
rG   rT   rU   rV   rX   r!   r;   r@   rQ   rY   r   r&   r   r   r      s    IJG-D;r&   r   c                   Z    \ rS rSrSr\" S5      rSrSS jrS r	S r
S rS	 rS
 rS rSrg)BaseUniqueForValidator   Nr]   Tc                 \    Xl         X l        X0l        U=(       d    U R                  U l        g r    )r   field
date_fieldr!   )r#   r   r   r   r!   s        r   r$   BaseUniqueForValidator.__init__   s!     
$.$,,r&   c                     U R                   U R                  4 Vs0 s H  nX!;  d  M
  X R                  _M     nnU(       a
  [        USS9egs  snf )zu
The `UniqueFor<Range>Validator` classes always force an implied
'required' state on the fields they are applied to.
rc   r:   N)r   r   re   r   )r#   rf   r*   rh   s       r   ri   .BaseUniqueForValidator.enforce_required_fields   s^      $zz4??;
;
& -J,,,; 	 

 !-jAA 
s
   	AAc                     [        S5      e)Nz&`filter_queryset` must be implemented.)NotImplementedError)r#   rf   r   r*   date_field_names        r   r,   &BaseUniqueForValidator.filter_queryset  s    !"JKKr&   c                 >    Ub  UR                  UR                  S9$ U$ r/   r1   ro   s       r   r4   /BaseUniqueForValidator.exclude_current_instance  r6   r&   c                    UR                   U R                     R                  S   nUR                   U R                     R                  S   nU R	                  U5        U R
                  nU R                  XX45      nU R                  XUR                  5      n[        U5      (       a9  U R                  R                  U R                  S9n[        U R                  U0SS9eg )Nr8   )r   r9   r:   )r_   r   r<   r   ri   r   r,   r4   r3   r   r!   ru   r   )r#   rf   rg   r*   r   r   r!   s          r   r@   BaseUniqueForValidator.__call__  s      &&tzz2??C
$++DOO<II"M$$U+==''U00*BUBUVXll))T__)EG!

G#  r&   c                    [        XR                  5      (       d  [        $ U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       ay    U R
                  UR
                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r    )	rL   rF   rM   r!   re   rN   r   r   r   rO   s     r   rQ   BaseUniqueForValidator.__eq__  s    %00!!- 8((E,A,AA8))U-C-CC8 MMU^^38 JJ%++-	8
 OOu'7'77	r&   c           
          SU R                   R                  < S[        U R                  5      < S[        U R                  5      < S[        U R
                  5      < S3	$ )NrC   rD   z, field=z, date_field=rE   )rF   rG   r   r   r   r   rH   s    r   rI   BaseUniqueForValidator.__repr__*  s=    NN##t}}%tzz"t'	
 	
r&   )r   r   r!   r   r    )rG   rT   rU   rV   r!   rX   re   rN   r$   ri   r,   r4   r@   rQ   rI   rY   r   r&   r   r   r      s=    G12O/BL 	
r&   r   c                   *    \ rS rSr\" S5      rS rSrg)UniqueForDateValidatori3  z6This field must be unique for the "{date_field}" date.c                     XR                      nXR                     n0 nXWU'   UR                  USU-  '   UR                  USU-  '   UR                  USU-  '   [        U40 UD6$ )Nz%s__day	%s__month%s__year)r   r   daymonthyearr   r#   rf   r   r*   r   r)   dater+   s           r   r,   &UniqueForDateValidator.filter_queryset6  sp    jj!__%$)j!59XXi/127;zzkO346:iij?233]33r&   r   NrG   rT   rU   rV   rX   r!   r,   rY   r   r&   r   r   r   3  s    HIG	4r&   r   c                   *    \ rS rSr\" S5      rS rSrg)UniqueForMonthValidatoriB  z7This field must be unique for the "{date_field}" month.c                     XR                      nXR                     n0 nXWU'   UR                  USU-  '   [        U40 UD6$ )Nr   )r   r   r   r   r   s           r   r,   'UniqueForMonthValidator.filter_querysetE  sJ    jj!__%$)j!7;zzkO343]33r&   r   Nr   r   r&   r   r   r   B  s    IJG4r&   r   c                   *    \ rS rSr\" S5      rS rSrg)UniqueForYearValidatoriO  z6This field must be unique for the "{date_field}" year.c                     XR                      nXR                     n0 nXWU'   UR                  USU-  '   [        U40 UD6$ )Nr   )r   r   r   r   r   s           r   r,   &UniqueForYearValidator.filter_querysetR  sJ    jj!__%$)j!6:iij?233]33r&   r   Nr   r   r&   r   r   r   O  s    HIG4r&   r   N)rW   django.core.exceptionsr   	django.dbr   django.db.modelsr   django.utils.translationr   rX   rest_framework.exceptionsr   #rest_framework.utils.representationr   r   r   r   r   r[   r   r   r   r   r   r   r&   r   <module>r      s    .  # 6 5 :8 8vm m` $E
 E
P43 4
44 
4
43 
4r&   