
    h!                     ^    S SK Jr  S SKJr  S SKJrJr  S SKJrJ	r	  S SK
Jr   " S S\5      rg)	    )apps)NotRegistered)FieldDoesNotExistPermissionDenied)Http404JsonResponse)BaseListViewc                   H    \ rS rSrSrSrSrS rS rS r	S r
S	 rSS
 jrSrg)AutocompleteJsonView   z3Handle AutocompleteWidget's AJAX requests for data.   Nc           	      `   U R                  U5      u  U l        U l        U l        nU R	                  U5      (       d  [
        eU R                  5       U l        U R                  5       n[        US    Vs/ s H  nU R                  Xd5      PM     snSUS   R                  5       0S.5      $ s  snf )z
Return a JsonResponse with search results as defined in
serialize_result(), by default:
{
    results: [{id: "123" text: "foo"}],
    pagination: {more: true}
}
object_listmorepage_obj)results
pagination)process_requesttermmodel_adminsource_fieldhas_permr   get_querysetr   get_context_datar   serialize_resulthas_next)selfrequestargskwargsto_field_namecontextobjs          Y/var/www/html/env/lib/python3.13/site-packages/django/contrib/admin/views/autocomplete.pygetAutocompleteJsonView.get   s       )	
I }}W%%"",,.'')  '}55 ))#=5  &wz':'C'C'EF
 	
s   3B+c                 B    [        [        X5      5      [        U5      S.$ )zV
Convert the provided model object to a dictionary that is added to the
results list.
)idtext)strgetattr)r   r#   r!   s      r$   r   %AutocompleteJsonView.serialize_result-   s    
 '#56CII    c                 V    U R                   R                  " U R                  /UQ70 UD6$ )zUse the ModelAdmin's paginator.)r   get_paginatorr   )r   r   r    s      r$   r/   "AutocompleteJsonView.get_paginator4   s'    --dllLTLVLLr-   c                 4   U R                   R                  U R                  5      nUR                  U R                  R                  5       5      nU R                   R                  U R                  XR                  5      u  pU(       a  UR                  5       nU$ )z9Return queryset based on ModelAdmin.get_search_results().)	r   r   r   complex_filterr   get_limit_choices_toget_search_resultsr   distinct)r   qssearch_use_distincts      r$   r   !AutocompleteJsonView.get_queryset8   sv    **4<<8t00EEGH"&"2"2"E"ELL"ii#
 B	r-   c                    UR                   R                  SS5      n UR                   S   nUR                   S   nUR                   S   n [        R
                  " X45      n UR                  R                  U5      n UR                  R                  n	 U R                  R                  U	5      n
U
R!                  U5      (       d!  [#        S[%        U
5      R&                  -  5      e[)        UR                  SU	R                  R*                  R,                  5      nU	R                  R                  U5      R,                  nU
R/                  X5      (       d  [        eX*X4$ ! [         a  n[        UeSnAff = f! [         a  n[        UeSnAff = f! [         a  n[        UeSnAff = f! [         a  n[        UeSnAff = f! [         a  n[        UeSnAff = f)aN  
Validate request integrity, extract and return request parameters.

Since the subsequent view permission check requires the target model
admin, which is determined here, raise PermissionDenied if the
requested app, model or field are malformed.

Raise Http404 if the target model admin is not configured properly with
search_fields.
r    	app_label
model_name
field_nameNz5%s must have search_fields for the autocomplete_view.)GETr%   KeyErrorr   r   	get_modelLookupError_meta	get_fieldr   remote_fieldmodelAttributeError
admin_siteget_model_adminr   get_search_fieldsr   type__qualname__r+   pkattnameto_field_allowed)r   r   r   r;   r<   r=   esource_modelr   remote_modelr   r!   s               r$   r   $AutocompleteJsonView.process_requestC   s    {{vr*	*K0I \2J \2J
	*>>)@L	*'--77
CL	*'44::L	*//99,GK
 ,,W55G{#001 
  %%|\5G5G5J5J5R5R
 %**44]CKK++GCC"",==I  	*")	*  	*")	*
 ! 	*")	*  	*")	*  	*")	*sw   -E" E; #F ?F- G "
E8,E33E8;
FFF
F*F%%F*-
G7F>>G
GGGc                 4    U R                   R                  XS9$ )z9Check if user has permission to access the related model.)r#   )r   has_view_permission)r   r   r#   s      r$   r   AutocompleteJsonView.has_permy   s    33G3EEr-   )r   r   r   r   )N)__name__
__module__rK   __firstlineno____doc__paginate_byrG   r%   r   r/   r   r   r   __static_attributes__ r-   r$   r   r      s1    =KJ
>JM	4>lFr-   r   N)django.appsr   django.contrib.admin.exceptionsr   django.core.exceptionsr   r   django.httpr   r   django.views.generic.listr	   r   r\   r-   r$   <module>rb      s$     9 F - 2sF< sFr-   