
    jJh8                         d dl mZmZmZ d dlmZ  ede      Zg dZd Z	d Z
d Zej                  dd	g
      d        Zy)    )	Blueprintrequestjsonify)execute_queryapi_activity_location)	statedistrictblocksectorcentrepanchayat_nameschool_nameactivity_levelpeeo_uceeo_schoolc                 0    | sddidfS | t         vrddidfS y)z.Validate the level parameter from the request.errorzMissing level parameteri  zInvalid level parameterN)ACTIVITY_LOCATION_FIELDS)levels    :/var/www/dostadmin/dostadmin/apis/api_activity_location.pyvalidate_levelr      s3    23S88,,23S88    c                     g }g }t         D ];  }|j                  |      }|s|j                  | d       |j                  |       = |r dj                  |      }d|  d| d|  }||fS d|  d|  }||fS )z>Build the SQL query and values based on the request arguments.z = %sz AND zSELECT DISTINCT z FROM activities_data WHERE z
 ORDER BY z FROM activities_data ORDER BY )r   getappendjoin)r   request_argsfiltersvalueskeyvalwhere_clausequerys           r   build_query_and_valuesr#      s    GF's#NNcU%=)MM#	 ( ||G,"5')El^S]^c]de &= #5')HP&=r   c                      t        d| i      |fS )z&Returns a standardized error response.Error)r   )messagestatus_codes     r   error_responser(   0   s    GW%&33r   z/api/activity_locationGET)methodsc                  4   t         j                  j                  d      } t        |       }|rt	        |d         |d   fS t        | t         j                        \  }}	 t        ||      }t	        |      S # t        $ r}t        d| d      cY d}~S d}~ww xY w)zKAPI endpoint to get distinct values for a specific activity location level.r   r      zInternal server error. i  N)	r   argsr   r   r   r#   r   	Exceptionr(   )r   validation_errorr"   r   optionses         r   get_activity_location_valuesr2   5   s     LLW%E &e,'*+-=a-@@@ +5',,?ME6Bv. 7  B 7s;SAABs   A5 5	B>BBBN)flaskr   r   r   utils.helpers.db_helperr   __name__api_activity_location_bpr   r   r#   r(   router2    r   r   <module>r9      s[    - - 1$%<hG 
 (4
  85'J Kr   