
    D6i                         d dl m Z mZ d dlZ G d d      Zej
                  j                  edd      d        Zd	Zd
 Z	d Z
y)    )datetimetimezoneNc                       e Zd ZdZ ej
                  ej                  d d      Z ej
                  ej                  d d      Zy)	Timestampa  Adds `created` and `updated` columns to a derived declarative model.

    The `created` column is handled through a default and the `updated`
    column is handled through a `before_update` event that propagates
    for all derived declarative models.

    ::


        import sqlalchemy as sa
        from sqlalchemy_utils import Timestamp


        class SomeModel(Base, Timestamp):
            __tablename__ = 'somemodel'
            id = sa.Column(sa.Integer, primary_key=True)
    c                  j    t        j                  t        j                        j	                  d       S N)tz)tzinfor   nowr   utcreplace     Z/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/sqlalchemy_utils/models.py<lambda>zTimestamp.<lambda>   !    5==T=J r   F)defaultnullablec                  j    t        j                  t        j                        j	                  d       S r   r   r   r   r   r   zTimestamp.<lambda>    r   r   N)	__name__
__module____qualname____doc__saColumnDateTimecreatedupdatedr   r   r   r   r      sE    $ bii
JG
 bii
JGr   r   before_updateT)	propagatec                 v    t        j                  t        j                        j	                  d       |_        y r   )r   r   r   r   r   r   )mapper
connectiontargets      r   timestamp_before_updater&   %   s&     \\X\\2::$:GFNr   z<not loaded>c                    t        j                  |       }g }|s$|j                  j                  j	                         }|D ]]  }|j
                  |   j                  }||j                  v rt        }nt        |      }|j                  dj                  ||f             _ dj                  | j                  j                  dj                  |            S )N=z{}({})z, )r   inspectr#   columnskeysattrsloaded_valueunloadedNOT_LOADED_REPRreprappendjoinformat	__class__r   )selffieldsstatefield_reprskeyvalues         r   _generic_repr_methodr;   /   s    JJtEK%%**, 3C --%.. #EKE388S%L123 ??4>>22DIIk4JKKr   c                  h     t               dk(  rt         d         r d   }d |_        |S  fd}|S )a  Adds generic ``__repr__()`` method to a declarative SQLAlchemy model.

    In case if some fields are not loaded from a database, it doesn't
    force their loading and instead repesents them as ``<not loaded>``.

    In addition, user can provide field names as arguments to the decorator
    to specify what fields should present in the string representation
    and in what order.

    Example::


        import sqlalchemy as sa
        from sqlalchemy_utils import generic_repr


        @generic_repr
        class MyModel(Base):
            __tablename__ = 'mymodel'
            id = sa.Column(sa.Integer, primary_key=True)
            name = sa.Column(sa.String)
            category = sa.Column(sa.String)

        session.add(MyModel(name='Foo', category='Bar'))
        session.commit()
        foo = session.query(MyModel).options(sa.orm.defer('category')).one(s)

        assert repr(foo) == 'MyModel(id=1, name='Foo', category=<not loaded>)'
       r   c                     t        | d       S N)r6   r;   )r5   s    r   r   zgeneric_repr.<locals>.<lambda>_   s    ';D'N r   c                     fd| _         | S )Nc                     t        |       S r?   r@   )r5   r6   s    r   r   z1generic_repr.<locals>.decorator.<locals>.<lambda>d   s    (<T&(Q r   )__repr__)clsr6   s    r   	decoratorzgeneric_repr.<locals>.decoratorc   s    QCLJr   )lencallablerC   )r6   r%   rE   s   `  r   generic_reprrH   ?   s>    < 6{aHVAY/N	 r   )r   r   
sqlalchemyr   r   eventlistens_forr&   r/   r;   rH   r   r   r   <module>rL      sT    '  > iDAH BH !L (r   