
    jJh	                     \    d dl mZ d dlmZ  G d de      Z G d dej                        Zy)    )db)Queryc                       e Zd Zd Zd Zd Zy)SystemConfigQueryc                     | j                  t        j                  |j                         k(        }d}|r |j	                         r|j                         }|S )zW
        This method is used to get a config value in the system_config table.
        N)filterSystemConfigurationnameuppercountfirst)selfconfig_nameexisting_recordsoutputs       6/var/www/dostadmin/dostadmin/db_model/configuration.pyget_config_valuez"SystemConfigQuery.get_config_value   sO      ;;':'?'?;CTCTCV'VW 0 6 6 8%++-F    c                     | j                  t        j                  t        |      k(        }d }|r |j	                         r|j                         }|S N)r   r	   idintr   r   )r   	config_idr   r   s       r   get_config_by_idz"SystemConfigQuery.get_config_by_id   sH    ;;':'='=Y'OP 0 6 6 8%++-Fr   c                 "    | j                         S r   )r   r   s    r   get_all_configsz!SystemConfigQuery.get_all_configs   s    {{}r   N)__name__
__module____qualname__r   r   r    r   r   r   r      s    
r   r   c                      e Zd ZdZeZ ej                  dej                  d      Z	 ej                   ej                  d      ddd      Z ej                   ej                  d            Zd	 Zd
 Zd Zd Zd Zd Zy)r	   system_configurationr   T)primary_key2   F)uniqueindexnullable   c                 x   | j                  |      }|r=t        j                  j                  |       t        j                  j	                          t        |j                         |      }	 t        j                  j                  |       t        j                  j	                          |S # t        $ r Y y w xY w)Nr   )r
   value)	
get_configr   sessiondeletecommitr	   r   add	Exception)r   r   config_valueexisting_recordsystem_config_records        r   
set_configzSystemConfiguration.set_config'   s    //k/BJJo.JJ  3""$L 
	JJNN/0JJ'' 		s   .>B- -	B98B9c                     | j                  |      }|r?	 t        j                  j                  |       t        j                  j	                          yy# t
        $ r Y yw xY w)NTF)r   r   r.   r/   r0   r2   )r   r   records      r   delete_configz!SystemConfiguration.delete_config:   sX    &&y1

!!&)

!!#   s   =A 	A A c                 ^    t         j                  j                  |j                               S )Nr+   )r	   queryr   r   )r   r   s     r   r-   zSystemConfiguration.get_configE   s,    "((99#))+ : 
 	
r   c                 T    t         j                  j                  t        |            S )N)r   )r	   r;   r   r   )r   r   s     r   r   z$SystemConfiguration.get_config_by_idJ   s     "((99C	N9SSr   c                     | j                   j                  D ci c]#  }|j                  t        | |j                        % c}S c c}w r   )	__table__columnsr
   getattr)r   cs     r   as_dictzSystemConfiguration.as_dictM   s:    7;~~7M7MN7M!aff--7MNNNs   (Ac                 "    d| j                    dS )Nz<SystemConfiguration >)r
   r   s    r   __repr__zSystemConfiguration.__repr__P   s    &tyyk33r   N)r   r   r    __tablename__r   query_classr   ColumnIntegerr   Stringr
   r,   r6   r9   r-   r   rB   rE   r!   r   r   r	   r	      s~    *M#K	4	6B299YRYYr]4teLDBIIibiin%E&	

TO4r   r	   N)	dostadminr   flask_sqlalchemy.queryr   	BaseQueryr   Modelr	   r!   r   r   <module>rO      s'     5	 424"(( 24r   