
    NwgG                    :   d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZmZ d dlmZmZ  ed	e
j2                  d
      Z e       Z G d de
j2                        Z G d de
j2                        Z G d de
j2                        ZddZddZ e
jB                  jD                  jG                  e       e
jB                  jD                  jG                  e        ddZ$ G d de
j2                        Z% G d de
j2                        Z&y)    )annotations)AnyLiteralTypeVaroverload)ImproperlyConfigured)models)Now)gettext_lazy)AutoCreatedFieldAutoLastModifiedFieldMonitorFieldStatusField	UUIDField)QueryManagerSoftDeletableManagerModelTT)bound	covariantc                  p     e Zd ZdZ e ed            Z e ed            Zd fdZ	 G d d      Z
 xZS )TimeStampedModelzl
    An abstract base class model that provides self-updating
    ``created`` and ``modified`` fields.

    createdmodifiedc                    |j                  dd      }|rt        |      j                  dh      |d<   t        |   |i | y)z
        Overriding the save method in order to make sure that
        modified field is updated even if it is not given as
        a parameter to the update field argument.
        update_fieldsNr   getsetunionsupersaveselfargskwargsr   	__class__s       I/var/www/horilla/myenv/lib/python3.12/site-packages/model_utils/models.pyr!   zTimeStampedModel.save!   sE     

?D9&)-&8&>&>
|&LF?#d%f%    c                      e Zd ZdZy)TimeStampedModel.MetaTN__name__
__module____qualname__abstract r(   r'   Metar*   -       r(   r1   r$   r   r%   r   returnNone)r,   r-   r.   __doc__r   _r   r   r   r!   r1   __classcell__r&   s   @r'   r   r      s5    
 q|,G$Qz]3H
& r(   r   c                      e Zd ZdZ ej
                   ed      dd      Z ej
                   ed      dd      Z G d d      Z	y)	TimeFramedModelzm
    An abstract base class model that provides ``start``
    and ``end`` fields to record a timeframe.

    startT)nullblankendc                      e Zd ZdZy)TimeFramedModel.MetaTNr+   r0   r(   r'   r1   rA   :   r2   r(   r1   N)
r,   r-   r.   r6   r	   DateTimeFieldr7   r<   r?   r1   r0   r(   r'   r;   r;   1   sG    
 !F  7$dCE
&

qxd$
?C r(   r;   c                  t     e Zd ZdZ e ed            Z e ed      d      Zd fdZ	 G d d      Z
 xZS )	StatusModelaD  
    An abstract base class model with a ``status`` field that
    automatically uses a ``STATUS`` class attribute of choices, a
    ``status_changed`` date-time field that records when ``status``
    was last modified, and an automatically-added manager for each
    status that returns objects with that status only.

    statuszstatus changed)monitorc                    |j                  dd      }|r"d|v rt        |      j                  dh      |d<   t        |   |i | y)z
        Overriding the save method in order to make sure that
        status_changed field is updated even if it is not given as
        a parameter to the update field argument.
        r   NrE   status_changedr   r"   s       r'   r!   zStatusModel.saveJ   sN     

?D9X6&)-&8&>&>@P?Q&RF?#d%f%r(   c                      e Zd ZdZy)StatusModel.MetaTNr+   r0   r(   r'   r1   rJ   V   r2   r(   r1   r3   )r,   r-   r.   r6   r   r7   rE   r   rH   r!   r1   r8   r9   s   @r'   rD   rD   >   s9     8%F!!$4"5xHN
& r(   rD   c                B   t        | t              sy| j                  j                  }|J t	        | dd      D ]I  \  }}t        | |      rt        d| j                  d|d      | j                  |t        |             K |j                  | j                  _        y)z?
    Add a Querymanager for each status item dynamically.

    NSTATUSr0   zStatusModel: Model 'z' has a field named 'z1' which conflicts with a status of the same name.)rE   )
issubclassrD   _metadefault_managergetattr_field_existsr   r,   add_to_classr   namedefault_manager_name)senderr%   rO   valuedisplays        r'   add_status_query_managersrX   Z   s    
 fk*ll22O&&&!&(B7 ?w'& ??E+ 
 	E<u#=>? )8(<(<FLL%r(   c           
     f   t        | t              syt        | d      rt        d| j                  z        | j                  dt        t        j                  t              t        j                  d      z  t        j                  t              t        j                  d      z  z               y)	z7
    Add a QueryManager for a specific timeframe.

    N
timeframedz[Model '%s' has a field named 'timeframed' which conflicts with the TimeFramedModel manager.)
start__lteT)start__isnull)end__gte)end__isnull)
rM   r;   rQ   r   r,   rR   r   r	   Qnow)rU   r%   s     r'   add_timeframed_query_managerra   q   s    
 fo.V\*"@oo
 	

 l	S	!FHH4$@	@88S!FHH$>>	@' r(   c                l    || j                   j                  D cg c]  }|j                   c}v S c c}w N)rN   local_fieldsattname)model_class
field_namefs      r'   rQ   rQ      s+    [->->-K-KL!))LLLLs   1c                  (    e Zd ZU dZ ej
                  d      Z G d d      Z ed      Z	de
d	<    e       Zde
d
<    ej                         Ze	 ddd	 	 	 	 	 	 	 	 	 dd       Ze	 d	 	 	 	 	 	 	 	 	 dd       Z	 ddd	 	 	 	 	 	 	 	 	 d fdZ xZS )SoftDeletableModelz
    An abstract base class model with a ``is_removed`` field that
    marks entries that are not going to be used anymore, but are
    kept in db for any reason.
    Default manager returns only not-removed entries.
    F)defaultc                      e Zd ZdZy)SoftDeletableModel.MetaTNr+   r0   r(   r'   r1   rm      r2   r(   r1   T)_emit_deprecation_warningsz"models.Manager[SoftDeletableModel]objectsavailable_objects)softc                    y rc   r0   r#   usingrq   r$   r%   s        r'   deletezSoftDeletableModel.delete        	r(   c                    y rc   r0   rs   s        r'   ru   zSoftDeletableModel.delete   rv   r(   c               b    |rd| _         | j                  |       yt        |   |g|i |S )z
        Soft delete object (set its ``is_removed`` field to True).
        Actually delete object if setting ``soft`` to False.
        T)rt   N)
is_removedr!   r    ru   )r#   rt   rq   r$   r%   r&   s        r'   ru   zSoftDeletableModel.delete   s9     "DOIIEI"7>%9$9&99r(   rc   )
rt   r   r$   r   rq   zLiteral[True]r%   r   r4   r5   )
rt   r   r$   r   rq   zLiteral[False]r%   r   r4   ztuple[int, dict[str, int]])
rt   r   r$   r   rq   boolr%   r   r4   z!tuple[int, dict[str, int]] | None)r,   r-   r.   r6   r	   BooleanFieldry   r1   r   ro   __annotations__rp   Managerall_objectsr   ru   r8   r9   s   @r'   rj   rj      s    %$$U3J  3Gbf2gG/g<P<R9R &.."K
 CG(+3@SV	 
 (+3AMP	#   ::>::(+:37:JM:	*: :r(   rj   c                  :    e Zd ZdZ eddd      Z G d d      Zy)		UUIDModelzz
    This abstract base class provides id field on any model that inherits from it
    which will be the primary key.
    T   F)primary_keyversioneditablec                      e Zd ZdZy)UUIDModel.MetaTNr+   r0   r(   r'   r1   r      r2   r(   r1   N)r,   r-   r.   r6   r   idr1   r0   r(   r'   r   r      s&     

B r(   r   N)rU   type[models.Model]r%   r   r4   r5   )rf   r   rg   strr4   rz   )'
__future__r   typingr   r   r   r   django.core.exceptionsr   	django.dbr	   django.db.models.functionsr
   django.utils.translationr   r7   model_utils.fieldsr   r   r   r   r   model_utils.managersr   r   Modelr   r`   r   r;   rD   rX   ra   signalsclass_preparedconnectrQ   rj   r   r0   r(   r'   <module>r      s    " 2 2 7  * 6  D		>	ev|| 2
fll 
&,, 8=.&    % %&? @    % %&B CM+: +:\ r(   