Ņō
T6Jc        	   @   s   d  d k  l  Z  d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k	 l
 Z
 h  Z d e i f d     YZ d	 S(
   iĸĸĸĸ(   t   datetime(   t   Site(   t   cache(   t   models(   t   SiteConfigurationManager(   t	   JSONFieldt   SiteConfigurationc           B   sĪ   e  Z d  Z e i e d d Z e i d d  Z e	   Z
 e   Z d   Z d d  Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   sÔ   
    Configuration data for a site. The version and all persistent settings
    are stored here.

    The usual way to retrieve a SiteConfiguration is to use
    ```SiteConfiguration.objects.get_current()'''
    t   related_namet   configt
   max_lengthi   c         O   s)   t  i i |  | |  t i   |  _ d  S(   N(   R   t   Modelt   __init__R    t   nowt   _last_sync_time(   t   selft   argst   kwargs(    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyR   5   s    c         C   sM   | d j o- |  i t j o t |  i i | d  } n |  i i | |  S(   sÏ   
        Retrieves a setting. If the setting is not found, the default value
        will be returned. This is represented by the default parameter, if
        passed in, or a global default if set.
        N(   t   Nonet   idt	   _DEFAULTSt   gett   settings(   R   t   keyt   default(    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyR   9   s    c         C   s   | |  i  | <d S(   st   
        Sets a setting. The key should be a string, but the value can be
        any native Python object.
        N(   R   (   R   R   t   value(    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt   setD   s    c         C   s9   |  i  t j o h  t |  i  <n t |  i  i |  d S(   sž   
        Adds a dictionary of defaults to this SiteConfiguration. These
        defaults will be used when calling ```get''', if that setting wasn't
        saved in the database.
        N(   R   R   t   update(   R   t   defaults_dict(    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt   add_defaultsK   s    c         C   s   |  i  h | | 6 d S(   s0   
        Adds a single default setting.
        N(   R   (   R   R   t   default_value(    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt   add_defaultV   s    c         C   s,   |  i  t j o h  t |  i  <n t |  i  S(   sV   
        Returns all default settings registered with this SiteConfiguration.
        (   R   R   (   R   (    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt   get_defaults\   s    c         C   s2   t  i |  i    } t | t  o | |  i j S(   sl   
        Returns whether or not this SiteConfiguration is expired and needs
        to be reloaded.
        (   R   R   t&   _SiteConfiguration__get_sync_cache_keyt
   isinstanceR    R   (   R   t   last_updated(    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt
   is_expirede   s    c         K   s_   t  i   } | |  _ t i |  i   |  t i i   t	 i i   t
 t |   i |   d  S(   N(   R    R   R   R   R   R    R   t   objectst   clear_cacheR   t   supert   save(   R   R   R   (    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyR'   n   s    	c         C   s   d |  i  i |  i f S(   Ns   %s:siteconfig:%s:last-updated(   t   sitet   domainR   (   R   (    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt   __get_sync_cache_key{   s    c         C   s   d t  |  i  |  i f S(   Ns   %s (version %s)(   t   unicodeR(   t   version(   R   (    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt   __unicode__~   s    N(   t   __name__t
   __module__t   __doc__R   t
   ForeignKeyR   R(   t	   CharFieldR,   R   R   R   R$   R   R   R   R   R   R   R   R#   R'   R    R-   (    (    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyR   '   s   												N(   R    t   django.contrib.sites.modelsR   t   django.core.cacheR   t	   django.dbR   t   djblets.siteconfig.managersR   t   djblets.util.fieldsR   R   R
   R   (    (    (    s:   /var/www/Pootle/external_apps/djblets/siteconfig/models.pyt   <module>   s   