
    >Tf                     `    d dl mZ d dlmZ d dlmZ d dlmZ dZ	 G d dej
                  ZdS )	    )models)gettext_lazy)
get_config)flatten_dict)
UserConfigc                       e Zd ZdZ ej        dej        d          Z ej        e	          Z
dZ G d d          Zdd
Zd ZddZddZd	S )r   zY
    This model stores arbitrary user-specific preferences in a JSON data structure.
    z
users.Userconfig)to	on_deleterelated_name)defaultTc                   @    e Zd ZdgZ ed          Z ed          ZdS )UserConfig.Metauserzuser preferencesN)__name__
__module____qualname__ordering_verbose_nameverbose_name_plural     =/var/www/html/netbox-4.1.3/netbox/users/models/preferences.pyMetar      s8        8q+,,a 233r   r   Nc                    | j         }|                    d          }	 |D ]
}||         }|S # t          t          f$ r Y nw xY wt	                      }|j        }	 |D ]
}||         }|S # t          t          f$ r Y nw xY w|S )aQ  
        Retrieve a configuration parameter specified by its dotted path. Example:

            userconfig.get('foo.bar.baz')

        :param path: Dotted path to the configuration key. For example, 'foo.bar' returns self.data['foo']['bar'].
        :param default: Default value to return for a nonexistent key (default: None).
        .)datasplit	TypeErrorKeyErrorr   DEFAULT_USER_PREFERENCES)selfpathr   dkeyskeyr	   s          r   getzUserConfig.get    s     Izz#	  cFH8$ 	 	 	D	 +	  cFH8$ 	 	 	D	 s!   - A AA) )A=<A=c                 *    t          | j                  S )zK
        Return a dictionary of all defined keys and their values.
        )r   r   )r#   s    r   allzUserConfig.allA   s     DI&&&r   Fc                    | j         }|                    d          }t          |dd                   D ]\  }}||v r%t          ||                   t          u r	||         }.||v rcd                    |                    d          d|dz                      }t          t          d                              |                    |	                    |i           }|d         }||v r~t          ||                   t          u rbt          |          t          u r||         
                    |           n5t          t          d                              |                    |||<   |r|                                  dS dS )a1  
        Define or overwrite a configuration parameter. Example:

            userconfig.set('foo.bar.baz', 123)

        Leaf nodes (those which are not dictionaries of other nodes) cannot be overwritten as dictionaries. Similarly,
        branch nodes (dictionaries) cannot be overwritten as single values. (A TypeError exception will be raised.) In
        both cases, the existing key must first be cleared. This safeguard is in place to help avoid inadvertently
        overwriting the wrong key.

        :param path: Dotted path to the configuration key. For example, 'foo.bar' sets self.data['foo']['bar'].
        :param value: The value to be written. This can be any type supported by JSON.
        :param commit: If true, the UserConfig instance will be saved once the new value has been applied.
        r   N   z3Key '{path}' is a leaf node; cannot assign new keys)r$   zBKey '{path}' is a dictionary; cannot assign a non-dictionary value)r   r   	enumeratetypedictjoinr    r   format
setdefaultupdatesave)	r#   r$   valuecommitr%   r&   ir'   err_paths	            r   setzUserConfig.setG   s    Izz#  SbS	** 		* 		*FAsaxxD3LLD00cF88DJJsOOFQUF$;<<KLLSSYaSbb   LLb)) 2h!88QsV,,E{{d""#e$$$$Z[[bbhlbmm   AcF 	IIKKKKK	 	r   c                    | j         }|                    d          }|dd         D ],}||vr n%t          ||                   t          u r||         }-|d         }|                    |d           |r|                                  dS dS )a  
        Delete a configuration parameter specified by its dotted path. The key and any child keys will be deleted.
        Example:

            userconfig.clear('foo.bar.baz')

        Invalid keys will be ignored silently.

        :param path: Dotted path to the configuration key. For example, 'foo.bar' deletes self.data['foo']['bar'].
        :param commit: If true, the UserConfig instance will be saved once the new value has been applied.
        r   Nr,   )r   r   r/   r0   popr5   )r#   r$   r7   r%   r&   r'   s         r   clearzUserConfig.clearu   s     Izz#9 	 	C!||AcF||t##cF2h	c4 	IIKKKKK	 	r   )N)F)r   r   r   __doc__r   OneToOneFieldCASCADEr   	JSONFieldr0   r   _netbox_privater   r(   r*   r:   r=   r   r   r   r   r      s           6.  D
 6  D O4 4 4 4 4 4 4 4
   B' ' ', , , ,\     r   r   N)	django.dbr   django.utils.translationr   r   netbox.configr   utilities.datar   __all__Modelr   r   r   r   <module>rI      s          6 6 6 6 6 6 $ $ $ $ $ $ ' ' ' ' ' '
B B B B B B B B B Br   