a
    Dg                     @   sh  d dl mZ d dl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 G dd deZG dd de	jZejdkrd dlmZ d dlm Z  G dd deZ!e!Z"nnejdkr.d dl#m$Z$ G dd deZ%e%Z"e$ rTG dd de	jZ&n&ejdkrPG dd deZ'e'Z"neZ"G dd  d e"Z(d!S )"    )apps)GenericForeignKeyGenericRelation)ContentType)
connectionmodels)	TextField)OneToOneField)Cast)	WhereNode)gettext_lazy   )class_is_indexed)!get_descendants_content_types_pksc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TextIDGenericRelationTc                 C   s.   | j jj| j}|d||t| jS )Nin)remote_fieldmodel_meta	get_fieldZcontent_type_field_name
get_lookupget_colr   )selfaliasremote_aliasfield r   T/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/search/models.pyget_content_type_lookup   s    z-TextIDGenericRelation.get_content_type_lookupc                 C   s>   | j jj| j}| jjj}|d||t|||S )Nexact)	r   r   r   r   Zobject_id_field_namepkr   r   r
   )r   r   r   Z
from_fieldZto_fieldr   r   r   get_object_id_lookup   s
    
z*TextIDGenericRelation.get_object_id_lookupc                 C   s2   t  }|| ||d || ||d |S )NAND)r   addr   r!   )r   r   r   Zcondr   r   r   get_extra_restriction   s    z+TextIDGenericRelation.get_extra_restrictionc                 C   s   g S Nr   r   r   r   r   resolve_related_fields%   s    z,TextIDGenericRelation.resolve_related_fieldsN)__name__
__module____qualname__Zauto_createdr   r!   r$   r'   r   r   r   r   r      s
   r   c                   @   sr   e Zd ZdZejeejddZej	ddZ
e ZejddZdZG d	d
 d
Zdd Zedd Zedd ZdS )BaseIndexEntryz
    This is an abstract class that only contains fields common to all database vendors.
    It should be extended by the models specific for each backend.
    +)	on_deleteZrelated_name2   )
max_lengthg      ?)defaultTc                   @   s$   e Zd ZdZedZedZdZdS )zBaseIndexEntry.Meta)content_type	object_idzindex entryzindex entriesTN)r(   r)   r*   Zunique_together_Zverbose_nameZverbose_name_pluralabstractr   r   r   r   Meta?   s   r5   c                 C   s   | j j d| j S )Nz: )r1   namecontent_objectr&   r   r   r   __str__E   s    zBaseIndexEntry.__str__c                 C   s   | j jS r%   )r1   r   r&   r   r   r   r   H   s    zBaseIndexEntry.modelc                 C   s*   t  D ]}t|rt| |d qd S )NZindex_entries)r   Z
get_modelsr   r   Zcontribute_to_class)clsr   r   r   r   add_generic_relationsL   s    z$BaseIndexEntry.add_generic_relationsN)r(   r)   r*   __doc__r   Z
ForeignKeyr   CASCADEr1   Z	CharFieldr2   r   r7   Z
FloatFieldZ
title_normZwagtail_reference_index_ignorer5   r8   propertyr   classmethodr:   r   r   r   r   r+   )   s   
r+   Z
postgresql)GinIndex)SearchVectorFieldc                   @   s4   e Zd ZdZe Ze Ze ZG dd dej	Z	dS )AbstractPostgresIndexEntrya
  
        This class is the specific IndexEntry model for PostgreSQL database systems.
        It inherits the fields defined in BaseIndexEntry, and adds PostgreSQL-specific
        fields (tsvectors), plus indexes for doing full-text search on those fields.
        c                   @   s2   e Zd ZdZedgdedgdedgdgZdS )zAbstractPostgresIndexEntry.MetaTautocomplete)fieldstitlebodyN)r(   r)   r*   r4   r?   Zindexesr   r   r   r   r5   d   s
   


r5   N)
r(   r)   r*   r;   r@   rB   rD   rE   r+   r5   r   r   r   r   rA   X   s
   rA   Zsqlite)fts5_availablec                   @   s@   e Zd ZdZeddZeddZeddZG dd dej	Z	dS )AbstractSQLiteIndexEntryz
        This class is the specific IndexEntry model for SQLite database systems. The autocomplete, title, and body fields store additional
        TnullFc                   @   s   e Zd ZdZdS )zAbstractSQLiteIndexEntry.MetaTNr(   r)   r*   r4   r   r   r   r   r5   |   s   r5   N
r(   r)   r*   r;   r   rB   rD   rE   r+   r5   r   r   r   r   rG   s   s
   


rG   c                   @   sJ   e Zd ZeddZeddZeddZeddej	ddZ
G dd dZd	S )
SQLiteFTSIndexEntryTrH   Fzwagtailsearch.indexentryZrowid)Zprimary_keytor-   Z	db_columnc                   @   s   e Zd ZdZdS )zSQLiteFTSIndexEntry.MetaZwagtailsearch_indexentry_ftsN)r(   r)   r*   Zdb_tabler   r   r   r   r5      s   r5   N)r(   r)   r*   r   rB   rD   rE   r	   r   r<   Zindex_entryr5   r   r   r   r   rL      s   


rL   Zmysqlc                   @   s@   e Zd ZdZeddZeddZeddZG dd dej	Z	dS )AbstractMySQLIndexEntryzY
        This class is the specific IndexEntry model for MySQL database systems.
        TrH   Fc                   @   s   e Zd ZdZdS )zAbstractMySQLIndexEntry.MetaTNrJ   r   r   r   r   r5      s   r5   NrK   r   r   r   r   rN      s
   


rN   c                   @   s"   e Zd ZdZG dd dejZdS )
IndexEntryzE
    The IndexEntry model that will get created in the database.
    c                   @   s   e Zd ZdZdZdS )zIndexEntry.Metazj
        Contains everything in the AbstractIndexEntry Meta class, but makes this model concrete.
        FN)r(   r)   r*   r;   r4   r   r   r   r   r5      s   r5   N)r(   r)   r*   r;   AbstractIndexEntryr5   r   r   r   r   rO      s   rO   N))Zdjango.appsr   Z"django.contrib.contenttypes.fieldsr   r   Z"django.contrib.contenttypes.modelsr   Z	django.dbr   r   Zdjango.db.models.fieldsr   Zdjango.db.models.fields.relatedr	   Zdjango.db.models.functionsr
   Zdjango.db.models.sql.wherer   Zdjango.utils.translationr   r3   indexr   utilsr   r   ZModelr+   vendorZdjango.contrib.postgres.indexesr?   Zdjango.contrib.postgres.searchr@   rA   rP   Z-wagtail.search.backends.database.sqlite.utilsrF   rG   rL   rN   rO   r   r   r   r   <module>   s8   +
