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__/djpeewee.cpython-38.pyc

U

S��W��@sxdZddlmZddlZddlTe�d�ZGdd�de�ZGdd	�d	e	�Z
zddlZe
�jZ
Wnek
rrYnXdS)
zE
Simple translation of Django model classes to peewee model classes.
�)�partialN)�*zpeewee.playhouse.djpeeweec@seZdZdd�ZdS)�AttrDictcCs||S�N�)�self�attrrr�/djpeewee.py�__getattr__szAttrDict.__getattr__N)�__name__�
__module__�__qualname__r
rrrr	rsrc@s6eZdZdd�Zdd�Zdd�Zd
d	d
�Zdd�ZdS)�DjangoTranslatorcCs|��|_dSr)�get_django_field_map�
_field_map)rrrr	�__init__szDjangoTranslator.__init__cCs�ddlm}|jtf|jtf|jtf|jtf|jtf|jtf|j	t	f|j
tf|jtf|jtf|j
ttdd�f|jtf|jtf|jjtfgS)Nr��fieldsT�Znull)�django.db.modelsrZ	AutoFieldZPrimaryKeyFieldZBigIntegerFieldZBooleanFieldZ	CharFieldZ
DateTimeFieldZ	DateFieldZDecimalFieldZ
FilePathFieldZ
FloatField�IntegerFieldZNullBooleanFieldrZ	TextFieldZ	TimeField�relatedZ
ForeignKey�ForeignKeyField)r�djfrrr	rs 
�z%DjangoTranslator.get_django_field_mapcCs*d}|jD]\}}t||�r
|}q&q
|Sr)r�
isinstance)r�field�	convertedZdjango_fieldZpeewee_fieldrrr	�
convert_field's
zDjangoTranslator.convert_fieldNFcCsT|r||krdS|dkrd}ddlm}|j}|�|j�r>dSd||j<i}dd�}	t|j|	d�D�]}
|�|
�}|tk�rP|dk�r<|
jj	}|jj}
|
|kr�d||
<|j
|||d||d�||
dkr�t�d	|
j
|
�t|
jd
�||
j
<nL|
jjp�|
��}|�d��r d||
j
|�d�f}t||
||
jd
�||
j
<nt|
jd
�||
j
<qb|rb||
jd
�||
j
<qbt|jtf|�}|j|j_d|jj_|||j<|�rzdd�|��D�}Wn(tk
�r�dd�|��D�}YnX|D]4\}}|jj|k�r��q�|j
|||d||d��q�|jD]2}t||jj ��s4�q|j
|jj!||||d��qdS)N���rrcSs|jr
dpd|fS)N�rr)rrrr	�<lambda>C�z3DjangoTranslator._translate_model.<locals>.<lambda>)�keyr��	max_depth�backrefs�excludezCycle detected: %s: %s)�	db_column�+z
__%s:%s:%s)�related_namer'z%scSsg|]}||jf�qSr)�model��.0�frrr	�
<listcomp>{sz5DjangoTranslator._translate_model.<locals>.<listcomp>cSs0g|](}|js|jr|jr|js||jjf�qSr)Zone_to_manyZ
one_to_oneZauto_createdZconcreterr*r+rrr	r.~s�)"rrZ_meta�getZobject_name�sortedrrZrel�to�_translate_model�logger�warn�namer�columnr)Zrelated_query_name�endswith�stripr'�typeZModelZdb_tableZdatabaseZ
interpolationZget_all_related_objects�AttributeErrorZ
get_fields�many_to_manyrrZManyToManyFieldZthrough)rr*�mappingr$r%r&r�optionsZattrsZ	field_keyZmodel_fieldrZ
related_modelZ
model_namer)�klassZall_relatedZrel_objr;rrr	r2/s�



��������


�
�

�z!DjangoTranslator._translate_modelc	Os�t�}|�dd�}|�dd�}|�dd�}|�dd�}|sH|rHtd��n|sRd	}n|rb|dkrbd
}|D]}|j|||||d�qf|S)av
        Generate a group of peewee models analagous to the provided Django
        models for the purposes of creating queries.

        :param model: A Django model class.
        :param options: A dictionary of options, see note below.
        :returns: A dictionary mapping model names to peewee model classes.
        :rtype: dict

        Recognized options:
            `recurse`: Follow foreign keys (default: True)
            `max_depth`: Max depth to recurse (default: None, unlimited)
            `backrefs`: Follow backrefs (default: False)
            `exclude`: A list of models to exclude

        Example::

            # Map Django models to peewee models. Foreign keys and M2M will be
            # traversed as well.
            peewee = translate(Account)

            # Generate query using peewee.
            PUser = peewee['User']
            PAccount = peewee['Account']
            query = (PUser
                     .select()
                     .join(PAccount)
                     .where(PAccount.acct_type == 'foo'))

            # Django raw query.
            users = User.objects.raw(*query.sql())
        �recurseTr$Nr%Fr&z9Error, you cannot specify a max_depth when recurse=False.rrr#)rr/�
ValueErrorr2)	rZmodelsr=r<r?r$r%r&r*rrr	�translate_models�s(!
�z!DjangoTranslator.translate_models)NFN)rrr
rrrr2rArrrr	rs�
ir)�__doc__�	functoolsrZloggingZpeeweeZ	getLoggerr3�dictr�objectrZdjangorA�	translate�ImportErrorrrrr	�<module>s
A

Zerion Mini Shell 1.0