
    (phn/                         S 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 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.
    )	DataError)gettext_lazy)ValidationError)
smart_reprc                 Z     U R                  5       $ ! [        [        [        4 a     gf = f)NF)exists	TypeError
ValueErrorr   )querysets    L/var/www/html/venv/lib/python3.13/site-packages/rest_framework/validators.py	qs_existsr      s-      z9- s    **c                 ~     U R                   " S0 UD6$ ! [        [        [        4 a    U R	                  5       s $ f = f)N )filterr	   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__*   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excluder(   )r   r   instances      r   exclude_current_instance(UniqueValidator.exclude_current_instance6   '    
 ##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 )Nr+   uniquecode)	source_attrsgetattrparentr   r$   r,   r   r   r   )r   r!   serializer_fieldr"   r+   r   s         r   __call__UniqueValidator.__call__?   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__L   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   )
isinstancer>   NotImplementedr   requires_contextr   r   r   others     r   __eq__UniqueValidator.__eq__R   sq    %00!!- 0))U-C-CC0MMU^^30 KK5<</	r   )r   r   r   )Nexact)r?   
__module____qualname____firstlineno____doc___r   rF   r   r$   r,   r8   rA   rI   __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)UniqueTogetherValidator\   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                 P    Xl         X l        U=(       d    U R                  U l        g r   )r   fieldsr   )r   r   rW   r   s       r   r    UniqueTogetherValidator.__init__f   s     .$,,r   c                     UR                   b  gU R                   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requiredr2   )r+   rW   sourcemissing_messager   )r   attrs
serializerr"   missing_itemss        r   enforce_required_fields/UniqueTogetherValidator.enforce_required_fieldsk   sy    
 * #kk
)
  ,335@ -J,,,) 	 

 !-jAA 
s   !A&A&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.
)rW   r[   r+   r5   r   )r   r]   r   r^   r"   sourcesr[   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'   r)   r   r]   r   r+   s       r   r,   0UniqueTogetherValidator.exclude_current_instance   r.   r   c           	         U R                  X5        U R                  nU R                  XU5      nU R                  XUR                  5      nUR                  c6  UR                  5        VVs/ s H  u  pEX@R                  ;   d  M  UPM     nnnOQUR                  5        VVs/ s H4  u  pEX@R                  ;   d  M  U[        UR                  U5      :w  d  M2  UPM6     nnnU(       aV  S U;  aO  [        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nf s  snnf )Nz, )field_namesr1   r2   )r`   r   r$   r,   r+   itemsrW   r5   r   joinr   formatr   )	r   r]   r^   r   fieldr!   checked_valuesri   r   s	            r   r8    UniqueTogetherValidator.__call__   s0   $$U7==''D00*BUBUV &*/++-*7,%5KK;O-  N %*KKM$1LEKK' ,1WZ=P=PRW5X,X $1   d.8Yx=P=P))DKK0Kll))k)BG!'99 >Q8>
s   ,D>D>"E;EEc                     SU R                   R                  < S[        U R                  5      < S[        U R                  5      < S3$ )Nr;   r<   z	, fields=r=   )r>   r?   r   r   rW   r@   s    r   rA    UniqueTogetherValidator.__repr__   s1    NN##t}}%t{{#
 	
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   )rD   r>   rE   r   rF   r\   r   rW   rG   s     r   rI   UniqueTogetherValidator.__eq__   s    %00!!- 0))U-C-CC0((E,A,AA0 MMU^^30 KK5<</		r   )rW   r   r   r   )r?   rL   rM   rN   rO   rP   r   r\   rF   r   r`   r$   r,   r8   rA   rI   rQ   r   r   r   rS   rS   \   sI    
 BCG12O/
B 40:0
r   rS   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).0chs     r   	<genexpr>@ProhibitSurrogateCharactersValidator.__call__.<locals>.<genexpr>   s/      $D2'-R'BF'B %''B %'s   --	-)
code_pointr2   )strr   rl   rz   r   r3   )r   r!   surrogate_characterr   s       r   r8   -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   )rD   r>   rE   r   r3   rG   s     r   rI   +ProhibitSurrogateCharactersValidator.__eq__   sA    %00!!- ,II+	r   r   N)
r?   rL   rM   rN   rP   r   r3   r8   rI   rQ   r   r   r   ru   ru      s    IJG-D;r   ru   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   NrU   Tc                 \    Xl         X l        X0l        U=(       d    U R                  U l        g r   )r   rm   
date_fieldr   )r   r   rm   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.
rZ   r2   N)rm   r   r\   r   )r   r]   r"   r_   s       r   r`   .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   r]   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'   r)   rf   s       r   r,   /BaseUniqueForValidator.exclude_current_instance   r.   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 )Nr0   )r   r1   r2   )rW   rm   r4   r   r`   r   r$   r,   r+   r   r   rl   r   )r   r]   r^   r"   r   r   r   s          r   r8   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   )	rD   r>   rE   r   r\   rF   r   rm   r   rG   s     r   rI   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	$ )Nr;   r<   z, field=z, date_field=r=   )r>   r?   r   r   rm   r   r@   s    r   rA   BaseUniqueForValidator.__repr__  s=    NN##t}}%tzz"t'	
 	
r   )r   rm   r   r   r   )r?   rL   rM   rN   r   rP   r\   rF   r   r`   r$   r,   r8   rI   rA   rQ   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)UniqueForDateValidatori   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)rm   r   daymonthyearr   r   r]   r   r"   r   r!   dater#   s           r   r$   &UniqueForDateValidator.filter_queryset#  sp    jj!__%$)j!59XXi/127;zzkO346:iij?233]33r   r   Nr?   rL   rM   rN   rP   r   r$   rQ   r   r   r   r   r      s    HIG	4r   r   c                   *    \ rS rSr\" S5      rS rSrg)UniqueForMonthValidatori/  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   )rm   r   r   r   r   s           r   r$   'UniqueForMonthValidator.filter_queryset2  sJ    jj!__%$)j!7;zzkO343]33r   r   Nr   r   r   r   r   r   /  s    IJG4r   r   c                   *    \ rS rSr\" S5      rS rSrg)UniqueForYearValidatori<  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   )rm   r   r   r   r   s           r   r$   &UniqueForYearValidator.filter_queryset?  sJ    jj!__%$)j!6:iij?233]33r   r   Nr   r   r   r   r   r   <  s    HIG4r   r   N)rO   	django.dbr   django.utils.translationr   rP   rest_framework.exceptionsr   #rest_framework.utils.representationr   r   r   r   rS   ru   r   r   r   r   r   r   r   <module>r      sx      6 5 :8 8vg gT $E
 E
P43 4
44 
4
43 
4r   