
    Sf                         d dl mZ d dlmZ d dlmZ ddlmZ  eedd          Z	 G d d	e          Z
 G d
 de
          Zd Zd ZdS )    )settings)get_object_or_404)
LazyObject   )reverse_hostHOST_SITE_TIMEOUTi  c                   $     e Zd Z fdZd Z xZS )LazySitec                     t          t          |                                            | j                            |j        j        ||d           d S )N)nameargskwargs)superr
   __init____dict__updatehostr   )selfrequestr   r   	__class__s       H/var/www/html/env/lib/python3.11/site-packages/django_hosts/callbacks.pyr   zLazySite.__init__   s[    h&&(((L%
 
 	 	 	 	 	    c                     t          | j        | j        | j                  }ddlm} t          ||          }|| _        d S )Nr   r   r   Sitedomain__iexact)r   r   r   r   django.contrib.sites.modelsr   r   _wrapped)r   r   r   sites       r   _setupzLazySite._setup   sK    DIDIdkJJJ444444 d;;;r   )__name__
__module____qualname__r   r"   __classcell__)r   s   @r   r
   r
   
   sG                  r   r
   c                       e Zd Zd ZdS )CachedLazySitec                    t          | j        | j        | j                  }d|z  }ddlm} |                    |d           }|	|| _        d S ddlm	} t          ||          }|                    ||t                     || _        d S )Nr   zhosts:%sr   )cacher   r   )r   r   r   r   django.core.cacher*   getr    r   r   r   setr   )r   r   	cache_keyr*   r!   r   s         r   r"   zCachedLazySite._setup   s    DIDIdkJJJ%	++++++yyD)) DMF444444 d;;;		)T#4555r   N)r#   r$   r%   r"    r   r   r(   r(      s#            r   r(   c                 0    t          | g|R i || _        dS )a  
    A callback function which uses the :mod:`django.contrib.sites` contrib
    app included in Django to match a host to a
    :class:`~django.contrib.sites.models.Site` instance, setting a
    ``request.site`` attribute on success.

    :param request: the request object passed from the middleware
    :param \*args: the parameters as matched by the host patterns
    :param \*\*kwargs: the keyed parameters as matched by the host patterns

    It's important to note that this uses
    :func:`~django_hosts.resolvers.reverse_host` behind the scenes to
    reverse the host with the given arguments and keyed arguments to
    enable a flexible configuration of what will be used to retrieve
    the :class:`~django.contrib.sites.models.Site` instance -- in the end
    the callback will use a ``domain__iexact`` lookup to get it.

    For example, imagine a host conf with a username parameter::

        from django.conf import settings
        from django_hosts import patterns, host

        settings.PARENT_HOST = 'example.com'

        host_patterns = patterns('',
            host(r'www', settings.ROOT_URLCONF, name='www'),
            host(r'(?P<username>\w+)', 'path.to.custom_urls',
                 callback='django_hosts.callbacks.host_site',
                 name='user-sites'),
        )

    When requesting this website with the host ``jezdez.example.com``,
    the callback will act as if you'd do::

        request.site = Site.objects.get(domain__iexact='jezdez.example.com')

    ..since the result of calling :func:`~django_hosts.resolvers.reverse_host`
    with the username ``'jezdez'`` is ``'jezdez.example.com'``.

    Later, in your views, you can nicely refer to the current site
    as ``request.site`` for further site-specific functionality.
    N)r
   r!   r   r   r   s      r   	host_siter2   +   s(    V G5d555f55GLLLr   c                 0    t          | g|R i || _        dS )a  
    A callback function similar to :func:`~django_hosts.callbacks.host_site`
    which caches the resulting :class:`~django.contrib.sites.models.Site`
    instance in the default cache backend for the time specfified as
    :attr:`~django.conf.settings.HOST_SITE_TIMEOUT`.

    :param request: the request object passed from the middleware
    :param \*args: the parameters as matched by the host patterns
    :param \*\*kwargs: the keyed parameters as matched by the host patterns
    N)r(   r!   r1   s      r   cached_host_siter4   Y   s'     "';D;;;F;;GLLLr   N)django.confr   django.shortcutsr   django.utils.functionalr   	resolversr   getattrr   r
   r(   r2   r4   r/   r   r   <module>r:      s                . . . . . . . . . . . . # # # # # #GH&94@@     z   "    X    +6 +6 +6\< < < < <r   