a
    յ\ef	                     @   s   d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZmZmZ e	 Ze
dedejdd Zededejdd ZdS )	zRoutes for edit/properties.    N)Bottlerouteviewredirectpostrequestz/surveys/<name>/properties
propertiesc                 C   s^   t | \}}tjdd}tj|dd tt|d }t| |t 	| |t
jd|dS )zcPresents user with form to edit survey's properties or enter them for
	the first time if uploading.dbsurveysT)exist_ok   	uploading)survey_namesurveymetadatar   r   r
   )surveyparser
get_surveyospathjoinmakedirsnextwalkdictget_metadatar   queryget)namer   r   baser
    r   "/var/www/vevn/routes/properties.pyedit_properties   s    
r!   c              	   C   s>  t tjdd| dtjdtjd\}}tjdd| }t ||| tj	dt
dttj	dtj	d	dtj	d
tjdtjdd}t|tj|d tjddd}tj|g d}ttj	d| |v kr| |v r||  n
||  t|| tj	dr2td|  d  td dS )zApply and write changes.r	   r
   zraw.csvtouchpoint-columnszdeleted-columnspublicr   anon-matchescompare-withnotesfilterable-columns)r#   r$   r%   guestsr&   r'   r"   zproperties.jsonzpublic.json)fallbackr   z	/surveys/z/readings?uploading=1z/surveysN)r   
parse_filer   r   r   r   formsgetallwriter   maxintutilssafejsondumpsafejsonloadboolremoveappendr   r   )r   Z
new_surveynew_metadatar   Znew_propertiespublic_pathr#   r   r   r    r!      s4    






	
)__doc__r   jsonpandassecurityr   shutilr0   bottler   r   r   r   r   r   r   require_adminr!   r   r   r   r    <module>   s   8 