o
    [h                     @   s   d dl Zd dlZd dl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 eG dd	 d	Zg Zd ad
ZdefddZdd Zdd ZG dd de
Ze Zdd Zeddgej dZdS )    N)	dataclassasdict)Path)StaticFiles)settings)db)PageTimeBatchc                   @   s^   e Zd ZU eed< eed< eed< eed< eed< eed< eed< eed< eed	< eed
< dS )TimeSpentRowsession_codeparticipant_id_in_sessionparticipant_code
page_indexapp_name	page_nameepoch_time_completedround_numbertimeout_happenedis_wait_pageN)__name__
__module____qualname__str__annotations__int r   r   t/home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/otree/common2.pyr	      s   
 r	   2   rowc                 C   sT   t | }dtt| d } t|  tttks#t		 t
 dkr(t  d S d S )N,
x   )r   joinmapr   valuespage_completion_bufferappendlenBUFFER_SIZEtimepage_completion_last_writewrite_page_completion_buffer)r   dr   r   r   write_row_to_page_buffer#   s   

r,   c                 C   sN   t t }t|| jt| j|| j|||t tt| dd|d
}t	| d S )Nr   F)
r   r   r   r   r   r   r   r
   r   r   )
r   r(   r	   Z_index_in_pagestyper   r   boolgetattrr,   )viewr   Zparticipant__id_in_sessionZparticipant__coder
   r   nowr   r   r   r   make_page_completion_row/   s   	r2   c                   C   s*   t tdtd t at  d S )N )text)r   addr   r!   r$   r(   r)   clearr   r   r   r   r*   H   s   r*   c                   @   s   e Zd Zdd Zdd ZdS )OTreeStaticFilesc                 C   s   g }|d ur| | |pg D ]1}tj|}|d ur |jd us(J d|dtjtj|jdd}tj	|r@| | q|S )NzPackage z4 could not be found, or maybe __init__.py is missingz..static)
r%   	importlibutil	find_specoriginospathnormpathr!   isdir)self	directorypackagesdirectoriespackagespecZpackage_directoryr   r   r   get_directoriesR   s   


z OTreeStaticFiles.get_directoriesc                 C   s>   |t v rd S | jD ]}t|| rt |  d S q	t|)N)existing_filenames_cacheZall_directoriesr   is_filer5   FileNotFoundError)rA   r>   Z_dirr   r   r   assert_file_existsd   s   

z#OTreeStaticFiles.assert_file_existsN)r   r   r   rG   rK   r   r   r   r   r7   O   s    r7   c                 C   s&   ddl m} t|  |jjd| dS )aF  
    naming:
    - it shouldn't start with
    'static' because that would distract from @staticmethod in autocomplete,
    which is much more important.
    - url_of_static is more specific than url_for_static (which looks like vars_for_template but works differently)

    better than hardcoding '/static/', which will fail silently if the file
    doesn't exist.

    this would be useful for 2 situations:
    - live pages, where {% static %} can't be used because the template was already rendered
    - for use with js_vars (don't want {% static %} mixed in with JS code)
    r   )appr8   )r>   )Z
otree.asgirL   static_files_apprK   ZrouterZurl_path_for)r>   rL   r   r   r   url_of_staticq   s   
rN   Z_staticotree)rB   rC   )importlib.utilr9   r=   r(   dataclassesr   r   pathlibr   Zstarlette.staticfilesr   rO   r   Zotree.databaser   Zotree.models_concreter   r	   r$   r)   r'   r,   r2   r*   r7   setrH   rN   Z
OTREE_APPSrM   r   r   r   r   <module>   s.   
