Ñò
ÍwLc           @   s  d  d k  Z  d  d k l Z d  d k l Z d  d k l Z l Z l Z d  d k	 l
 Z d  d k l Z d  d k l Z d  d k l Z d	 e f d
 „  ƒ  YZ e e i _ d e i f d „  ƒ  YZ d e i f d „  ƒ  YZ d „  Z e i e d e ƒd „  Z d S(   iÿÿÿÿN(   t   models(   t   Q(   t   Usert   UserManagert   AnonymousUser(   t   ugettext_lazy(   t	   post_save(   t   lang_choices(   t   lt   PootleUserManagerc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s   A manager class which is meant to replace the manager class for the User model. This manager
    hides the 'nobody' and 'default' users for normal queries, since they are special users. Code
    that needs access to these users should use the methods get_default_user and get_nobody_user.c         C   s+   t  t |  ƒ i ƒ  i d d ƒ i d d ƒ S(   Nt   depthi   t   usernamet   default(   t   superR	   t   get_query_sett   select_relatedt   get(   t   self(    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   get_default_user&   s    c         C   s+   t  t |  ƒ i ƒ  i d d ƒ i d d ƒ S(   NR
   i   R   t   nobody(   R   R	   R   R   R   (   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   get_nobody_user)   s    c         C   s   t  t |  ƒ i ƒ  i d d ƒ S(   Nt   username__inR   R   (   s   nobodys   default(   R   R	   R   t   exclude(   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   hide_defaults,   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyR	   "   s   		t   PootleProfileManagerc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s"   t  t |  ƒ i ƒ  i d d d ƒ S(   Nt	   languagest   projectst   alt_src_langs(   R   R   R   R   (   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyR   4   s    c         C   s   |  i  d | ƒ S(   Nt   user__username(   R   (   R   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   get_by_natural_key8   s    (   R   R   R   R    (    (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyR   3   s   	t   PootleProfilec           B   sÎ  e  Z e ƒ  Z d  d& d „  ƒ  YZ e i e d e d e ƒZ	 e i
 d d d e d ƒ ƒ Z e i
 d d d	 e ƒ Z e i d
 d e d e d d ƒ d d d e d ƒ d e ƒZ e i d d e d e d e d ƒ ƒZ e i d d d e d e d d „  e ƒ  Dƒ d e d ƒ ƒ Z e i d
 d e d e d e d d ƒ d d d e d ƒ ƒZ d „  Z d g e _ d „  Z d „  Z d  „  Z e e ƒ Z e d! „  ƒ Z d" „  Z e e ƒ Z  d# „  Z! d$ „  Z" d% „  Z# RS('   t   Metac           B   s   e  Z d  Z RS(   t   pootle_app_pootleprofile(   R   R   t   db_table(    (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyR"   =   s   t   uniquet   db_indexR   i	   t   verbose_names   Number of Rowsi   t   editables   pootle_language.Languaget   blankt   limit_choices_tot   codet	   templatest   related_namet   user_languagest	   Languagess   pootle_project.Projectt   Projectst
   max_lengthi2   t   nullt   choicesc         c   s   x |  ] } | Vq Wd  S(   N(    (   t   .0t   choice(    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pys	   <genexpr>G   s   	 s   Interface Languaget   user_alt_src_langss   Alternative Source Languagesc         C   s   |  i  i f S(   N(   t   userR   (   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   natural_keyJ   s    s	   auth.Userc         C   s
   |  i  i S(   N(   R7   R   (   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   __unicode__N   s    c         C   s   t  d |  i i ƒ S(   Ns   /accounts/%s/(   R   R7   R   (   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   get_absolute_urlQ   s    c         C   s   d S(   Nt   Foo(    (   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   _get_statusT   s    c         C   s   t  S(    (   t   True(   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   <lambda>Y   s    c         C   s#   |  i  d  j	 o |  i St ƒ  Sd  S(   N(   t   user_idt   NoneR7   R   (   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   _get_pootle_user[   s    c         C   s   t  t |  i d ƒ d ƒ S(   Ni   i1   (   t   mint   maxt	   unit_rows(   R   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   get_unit_rowsb   s    c         C   sÊ   g  } | i  h t d ƒ d 6|  i i d d ƒ i ƒ  d 6ƒ | i  h t d ƒ d 6|  i i d d ƒ i ƒ  d 6ƒ | i  h t d ƒ d 6|  i i ƒ  d 6ƒ | i  h t d	 ƒ d 6|  i i ƒ  d 6ƒ | S(
   s.    get user statistics for user statistics linkss   Suggestions Acceptedt   textt   statet   acceptedt   counts   Suggestions Pendingt   pendings   Suggestions Revieweds   Submissions Made(   t   appendt   _t	   suggestert   filterRI   t   reviewert   submission_set(   R   t   userstatistics(    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   getuserstatisticse   s    66**c   	   	   C   s/  d d k  l } |  i i ƒ  } g  } x|  i i ƒ  D]ò } g  } | i ƒ  ov xs | i i d |  i i ƒ  ƒ i ƒ  D]I } | |  d | i	 ƒ } | i
 h | i i d 6| i i d 6| d 6ƒ qs Wn | |  d | i	 ƒ } | i
 h | i d 6| i ƒ  d 6| d 6| d	 6ƒ | i d
 t i d d „  ƒ q5 W| S(   s5   gets a set of quick links to user's project-languagesiÿÿÿÿ(   t   check_profile_permissiont   project__int   administrateR+   t   namet   isprojectadmint   islangadminR   t   cmpt   keyc         S   s   |  d  S(   RV   (    (   t   dict(    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyR>   …   s    (   t   pootle_app.models.permissionsRS   R   t   allR   t   iteratorRI   t   translationproject_setRN   t	   directoryRK   t   projectR+   t   fullnamet	   localnamet   sortt   localet   strcoll(	   R   RS   R   t
   quicklinkst   languaget	   langlinkst   translation_projectRW   RX   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   getquicklinksn   s,     % 		 (    ($   R   R   R   t   objectsR"   R    t   OneToOneFieldR   R=   R7   t   SmallIntegerFieldRL   RD   t   Falset   input_heightt   ManyToManyFieldR   R   R   t	   CharFieldR   t   ui_langR   R8   t   dependenciesR9   R:   R<   t   propertyt   statust   isopenRA   t   pootle_userRE   RR   Rk   (    (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyR!   ;   s*   	='==								c         K   sF   y | i  ƒ  } Wn/ t i j
 o  t d | ƒ } | i ƒ  n Xd S(   s_   A post-save hook for the User model which ensures that it gets an
    associated PootleProfile.R7   N(   t   get_profileR!   t   DoesNotExistt   save(   t   sendert   instancet   kwargst   profile(    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   create_pootle_profileŠ   s
    R|   c         C   s5   |  i  ƒ  o |  i ƒ  St i i d d ƒ i ƒ  Sd S(   sì   Return the PootleProfile associated with a user.

    This function is only necessary if 'user' could be an anonymous
    user.  If you know for certain that a user is logged in, then use
    the .get_profile() method on a user instead.R   R   N(   t   is_authenticatedRy   R   Rl   R   (   R7   (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyRy   •   s    (   Re   t	   django.dbR    t   django.db.modelsR   t   django.contrib.auth.modelsR   R   R   t   django.utils.translationR   RL   t   django.db.models.signalsR   t   pootle.i18n.overrideR   t   pootle_misc.baseurlR   R	   Rl   t	   __class__t   ManagerR   t   ModelR!   R€   t   connectRy   (    (    (    s3   /var/www/Pootle/local_apps/pootle_profile/models.pyt   <module>   s   O		