
    h%                     D    d Z ddlmZmZ dZ G d d      Z G d d      Zy)	z8
Context managers for temporary switching the language.
    )activateget_language)smart_overrideswitch_languagec                   "    e Zd ZdZd Zd Zd Zy)r   a  
    This is a smarter version of :func:`translation.override <django.utils.translation.override>`
    which avoids switching the language if there is no change to make.
    This method can be used in place of :func:`translation.override <django.utils.translation.override>`:

    .. code-block:: python

        with smart_override(self.get_current_language()):
            return reverse('myobject-details', args=(self.id,))

    This makes sure that any URLs wrapped in :func:`~django.conf.urls.i18n.i18n_patterns`
    will receive the correct language code prefix.
    When the URL also contains translated fields (e.g. a slug), use :class:`switch_language` instead.
    c                 0    || _         t               | _        y N)languager   old_language)selflanguage_codes     D/home/dcms/DCMS/lib/python3.12/site-packages/parler/utils/context.py__init__zsmart_override.__init__   s    %(N    c                 b    | j                   | j                  k7  rt        | j                          y y r	   r
   r   r   r   s    r   	__enter__zsmart_override.__enter__    s'     ==D---T]]# .r   c                 b    | j                   | j                  k7  rt        | j                         y y r	   r   r   exc_type	exc_value	tracebacks       r   __exit__zsmart_override.__exit__)   s'    ==D---T&&' .r   N__name__
__module____qualname____doc__r   r   r    r   r   r   r      s    +$(r   r   c                   $    e Zd ZdZddZd Zd Zy)r   a  
    A contextmanager to switch the translation of an object.

    It changes both the translation language, and object language temporary.

    This context manager can be used to switch the Django translations
    to the current object language.
    It can also be used to render objects in a different language:

    .. code-block:: python

        with switch_language(object, 'nl'):
            print object.title

    This is particularly useful for the :func:`~django.db.models.get_absolute_url` function.
    By using this context manager, the object language will be identical to the current Django language.

    .. code-block:: python

        def get_absolute_url(self):
            with switch_language(self):
                return reverse('myobject-details', args=(self.slug,))

    .. note::

       When the object is shared between threads, this is not thread-safe.
       Use :func:`~parler.models.TranslatableModel.safe_translation_getter` instead
       to read the specific field.
    Nc                     || _         |xs |j                         | _        t               | _        |j                         | _        y r	   )objectget_current_languager
   r   r   old_parler_language)r   r#   r   s      r   r   zswitch_language.__init__M   s9    %F)D)D)F(N#)#>#>#@ r   c                     | j                   | j                  k7  rt        | j                          | j                   | j                  k7  r&| j                  j                  | j                          y y r	   r
   r   r   r%   r#   set_current_languager   s    r   r   zswitch_language.__enter__S   sO     ==D---T]]#==D444KK,,T]]; 5r   c                     | j                   | j                  k7  rt        | j                         | j                   | j                  k7  r&| j                  j                  | j                         y y r	   r'   r   s       r   r   zswitch_language.__exit__^   sQ    ==D---T&&'==D444KK,,T-E-EF 5r   r	   r   r    r   r   r   r   .   s    <A	<Gr   r   N)r   django.utils.translationr   r   __all__r   r   r    r   r   <module>r,      s-    <( (D4G 4Gr   