Ë
    qûàgÅ  ã                   óD  — d dl Z d dlmZmZ d dlmZmZmZ d dl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 d dlmZ d dlmZ d dlmZ  G d„ d«      Z G d„ deej>                  «      Z  G d„ deejB                  «      Z" G d„ deejF                  «      Z$y)é    N)Úupdate_wrapperÚreduce)ÚTupleÚDictÚCallable)Úapps)ÚHttpResponseÚHttpResponseNotFound)Úsettings)Úmodels)ÚQuerySet)Ú	smart_str)Úgettext)Úget_text_list)Úadmin)ÚForeignKeySearchInputc                   óZ   ‡ — e Zd ZdZi Zi Z eedd«      Zˆ fd„Z	d„ Z
d„ Zd„ Zˆ fd„Zˆ xZS )	Ú ForeignKeyAutocompleteAdminMixinaÙ  
    Admin class for models using the autocomplete feature.

    There are two additional fields:
       - related_search_fields: defines fields of managed model that
         have to be represented by autocomplete input, together with
         a list of target model fields that are searched for
         input string, e.g.:

         related_search_fields = {
            'author': ('first_name', 'email'),
         }

       - related_string_functions: contains optional functions which
         take target model instance as only argument and return string
         representation. By default __unicode__() method of target
         object is used.

    And also an optional additional field to set the limit on the
    results returned by the autocomplete query. You can set this integer
    value in your settings file using FOREIGNKEY_AUTOCOMPLETE_LIMIT or
    you can set this per ForeignKeyAutocompleteAdmin basis. If any value
    is set the results will not be limited.
    ÚFOREIGNKEY_AUTOCOMPLETE_LIMITNc                 óö   •‡ — ddl m} ˆ fd„} |d |‰ j                  «      ‰ j                  j                  j
                  ›d‰ j                  j                  j                  ›d�¬«      gt        ‰‰ �!  «       z   S )Nr   )Úpathc                 ó*   •‡ — ˆˆ fd„}t        |‰ «      S )Nc                  óF   •—  ‰j                   j                  ‰«      | i |¤ŽS ©N)Ú
admin_siteÚ
admin_view)ÚargsÚkwargsÚselfÚviews     €€ú^/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django_extensions/admin/__init__.pyÚwrapperzHForeignKeyAutocompleteAdminMixin.get_urls.<locals>.wrap.<locals>.wrapper8   s$   ø€ Ø7�t—‘×1Ñ1°$Ó7¸ÐHÀÑHÐHó    )r   )r    r"   r   s   ` €r!   Úwrapz7ForeignKeyAutocompleteAdminMixin.get_urls.<locals>.wrap7   s   ù€ õIä! '¨4Ó0Ð0r#   zforeignkey_autocomplete/Ú_Ú_autocomplete)Úname)	Údjango.urlsr   Úforeignkey_autocompleteÚmodelÚ_metaÚ	app_labelÚ
model_nameÚsuperÚget_urls)r   r   r$   Ú	__class__s   `  €r!   r/   z)ForeignKeyAutocompleteAdminMixin.get_urls4   sj   ù€ Ý$ô	1ñ Ð+©T°$×2NÑ2NÓ-OØ-1¯Z©Z×-=Ñ-=×-GÓ-GÈÏÉ×IYÑIY×IdÓIdÐeôgð
ô ‰GÑÓñð 	r#   c                 óþ  — |j                   j                  dd«      }|j                   j                  dd«      }|j                   j                  dd«      }|j                   j                  dd«      }|j                   j                  dd«      }	 | j                  |   }|�r©|�r¦|�r£|s|�ržd„ }t	        j
                  ||«      }	|	j                  j                  «       }
d	}|�r<|j                  «       D ]«  }|j                  d
«      D �cg c]1  }t        j                  di  |t        |«      «      t        |«      i¤Ž‘Œ3 }}t        |	«      }|
j                  j                  |j                  _        |j                  t!        t"        j$                  |«      «      }|
|z  }
Œ­ | j'                  |	|«      }|r|
j                  |«      }
| j(                  r|
d| j(                   }
d	j+                  |
D �cg c]"  }t-        d«       ||«      |j.                  fz  ‘Œ$ c}«      }n|r	 |
j                  |¬«      } ||«      }t3        |d¬«      S t5        «       S # t        $ r d„ }Y �ŒÅw xY wc c}w c c}w # t0        $ r Y Œ?w xY w)z 
        Search in the fields of the given related model and returns the
        result as a simple string to be used by the jQuery Autocomplete plugin
        ÚqNr,   r-   Úsearch_fieldsÚ	object_pkc                 ó"   — | j                  «       S r   )Ú__str__)Úxs    r!   ú<lambda>zJForeignKeyAutocompleteAdminMixin.foreignkey_autocomplete.<locals>.<lambda>O   s   € ¨1¯9©9«;€ r#   c                 ó¢   — | j                  d«      rd| dd  z  S | j                  d«      rd| dd  z  S | j                  d«      rd| dd  z  S d| z  S )	Nú^z%s__istartswithé   ú=z
%s__iexactú@z
%s__searchz%s__icontains)Ú
startswith)Ú
field_names    r!   Úconstruct_searchzRForeignKeyAutocompleteAdminMixin.foreignkey_autocomplete.<locals>.construct_searchR   sj   € à×(Ñ(¨Ô-Ø,¨z¸!¸"¨~Ñ=Ð=Ø×*Ñ*¨3Ô/Ø'¨*°Q°R¨.Ñ8Ð8Ø×*Ñ*¨3Ô/Ø'¨*°Q°R¨.Ñ8Ð8à*¨ZÑ7Ð7r#   Ú ú,z%s|%s
)Úpkz
text/plain)Úcontent_type© )ÚGETÚgetÚrelated_string_functionsÚKeyErrorr   Ú	get_modelÚ_default_managerÚallÚsplitr   ÚQr   r   ÚqueryÚselect_relatedÚfilterr   ÚoperatorÚor_Úget_related_filterÚautocomplete_limitÚjoinÚstrrC   Ú	Exceptionr	   r
   )r   ÚrequestrO   r,   r-   r3   r4   Úto_string_functionr@   r*   ÚquerysetÚdataÚbitr?   Ú
or_queriesÚother_qsÚadditional_filterÚfÚobjs                      r!   r)   z8ForeignKeyAutocompleteAdminMixin.foreignkey_autocompleteA   s\  € ð
 —‘—‘  TÓ*ˆØ—K‘K—O‘O K°Ó6ˆ	Ø—[‘[—_‘_ \°4Ó8ˆ
ØŸ™Ÿ™¨¸Ó>ˆØ—K‘K—O‘O K°Ó6ˆ	ð	7Ø!%×!>Ñ!>¸zÑ!JÐò šYª:¹5ÂIò	8ô —N‘N 9¨jÓ9ˆEà×-Ñ-×1Ñ1Ó3ˆHØˆDÚØ Ÿ;™;›=ò 3�Cð {H÷  {Nñ  {Nð  ORó  {Sö  "TÐlv¤&§(¡(Ñ"gÑ.>¼yÈÓ?TÓ.UÔW`ÐadÓWeÐ-fÓ"gð  "T�Jð  "TÜ'¨›�HØ4<·N±N×4QÑ4Q�H—N‘NÔ1Ø'Ÿ™¬v´h·l±lÀJÓ/OÓP�HØ'¨(Ñ2‘Hð3ð %)×$;Ñ$;¸EÀ7Ó$KÐ!Ù$Ø'Ÿ™Ð/@ÓA�Hà×*Ò*Ø'Ð(@¨×)@Ñ)@ÐA�Hà—w‘wÐX`ÖaÐST¤ I£Ñ2DÀQÓ2GÈÏÉÐ1NÓ NÒaÓb‘Ùð3Ø"Ÿ,™,¨)˜,Ó4�Cñ .¨cÓ2�DÜ °<Ô@Ð@Ü#Ó%Ð%øôW ò 	7Ù!6Óð	7üò* "Tùò  bøô !ò Ùðús0   ÂI Ä	6I&Ç0'I+È"I0 ÉI#É"I#É0	I<É;I<c                  ó   — y)zú
        Given a model class and current request return an optional Q object
        that should be applied as an additional filter for autocomplete query.
        If no additional filtering is needed, this method should return
        None.
        NrE   )r   r*   rY   s      r!   rT   z3ForeignKeyAutocompleteAdminMixin.get_related_filter{   s   € ð r#   c                 óŒ   — | j                   j                  |d «      }|r&|t        |t        d«      «      dœ}t        d«      |z  S y)NÚand)r-   Ú
field_listzMUse the left field to do %(model_name)s lookups in the fields %(field_list)s.rA   )Úrelated_search_fieldsrG   r   r%   )r   r?   r-   Úsearchable_fieldsÚhelp_kwargss        r!   Úget_help_textz.ForeignKeyAutocompleteAdminMixin.get_help_text„   sN   € Ø ×6Ñ6×:Ñ:¸:ÀtÓLÐÙà(Ü+Ð,=¼qÀ»xÓHñˆKô ÐdÓeÐhsÑsÐsØr#   c                 óÂ  •— t        |t        j                  «      rµ|j                  | j                  v r�| j                  |j                  |j                  j                  j                  j                  «      }|j                  d«      rt        d«      |d   |fz  }t        |j                  | j                  |j                     «      |d<   ||d<   t        ‰| �8  |fi |¤ŽS )z�
        Override the default widget for Foreignkey fields if they are
        specified in the related_search_fields class attribute.
        Ú	help_textz%s %sÚwidget)Ú
isinstancer   Ú
ForeignKeyr'   rg   rj   Úremote_fieldr*   r+   Úobject_namerG   rW   r   r.   Úformfield_for_dbfield)r   Údb_fieldr   rl   r0   s       €r!   rr   z6ForeignKeyAutocompleteAdminMixin.formfield_for_dbfieldŽ   sÀ   ø€ ô
 �h¤× 1Ñ 1Ô2°x·}±}È×HbÑHbÑ7bØ×*Ñ*¨8¯=©=¸(×:OÑ:O×:UÑ:U×:[Ñ:[×:gÑ:gÓhˆIØ�z‰z˜+Ô&Ü ›L¨F°;Ñ,?ÀÐ+KÑK�	Ü4°X×5JÑ5JÈD×LfÑLfÐgo×gtÑgtÑLuÓvˆF�8ÑØ"+ˆF�;ÑÜ‰wÑ,¨XÑ@¸Ñ@Ð@r#   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rg   rH   Úgetattrr   rU   r/   r)   rT   rj   rr   Ú__classcell__)r0   s   @r!   r   r      sG   ø„ ñð2 ÐØ!ÐÙ  Ð+JÈDÓQÐôò8&òtò÷Að Ar#   r   c                   ó   — e Zd Zy)ÚForeignKeyAutocompleteAdminN©rt   ru   rv   rE   r#   r!   r{   r{   œ   ó   „ Ør#   r{   c                   ó   — e Zd Zy)Ú#ForeignKeyAutocompleteTabularInlineNr|   rE   r#   r!   r   r       r}   r#   r   c                   ó   — e Zd Zy)Ú#ForeignKeyAutocompleteStackedInlineNr|   rE   r#   r!   r�   r�   ¤   r}   r#   r�   )%rR   Ú	functoolsr   r   Útypingr   r   r   Údjango.appsr   Údjango.httpr	   r
   Údjango.confr   Ú	django.dbr   Údjango.db.models.queryr   Údjango.utils.encodingr   Údjango.utils.translationr   r%   Údjango.utils.textr   Údjango.contribr   Údjango_extensions.admin.widgetsr   r   Ú
ModelAdminr{   ÚTabularInliner   ÚStackedInliner�   rE   r#   r!   ú<module>r‘      s   ðó
 ß ,ß (Ñ (å ß :Ý  Ý Ý +Ý +Ý 1Ý +Ý  å A÷CAñ CAôL	Ð"BÀE×DTÑDTô 	ô	Ð*JÈE×L_ÑL_ô 	ô	Ð*JÈE×L_ÑL_õ 	r#   