o
    [h<                     @   s>   d dl Z d dlmZ d dlmZ d dlmZ G dd dZdS )    N)FullResultSet)OrderByList)RemovedInDjango61Warningc                       sH   e Zd Zddd fdd
Z fddZ fddZ fd	d
Z  ZS )OrderableAggMixin )orderingorder_byc                   sj   |rt jdtdd |rtd|}|sd | _nt|ttfr%t| | _nt|| _t	 j
|i | d S )Nz:The ordering argument is deprecated. Use order_by instead.   )category
stacklevelz*Cannot specify both order_by and ordering.)warningswarnr   	TypeErrorr   
isinstancelisttupler   super__init__)selfr   r   Zexpressionsextra	__class__r   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/django/contrib/postgres/aggregates/mixins.pyr      s   
zOrderableAggMixin.__init__c                    s   t   | jg S N)r   get_source_expressionsr   )r   r   r   r   r      s   z(OrderableAggMixin.get_source_expressionsc                    s   |^ }| _ t |S r   )r   r   set_source_expressions)r   Zexprsr   r   r   r   !   s   z(OrderableAggMixin.set_source_expressionsc                    s   |   ^ }}}d}g }|d ur||\}}g }|d ur0z	||\}	}W n	 ty/   Y nw g }
|D ]}|
||d 7 }
q4t j|||d\}}	|g |
||R fS )N    )r   )r   compiler   r   as_sql)r   compiler
connectionZsource_exprsZfiltering_exprZorder_by_exprZorder_by_sqlZorder_by_paramsZfilter_params_Zsource_paramsZsource_exprsqlr   r   r   r   %   s"   zOrderableAggMixin.as_sql)__name__
__module____qualname__r   r   r   r   __classcell__r   r   r   r   r      s
    r   )r   Zdjango.core.exceptionsr   Zdjango.db.models.expressionsr   Zdjango.utils.deprecationr   r   r   r   r   r   <module>   s
    