
    R
h                     <   d Z ddlmZmZ ddlmZmZ ddl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 ddlmZmZ d Z G d dee          Z G d d          Z G d d          Z G d dee          Z G d de          Z G d dee          ZdS )z
Agnocomplete views.
    )abstractmethodABCMeta)PermissionDeniedSuspiciousOperation)Http404JsonResponse)	force_str)cached_property)View   get_agnocomplete_registry)+AuthenticationRequiredAgnocompleteExceptionImproperlyConfiguredView)	HTTPErrorTimeoutc                 F   t          | t                    r%| j        j        t	          | j        j                  fS t          | t                    rd| fS t          | t                    rd| fS t          | t                    rd| fS t          | t                    rd| fS d| fS )zS
    Return the appropriate HTTP status code according to the Exception/Error.
    i  i  i  i  i  )

isinstancer   responsestatus_codetextcontentr   r   r   r   )excs    ]/var/www/html/01_SiteInternet/03_Maps/venv/lib/python3.11/site-packages/agnocomplete/views.py	get_errorr      s    
 #y!! D|'cl.B)C)CCC#w Cx#w Cx#'(( Cx#*++ Cx 8O    c                   J    e Zd ZdZed             Zed             Zd Zd Z	dS )AgnocompleteJSONViewz2
    Generic toolbox for JSON-returning views
    c                 &    d| j         j        v rdS dS )a  
        Return content-type of the response.
        For a JSONResponseMixin, the obvious answer is ``application/json``.
        But Internet Explorer v8 can't handle this content-type and instead
        of processing it as a normal AJAX data response, it tries to download
        it.
        We're tricking this behaviour by sending back a ``text/html``
        content-type header instead.
        HTTP_X_REQUESTED_WITHzapplication/json;charset=utf-8z	text/html)requestMETAselfs    r   content_typez!AgnocompleteJSONView.content_type5   s     #dl&77733;r   c                     d S )N r$   kwargss     r   get_datasetz AgnocompleteJSONView.get_datasetE   s    r   c                 z    t          d | j        j                                                  }t	          |          S )Nc                     | d         dk    S )Nr   qr'   )xs    r   <lambda>z:AgnocompleteJSONView.get_extra_arguments.<locals>.<lambda>J   s    1 r   )filterr!   GETitemsdict)r$   extras     r   get_extra_argumentsz(AgnocompleteJSONView.get_extra_argumentsI   s2    ,,dl.>.D.D.F.FGGE{{r   c                 $   	  | j         di |                                 }t          d|i| j                  S # t          $ rL}t          |          \  }}t          ddd                    |          dgi| j        |          cY d }~S d }~ww xY w)	Ndata)r%   errorszAn error has occurredz{})titledetail)r%   statusr'   )r*   r5   r   r%   	Exceptionr   format)r$   argsr)   datasetr   r;   messages          r   getzAgnocompleteJSONView.getM   s    	&d&DD)A)A)C)CDDG!!.     		 		 		'nnOFG4"kk'22    ".        		s   69 
BAB
B
BN)
__name__
__module____qualname____doc__propertyr%   r   r*   r5   rA   r'   r   r   r   r   0   sr            X   ^      r   r   )	metaclassc                   (    e Zd ZdZed             ZdS )RegistryMixinzA
    This mixin is able to return the agnocomplete registry.
    c                     t                      S )z;
        Return the agnocomplete registry (cached)
        r   r#   s    r   registryzRegistryMixin.registryd   s    
 )***r   N)rB   rC   rD   rE   r
   rK   r'   r   r   rI   rI   `   s9          + + _+ + +r   rI   c                   (     e Zd ZdZd Z fdZ xZS )UserContextFormViewMixinzK
    This mixin is injecting the context variable into the form kwargs
    c                     | j         j        S )zt
        Return the view current user.

        You may want to change this value by overrding this method.
        )r!   userr#   s    r   get_agnocomplete_contextz1UserContextFormViewMixin.get_agnocomplete_contextq   s     |  r   c                     t                                                      }|                    d|                                 i           |S )z
        Return the form kwargs.

        This method injects the context variable, defined in
        :meth:`get_agnocomplete_context`. Override this method to adjust it to
        your needs.
        rO   )superget_form_kwargsupdaterP   )r$   r7   	__class__s     r   rS   z(UserContextFormViewMixin.get_form_kwargsy   sM     ww&&((D1133
 	 	 	 r   )rB   rC   rD   rE   rP   rS   __classcell__)rU   s   @r   rM   rM   l   sQ         ! ! !        r   rM   c                       e Zd ZdZd ZdS )CatalogViewzd
    The catalog view displays every available Agnocomplete slug available in
    the registry.
    c                 N    t          | j                                                  S )z.
        Return the registry key set.
        )tuplerK   keysr(   s     r   r*   zCatalogView.get_dataset   s      T]''))***r   N)rB   rC   rD   rE   r*   r'   r   r   rX   rX      s-         + + + + +r   rX   c                       e Zd Zd Zd ZdS )AgnocompleteGenericViewc                 \    t          | d          r| j        r| j        S t          d          )S
        Return the agnocomplete class to be used with the eventual query.
        klasszUndefined autocomplete class)hasattrr`   r   r#   s    r   	get_klassz!AgnocompleteGenericView.get_klass   s6    
 4!! 	dj 	:&'EFFFr   c                    |                                  }| j        j                            dd          }|sg S 	 t	          | j        j                            dd                     }n# t
          $ r d }Y nw xY w	  || j        j        |          } |j        dd|i|S # t          $ r t          d          t
          $ r  w xY w)Nr-    	page_size)rO   re   queryz(Unauthorized access to this Autocompleter'   )
rb   r!   r1   rA   intr<   rO   r2   r   r   )r$   r)   r`   rf   re   instances         r   r*   z#AgnocompleteGenericView.get_dataset   s      $$S"-- 	I	DL,00dCCDDII 	 	 	III		u$,"3yIIIH!8>888888: 	< 	< 	<":< < < 	 	 		s   -A( (A76A7;%B! !$CN)rB   rC   rD   rb   r*   r'   r   r   r]   r]      s5        G G G    r   r]   c                       e Zd Zd ZdS )AgnocompleteViewc                     | j                             dd          }| j                            |d          }|s"t          d                    |                    |S )r_   r`   NzUnknown autocomplete class `{}`)r)   rA   rK   r   r=   )r$   
klass_namer`   s      r   rb   zAgnocompleteView.get_klass   s[    
 [__Wd33
!!*d33 	P;BB:NNOOOr   N)rB   rC   rD   rb   r'   r   r   rj   rj      s#        	 	 	 	 	r   rj   N) rE   abcr   r   django.core.exceptionsr   r   django.httpr   r   django.utils.encodingr	   r   django.utils.functionalr
   django.views.genericr   registerr   
exceptionsr   r   requests.exceptionsr   r   r   r   rI   rM   rX   r]   rj   r'   r   r   <module>rv      s    ( ' ' ' ' ' ' ' H H H H H H H H - - - - - - - - 3 3 3 3 3 3 3 3 3 3 3 3 % % % % % % / / / / / /        3 2 2 2 2 2 2 2  :- - - - -47 - - - -`	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+       8	+ 	+ 	+ 	+ 	+-!5 	+ 	+ 	+! ! ! ! !2 ! ! !H    }&=     r   