Ë
    £2Úi  ã                   óR   — d dl mZ d dlmZ d dlmZ  G d„ dej                  «      Zy)é    )Úsettings)Úmodels)ÚFieldDoesNotExistc                   óJ   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd	ˆ fd„	Zd	d„Zd„ Zd„ Z	ˆ xZ
S )
ÚHostSiteManageraÉ  
    A model manager to limit objects to those associated with a site.

    :param field_name: the name of the related field pointing at the
                       :class:`~django.contrib.sites.models.Site` model,
                       or a series of relations using the
                       ``field1__field2__field3`` notation. Falls back
                       to looking for 'site' and 'sites' fields.
    :param select_related: a boolean specifying whether to use
                           :meth:`~django.db.models.QuerySet.select_related`
                           when querying the database

    Define a manager instance in your model class with one
    of the following notations::

        on_site = HostSiteManager()  # automatically looks for site and sites
        on_site = HostSiteManager("author__site")
        on_site = HostSiteManager("author__blog__site")
        on_site = HostSiteManager("author__blog__site",
                                  select_related=False)

    Then query against it with one of the manager methods::

        def home_page(request):
            posts = BlogPost.on_site.by_request(request).all()
            return render(request, 'home_page.html', {'posts': posts})

    c                 ób   •— t         t        | �  «        || _        || _        d| _        d| _        y )Né   F)Úsuperr   Ú__init__Ú_field_nameÚ_select_relatedÚ_depthÚ_is_validated)ÚselfÚ
field_nameÚselect_relatedÚ	__class__s      €úL/var/www/html/acx/venv/lib/python3.12/site-packages/django_hosts/managers.pyr   zHostSiteManager.__init__$   s/   ø€ ÜŒo˜tÑ-Ô/Ø%ˆÔØ-ˆÔØˆŒØ"ˆÕó    c                 ó¼  — d }| j                   �i| j                   j                  dd«      }t        |«      }|| j                  kD  r|| _        |d   }	 | j                  j
                  j                  |«      }n>dD ]9  }	 | j                  j
                  j                  |«      }|x| _         }d| _         n |r8t        |t        j                  t        j                  f«      sTt        dz  «      ‚t        | j                  j                   ›d›d| j                  j
                  j"                  ›d	�«      ‚d| _        y # t        $ r Y Œ“w xY w# t        $ r d }Y Œàw xY w)
NÚ__r	   r   )ÚsiteÚsitesTz+%s must be a ForeignKey or ManyToManyField.z couldn't find a field named z in ú.)r   ÚsplitÚlenr   ÚmodelÚ_metaÚ	get_fieldr   r   Ú
isinstancer   Ú
ForeignKeyÚManyToManyFieldÚ	TypeErrorÚ
ValueErrorr   Ú__name__Úobject_name)r   ÚfieldÚ
name_partsÚ	rel_depthr   Úpotential_names         r   Ú_validate_field_namez$HostSiteManager._validate_field_name+   se  € àˆØ×ÑÐ'Ø×)Ñ)×/Ñ/°°aÓ8ˆJÜ˜J›ˆIØ˜4Ÿ;™;Ò&Ø'�”Ø# A™ˆJðØŸ
™
×(Ñ(×2Ñ2°:Ó>‘ð
 #4ò �ðØ ŸJ™J×,Ñ,×6Ñ6°~ÓF�Eð 5CÐB�DÔ$ zØ)-�DÔ&Ùðñ Ü˜e¤f×&7Ñ&7Ü&,×&<Ñ&<ð&>ô ?äð !3Ø5?ñ!@ó Að Aô Ø"Ÿn™n×5Ó5²zØ"Ÿj™j×.Ñ.×:Ó:ð<ó =ð =ð "ˆÕøô/ %ò Ùðûô )ò &Ø!%’Jð&ús$   Á%D> Á>%EÄ>	E
Å	E
ÅEÅEc                 óÆ   •— |€t         j                  }| j                  s| j                  «        t        t
        | �  «       } |j                  di d| j                  z  |i¤ŽS )Nz%s__id__exact© )	r   ÚSITE_IDr   r+   r
   r   Úget_querysetÚfilterr   )r   Úsite_idÚqsr   s      €r   r/   zHostSiteManager.get_querysetO   s[   ø€ Øˆ?Ü×&Ñ&ˆGØ×!Ò!Ø×%Ñ%Ô'Ü”? DÑ6Ó8ˆØˆr�y‰yÑI˜O¨d×.>Ñ.>Ñ>ÀÐHÑIÐIr   c                 ó$   — | j                  |«      S )zç
        Returns a queryset matching the given site id. If not given
        this falls back to the ``SITE_ID`` setting.

        :param site_id: the ID of the site
        :rtype: :class:`~django.db.models.query.QuerySet`
        )r/   )r   r1   s     r   Úby_idzHostSiteManager.by_idW   s   € ð × Ñ  Ó)Ð)r   c                 óˆ   — t        |d«      r|j                  €| j                  «       S | j                  |j                  «      S )zù
        Returns a queryset matching the given request's site
        attribute.

        :param request: the current request
        :type request: :class:`~django.http.HttpRequest`
        :rtype: :class:`~django.db.models.query.QuerySet`
        r   )Úhasattrr   ÚnoneÚby_site)r   Úrequests     r   Ú
by_requestzHostSiteManager.by_requesta   s6   € ô �w Ô'¨7¯<©<Ð+?Ø—9‘9“;ÐØ�|‰|˜GŸL™LÓ)Ð)r   c                 ó8   — | j                  |j                  «      S )zÜ
        Returns a queryset matching the given site.

        :param site: a site instance
        :type site: :class:`~django.contrib.sites.models.Site`
        :rtype: :class:`~django.db.models.query.QuerySet`
        )r4   Úid)r   r   s     r   r8   zHostSiteManager.by_siten   s   € ð �z‰z˜$Ÿ'™'Ó"Ð"r   )NT)N)r%   Ú
__module__Ú__qualname__Ú__doc__r   r+   r/   r4   r:   r8   Ú__classcell__)r   s   @r   r   r      s(   ø„ ñõ:#ò""õHJó*ò*ö#r   r   N)Údjango.confr   Ú	django.dbr   Údjango.core.exceptionsr   ÚManagerr   r-   r   r   ú<module>rE      s    ðÝ  Ý Ý 4ôp#�f—n‘nõ p#r   