ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/gfk.cpython-38.pyc

U

S��W��@s�dZddlTddlmZddlmZddlmZddlmZddlmZe	�Z
iZGdd	�d	e�ZGd
d�deee��Zdd
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZdS)a
Provide a "Generic ForeignKey", similar to Django.  A "GFK" is composed of two
columns: an object ID and an object type identifier.  The object types are
collected in a global registry (all_models), so all you need to do is subclass
``gfk.Model`` and your model will be added to the registry.

Example:

class Tag(Model):
    tag = CharField()
    object_type = CharField(null=True)
    object_id = IntegerField(null=True)
    object = GFKField('object_type', 'object_id')

class Blog(Model):
    tags = ReverseGFK(Tag, 'object_type', 'object_id')

class Photo(Model):
    tags = ReverseGFK(Tag, 'object_type', 'object_id')

tag.object -> a blog or photo
blog.tags -> select query of tags for ``blog`` instance
Blog.tags -> select query of all tags for Blog instances
�)�*)�	BaseModel)�Model)�SelectQuery)�UpdateQuery)�with_metaclasscseZdZ�fdd�Z�ZS)rcs,tt|��||||�}|dkr(t�|�|S)N)Z_metaclass_helper_r)�superr�__new__�
all_models�add)�cls�name�basesZattrs��	__class__��/gfk.pyr	's
zBaseModel.__new__)�__name__�
__module__�__qualname__r	�
__classcell__rrrrr&src@seZdZdS)rN)rrrrrrrr-srcCs4|tkr*tD]}|jj|kr|t|<q*qt�|�S�N)�table_cacher
�_meta�db_table�get)�tbl_name�modelrrr�	get_model0src@s@eZdZdZdd�Zedd��Zedd��Zdd	�Zd
d�Z	dS)
�
BoundGFKField��model_class�	gfk_fieldcCs||_||_dSrr )�selfr!r"rrr�__init__;szBoundGFKField.__init__cCsB|jjj}t|jj|jjf�}|D]\}}|t|�s"dSq"dS�NTF)r!r�indexes�setr"�model_type_field�model_id_field)r#r&�fieldsZindexed_columnsZ	is_uniquerrr�unique?s
�zBoundGFKField.uniquecCs>|jjj}t|t�r:t|jj|jjf�}|t|j	�s:dSdSr%)
r!r�primary_key�
isinstanceZCompositeKeyr'r"r(r)�field_names)r#Zpkr*rrrr,Is

�zBoundGFKField.primary_keycCs<|jj}|j|jj}|j|jj}||jjk||��k@Sr)r!rr*r"r(r)r�
_get_pk_value)r#�other�meta�
type_field�id_fieldrrr�__eq__Ss

��zBoundGFKField.__eq__cCs@t|�}|jj|jj}|jj|jj}||jjk||��k@Sr)�typerr*r"r(r)rr/)r#r0Z	other_clsr2r3rrr�__ne__[s

��zBoundGFKField.__ne__N)
rrr�	__slots__r$�propertyr+r,r4r6rrrrr8s
	
	rc@s0eZdZddd�Zdd�Zd
dd	�Zd
d�ZdS)�GFKField�object_type�	object_idcCs$||_||_d�|j|jf�|_dS)N�.)r(r)�join�att_name)r#r(r)rrrr$eszGFKField.__init__cCsh|j}|�|j�rd|�|j�rd||j}t|�}|s@td|��|���|jj	||jk�}|��SdS)Nz-Model for table "%s" not found in GFK lookup.)
�_datarr(r)r�AttributeError�select�whererr,)r#�instance�datarr!Zqueryrrr�get_objks
��zGFKField.get_objNcCsB|r8|j|jkr*|�|�}|r*||j|j<|j�|j�St||�Sr)r>�
_obj_cacherErr)r#rC�
instance_typeZrel_objrrr�__get__ws
zGFKField.__get__cCs0||j|j<|jj|j|j<|��|j|j<dSr)rFr>rrr?r(r/r))r#rC�valuerrr�__set__�szGFKField.__set__)r:r;)N)rrrr$rErHrJrrrrr9ds�

	r9c@s(eZdZd
dd�Zddd�Zdd	�ZdS)�
ReverseGFKr:r;cCs&||_|jj||_|jj||_dSr)r!rr*r(r))r#rr(r)rrrr$�szReverseGFK.__init__NcCsJ|r,|j���|j|jjk|j|��k@�S|j���|j|jjk�SdSr)r!rArBr(rrr)r/)r#rCrGrrrrH�s
��
�zReverseGFK.__get__cs�|jj}|��}t|t�rL|j�jkrLt�j�j|�j|i��	|j
���nVtt
�fdd�|��r�|D],}t|�jj|�t|�jj|�|��qfntd|��dS)Ncst|�j�Sr)r-r!)�i�r#rr�<lambda>��z$ReverseGFK.__set__.<locals>.<lambda>z&ReverseGFK field unable to handle "%s")rrr/r-rr!rr(r)rBZ_whereZexecute�all�map�setattrr
Zsave�
ValueError)r#rCrIZmtvZmiv�objrrMrrJ�s&

���
zReverseGFK.__set__)r:r;)N)rrrr$rHrJrrrrrK�s
�

rKN)�__doc__ZpeeweerZ
_BaseModelrZ_Modelrrrr'r
rr�objectrr9rKrrrr�<module>s,"

Zerion Mini Shell 1.0