
1AMc        '   @   s8  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d  d k	 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  d k 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  d k  l! Z! l" Z" l# Z# d  d k$ l% Z% d  d k& l' Z' l( Z( d  d k) l* Z* d  d k+ l, Z, l- Z- l. Z. l/ Z/ l0 Z0 d  d k) l1 Z1 l2 Z2 l3 Z3 d  d k) l4 Z4 l5 Z5 d  d k6 l7 Z7 d  d k8 l9 Z9 d  d k: l; Z; d  d k< l= Z= d  d k> l? Z? d  d k@ lA ZA d  d kB lC ZC lD ZD d  d kB lE ZE d  d kF lG ZG lH ZH lI ZI d  d kF lJ ZJ lK ZK lL ZL d eM f d     YZN d    ZO d!   ZP d" eQ f d#     YZR d$ e7 f d%     YZS d& e
 iT f d'     YZU d(   ZV eW eW d)  ZX e iY eX d* e9 eW eW d+  ZZ e iY eZ d* e; d S(,   iN(   t   settings(   t   modelst   IntegrityError(   t	   post_save(   t   PermissionDenied(   t   ugettext_lazy(   t   checks(   t   matcht   indexing(   t   versioncontrol(   t
   ParseError(   t   LRUCachingDict(   t   hooks(   t   getfromcachet   dictsumt   deletefromcache(   t   l(   t   group_by_countt
   max_column(   t   calculate_stats(   t   Storet   Unitt   QualityCheckt   PARSEDt   CHECKED(   t   relative_real_patht   absolute_real_patht   OBSOLETE(   t   empty_quickstatst   empty_completestats(   t   RelatedManager(   t   Project(   t   Language(   t	   Directory(   t   project_tree(   t   check_permission(   t   post_vc_updatet   post_vc_commit(   t   post_template_update(   t	   add_filest   match_template_filenamet   direct_language_match_filename(   t   convert_templatet   get_translated_namet   get_translated_name_gnut   TranslationProjectNonDBStatec           B   s   e  Z d    Z RS(   c         C   s:   | |  _  d  |  _ d  |  _ t |  _ t |  _ d  |  _ d  S(   N(	   t   parentt   Nonet   termmatchert   termmatchermtimet   Truet   _indexing_enabledt   Falset   _index_initializedt   indexer(   t   selfR.   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   __init__>   s    					(   t   __name__t
   __module__R8   (    (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR-   =   s   c         C   sn   t  i |  |  oW y) t i i d |  d |  \ } } | SWqj t j
 o d  St j
 o d  SXn d  S(   Nt   languaget   project(   R"   t    translation_project_should_existt   TranslationProjectt   objectst   get_or_createt   OSErrorR/   t
   IndexError(   R;   R<   t   translation_projectt   created(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   create_translation_projectH   s    !c          C   sE   x> t  i i   D]- }  x$ t i i   D] } t |  |  q& Wq Wd  S(   N(   R    R?   t   iteratorR   RE   (   R;   R<   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   scan_translation_projectsR   s
      t   VersionControlErrorc           B   s   e  Z RS(    (   R9   R:   (    (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRH   W   s   t   TranslationProjectManagerc           B   s   e  Z d    Z RS(   c         C   s   |  i  d |  S(   Nt   pootle_path(   t   get(   R7   RJ   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   get_by_natural_key[   s    (   R9   R:   RL   (    (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRI   Z   s   R>   c           B   s  e  Z e e i e i  Z e   Z d  Z	 d d0 d     YZ
 e i e d e Z e i e d e Z e i d e  Z e i e d e d e Z e i d d d e d e d e d e  Z d	   Z d
 d d g e _ d   Z d   Z d   Z d   Z e  d    Z! d   Z" d   Z# e  e" e#  Z$ d   Z% e  e%  Z& d   Z' e  e'  Z( d   Z) d   Z* e  e*  Z+ e d  Z, e d  Z- e. d    Z/ d   Z0 e. d    Z1 e. d    Z2 d1 d  Z4 d   Z5 d    Z6 e  e6  Z7 d!   Z8 e  e8  Z9 d"   Z: d#   Z; d$   Z< d%   Z= d&   Z> d1 d'  Z? d(   Z@ d)   ZA d1 d*  ZB e  d+    ZC e  d,    ZD d-   ZE d1 d. d/  ZF RS(2   s   .translation_indext   Metac           B   s   e  Z d Z d Z RS(   R;   R<   t   pootle_app_translationproject(   s   languages   project(   R9   R:   t   unique_togethert   db_table(    (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRM   d   s   t   db_indext   editablet
   max_lengthi   t   nullt   uniquec         C   s
   |  i  f S(   N(   RJ   (   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   natural_keyn   s    s   pootle_app.Directorys   pootle_language.Languages   pootle_project.Projectc         C   s   |  i  S(   N(   RJ   (   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   __unicode__r   s    c         O   s   |  i  d  j } |  i i   } t i |  i | |  i d t |  _	 |  i i
 i |  i i  |  _
 |  i
 i |  _ t t |   i | |   | o |  i   n d  S(   Nt	   make_dirs(   t   idR/   R<   t   get_real_pathR"   t   get_translation_project_dirR;   t
   file_styleR2   t   abs_real_patht	   directoryt   get_or_make_subdirt   codeRJ   t   superR>   t   savet
   scan_files(   R7   t   argst   kwargsRD   t   project_dir(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRb   u   s    $c         O   sI   |  i  } t t |   i | |   | i   t |  d d d d g  d  S(   Nt   getquickstatst   getcompletestatst	   get_mtimet   has_suggestions(   R^   Ra   R>   t   deleteR   (   R7   Rd   Re   R^   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRk      s    	
c         C   s   t  |  i  S(   N(   R   RJ   (   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   get_absolute_url   s    c         C   s   d  |  i  i |  i i f S(   s   %s [%s](   R<   t   fullnameR;   t   name(   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   <lambda>   s    c         C   s   t  |  i  S(   N(   R   t	   real_path(   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   _get_abs_real_path   s    c         C   s   t  |  |  _ d  S(   N(   R   Rp   (   R7   t   value(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   _set_abs_real_path   s    c         C   s   |  i  i   S(   N(   R<   t   get_treestyle(   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   _get_treestyle   s    c         C   sL   t  i i |  i i t  i  t  i g } t  i d | d |  i d |  i	 i
  S(   Nt   checkerclassest   errorhandlert   languagecode(   R   t   projectcheckersRK   R<   t
   checkstylet   StandardCheckert   StandardUnitCheckert
   TeeCheckert   filtererrorhandlerR;   R`   (   R7   Rv   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   _get_checker   s    		c         C   s   t  i d | | | |  t S(   Nu   error in filter %s: %r, %r, %s(   t   loggingt   errorR4   (   R7   t   functionnamet   str1t   str2t   e(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR~      s    c         C   sm   t  |  d  pV y |  i |  i |  _ Wqf t j
 o, t |   |  _ t |   |  i |  i <qf Xn |  i S(   Nt   _non_db_state(   t   hasattrt   _non_db_state_cacheRY   R   t   KeyErrorR-   (   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   _get_non_db_state   s    c         C   sS   xL |  i  i d d  i d t  i   D]# } | i d t d | d |  q( Wd S(   s*   update all stores to reflect state on diskt   filet    t
   state__gtet   update_translationt   update_structuret   conservativeN(   t   storest   excludet   filterR   RF   t   updateR2   (   R7   R   t   store(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR      s    ( c      
   C   sY   xR |  i  i d d  i d t  i   D]) } | i d t d | d | d t  q( Wd S(	   s'   sync unsaved work on all stores to diskR   R   R   R   R   R   t   createN(   R   R   R   R   RF   t   syncR2   R4   (   R7   R   R   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR      s    ( c         C   s   t  t i i d |   d d   S(   Nt   store__translation_projectt   mtime(   R   R   R?   R   R/   (   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRi      s    c         C   s   d } x |  i  i d t  i   D] } y | i   Wq" t j
 o$ t i d | i  | d 7} q" t	 j
 o) } t i d | i |  | d 7} q" t
 t f j
 o) } t i d | i |  | d 7} q" Xq" W| S(   s    makes sure all stores are parsedi    t	   state__ltu   Duplicate IDs in %si   u   Failed to parse %s
%su   Can't access %s
%s(   R   R   R   RF   t   require_unitsR   R   t   infoR]   R
   t   IOErrorRA   (   R7   t   errorsR   R   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR      s     c         C   sJ   |  i  o t S|  i   } t t i i d |  d t   } | | d <| S(   NR   t	   state__gtR   (   t   is_template_projectR   R   R   R   R?   R   R   (   R7   R   t   stats(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRg      s    
!
c         C   sg   |  i  o t Sx- |  i i d t  i   D] } | i   q+ Wt i i d |  d t	  } t
 | d  S(   NR   t    unit__store__translation_projectt   false_positiveRn   (   R   R   R   R   R   RF   t   require_qualitychecksR   R?   R4   R   (   R7   R   t   query(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRh      s    
 c   	   	   C   sT  |  i  o d S|  i i   } | d j p | |  j o d S|  i i   } | p |  i   n | d j o |  i   } n x | i i   D]{ } |  i	 d j o t
 |  |  \ } } n t |  |  \ } } | d j	 o | | j o q n t |  | | | |  q W|  i   | d j o, |  i   } t i d |  d | d |  n d S(   s)   update translation project from templatesNt   gnut   sendert   oldstatst   newstats(   R   R<   t   get_template_translationprojectR/   t   is_monolingualR   Rg   R   RF   R\   R,   R+   R*   Rc   R&   t   send(	   R7   RJ   t   template_translation_projectt   monolingualR   R   t   new_pootle_patht   new_pathR   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   update_from_templates   s,    
 
c            s   t  d     i i i d  D  } t i   i i }   i o t i   i i   } n   i	 d j ok   i
 i d  o, t   | |   i   i   f d    q t   | |   i   i   f d    n t   | |   i   i  d S(   s7   returns a list of po files for the project and languagec         s   s   x |  ] } | i    Vq Wd  S(   N(   t   strip(   t   .0t   p(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pys	   <genexpr>  s   	 t   ,R   s   /templates/c            s   t    i |   S(    (   R(   R<   (   t   filename(   R7   (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRo     s    c            s   t    i i |   S(    (   R)   R;   R`   (   R   (   R7   (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRo     s    N(   t   setR<   t   ignoredfilest   splitt   ost   extsept   localfiletypeR   t   get_template_filtetypeR\   RJ   t
   startswithR'   R]   R^   (   R7   t   ignored_filest   ext(    (   R7   s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRc     s    %
c         C   s   |  i  i d  j o |  i  i o yF |  i   } |  i  i p |  i |  t |  i  _ n | |  i  _ Wq t j
 o= } t	 i
 d |  i i |  i i t |   t |  i  _ q Xn |  i  i S(   Nu-   Could not initialize indexer for %s in %s: %s(   t   non_db_stateR6   R/   R3   t   make_indexerR5   t
   init_indexR2   t	   ExceptionR   t   warningR<   R`   R;   t   strR4   (   R7   R6   R   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   _get_indexer  s     (c         C   s'   |  i  i o |  i  i p |  i d  j S(   N(   R   R3   R5   R6   R/   (   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt
   _has_index%  s    c         C   s  | i  d t  y# t i |  i i d | i i  Wn n X| i   } | i i	 } yG t
 i d | i i  t i | i i  | i i   | i i   Wn> t j
 o2 } t
 i d | | i i  | i   t  n Xy t
 i d | i i  | i d t d t d t  | i   } t
 i d | i i  | i | d  d	 t d
 t d t d t WnW t j
 oK } t
 i d | | i i  | i   | i d t d t d t    n Xy# t i |  i i d | i i  Wn n X| i   } | | | f S(   NR   t	   preupdateu    updating %s from version controluK   near fatal catastrophe, exception %s while updating %s from version controlu*   parsing version control copy of %s into dbR   R   u&   merging %s with version control updatet   allownewstringst   suggestionst   notranslatet   obsoletemissinguO   near fatal catastrophe, exception %s while merging %s with version control copyt
   postupdate(   R   R2   R   t   hookR<   R`   R   t   pathRg   R   R   t   debugR	   t
   updatefilet   _delete_store_cachet   _update_store_cacheR   R   Rb   RH   R   R4   t	   mergefileR/   (   R7   R   R   t   working_copyR   t   remotestatsR   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt    update_file_from_version_control+  sB    #
,
#c   	      C   s`  t  d |  p t t d    n |  i   } h  } xd |  i i d d  i   D]G } y+ |  i |  \ } } } t | |  } WqT t	 j
 o qT XqT W|  i
   |  i   } | i i i d t t d |  i    | i i i d t d |   | i i i d t d |   | i i i d t d	 |   t i d
 |  d | d | d |  d S(   sb   updates project translation files from version control,
        retaining uncommitted translationst   commits:   You do not have rights to update from version control hereR   R   t   messages)   Updated project "%s" from version controls   working copys   remote copys   merged copyR   R   R   R   N(   R#   R   t   _Rg   R   R   RF   R   R   RH   Rc   t   usert   message_setR   t   unicodeRm   t   stats_messageR$   R   (	   R7   t   requestt	   old_statst   remote_statsR   R   R   R   t	   new_stats(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   update_projectW  s$     	
(c         C   s;  t  d |  p t t d    n y |  i |  \ } } } | i i i d t t d | i i	    | i i i d t
 d |   | i i i d t
 d |   | i i i d t
 d |   t i d |  d	 | d
 | d |  Wn> t j
 o2 | i i i d t t d | i i	    n X|  i   d S(   sM   updates file from version control, retaining uncommitted
        translationsR   s:   You do not have rights to update from version control hereR   s$   Updated file %s from version controls   working copys   remote copys   merged copyR   R   R   R   s(   Failed to update %s from version controlN(   R#   R   R   R   R   R   R   R   R   Rn   R   R$   R   RH   Rc   (   R7   R   R   R   R   R   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   update_filer  s    +&0c   
      C   s  t  d |  p t t d    n | i d t d t d t  | i   } | i i } t	 d t
 i | f |  } | i i   o+ t | i i  o | d | i i 7} n y1 t i |  i i d | i i d	 | d
 | } Wn" t j
 o | i i g } n Xt } yH xA | D]9 } t i | d
 | d	 | | i i i d
 d |  qWWnE t j
 o9 }	 t i d |	  | i i i d
 d |	  t } n Xy) t i |  i i d | i i d | Wn n Xt i d |  d | d | d | i d |  | S(   s0   commits an individual PO file to version controlR   s+   You do not have rights to commit files hereR   R   R   s   Commit from %s by user %s.s    <%s>t	   precommitt   authorR   s   Committed file: <em>%s</em>u   Failed to commit files: %ss   Failed to commit file: %st
   postcommitt   successR   R   R   R   (   R#   R   R   R   R4   R2   Rg   R   t   usernameR   R    t   TITLEt   is_authenticatedt   lent   emailR   R   R<   R`   R   R   t   ImportErrorR	   t
   commitfileR   R   R   R   R   R%   R   (
   R7   R   R   R   R   R   t   filestocommitR   R   R   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   commitpofile  s8    #1 ")+c         C   s^   y) t  i |  i i d |  i |  i i  Wn. t j
 o" } t i d |  i i |  n Xd  S(   Nt
   initializeu   Failed to initialize (%s): %s(	   R   R   R<   R`   Rp   R;   R   R   R   (   R7   R   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR     s    )c   
         sK  d	 } z t i d d d d  \ } } t i |  t i d   i d i   f d   | i   D  | f  } | d j oG | d	 j	 o t	 i
 | |  d	 St | d
  i   } | o | Sn Wd	 | d	 j	 o$ t i i |  o t i |  n Xd	 } z | d	 j	 o> t i d d d d  \ } } t i |  t | d  } n t i   } t i | d t i  } xM | i   D]? }	 | i |	 i i d  |	 i t   i  d i d   qW| i   | d	 j	 o t	 i
 | |  n | i   SWd	 | d	 j	 o$ t i i |  o t i |  n y | i   Wn n XXd	 S(   s)   returns an archive of the given filenamest   prefixt   pootlet   suffixs   .zips   cd %s ; zip -r - %s > %st    c         3   s-   x& |  ] } | i  t   i   d  Vq Wd S(   i   N(   R]   R   (   R   R   (   R7   (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pys	   <genexpr>  s   	 i    Nt   rt   wbt   ws   utf-8i   (   R/   t   tempfilet   mkstempR   t   closet   systemR]   t   joinRF   t   shutilt   movet   opent   readR   t   existst   removet	   cStringIOt   StringIOt   zipfilet   ZipFilet   ZIP_DEFLATEDt   writet   encodeR   t   getvalue(
   R7   R   R   t   tempzipfilet   fdt   resultt   filedatat   archivecontentst   archiveR   (    (   R7   s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   get_archive  sF    >  =
 c         C   sv   t  i d |  i  t i i |  i |  i  } t i	 |  } | i
 h | i d 6| i d 6| i d 6| i d 6 | S(   s  get an indexing object for this project

        Since we do not want to keep the indexing databases open for the lifetime of
        the TranslationProject (it is cached!), it may NOT be part of the Project object,
        but should be used via a short living local variable.
        u   Loading indexer for %st
   pofilenamet   itemnot   pomtimet   dbid(   R   R   RJ   R   R   R   R]   t   index_directoryR   t   get_indexert   set_field_analyzerst   ANALYZER_EXACT(   R7   t   indexdirt   index(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR     s    	


c         C   s   yR | i    x' |  i i   D] } |  i | |  q W| i   | i d t  Wn@ t j
 o4 } t i	 d |  |  y | i
   Wq q Xn Xd S(   s   initializes the search indext   optimizeu    Error opening indexer for %s:
%sN(   t   begin_transactionR   RF   t   update_indext   commit_transactiont   flushR2   R   R   R   t   cancel_transaction(   R7   R6   R   R   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR     s    
 
c         C   sV  | d j o t St t | i    d  } | i d | i f g t  } | i d | f g t  } | i | | g t  } | i |  i	   } d }	 | d j o | o d S| d j	 oM | i
 i d |  }	 | i d t |  f g t  }
 | i | |
 g  n: t i d |  i | i  | i h | i d 6 | i
 }	 g  } x |	 i   D] } h | i d 6| d 6t | i  d	 6t | i  d 6} | i   o. d
 i | i i  } d
 i | i i  } n | i } | i } | | d <| | d <| i   | d <| i   | d <| i |  qZW| o" x | D] } | i |  q7Wn d S(   s  updates the index with the contents of pofilename (limit to items if given)

        There are three reasons for calling this function:
            1. creating a new instance of L{TranslationProject} (see L{initindex})
                    -> check if the index is up-to-date / rebuild the index if necessary
            2. translating a unit via the web interface
                    -> (re)index only the specified unit(s)

        The argument L{item} should be None for 1.

        known problems:
            1. This function should get called, when the po file changes externally.
                 WARNING: You have to stop the pootle server before manually changing
                 po files, if you want to keep the index database in sync.

        @param unitid: pk of unit within the po file OR None (=rebuild all)
        @type unitid: int
        @param optimize: should the indexing database be optimized afterwards
        @type optimize: bool
        i   R  R  i    NRY   R  u   Updating %s indexer for file %sR  s   
t   sourcet   targett   notest	   locations(   R/   R4   R   t   hashRi   t
   make_queryRJ   R2   t   get_query_resultt   get_matches_countt   unitsR   t
   delete_docR   R   RF   R  RY   t	   haspluralR   R%  t   stringsR&  t   getnotest   getlocationst   appendt   index_document(   R7   R6   R   t   unitidR  t   pofilenamequeryt   pomtimequeryt   gooditemsqueryt   gooditemsnumR-  t
   itemsqueryt   addlistt   unitt   doct   origt   transt   add_item(    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR!    sL    !	 		

 c         C   s   |  i  i d   S(   s   /terminology/(   RJ   t   endswith(   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRo   S  s    c         C   s   |  |  i  i   j S(    (   R<   R   (   R7   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyRo   T  s    c         C   s9  t  i i   } d } |  i o |  i i   } |  i   } n y= t i i	 d |  i
 d d  } | i   } | i i   } Wn t i j
 o n X|  i i d d  } x) | i   D] } t | | i    } q W| | B} | d j o d S| |  i i j o+ t i | i    |  i _ | |  i _ n |  i i S(   s   returns the terminology matcherR;   t   project__codet   terminologyt   name__startswiths   pootle-terminologyN(   R   R?   t   noneR/   t   is_terminology_projectR   t   allRi   R>   RK   t   language_idt   DoesNotExistR   RF   t   maxR   R1   R   t   terminologymatcherR0   (   R7   t   terminology_storesR   t   termprojectt   local_terminologyR   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   gettermmatcherV  s,    
 
i   c   	      C   s   x |  i  i   D] } | i |  } | d  j	 o | i   ow | i   o_ | d j oR |  i i } | o; t i	 |  } | i
 i | |  } | d  j	 o | Sq q | i
 Sq q W| d j o | d  j	 o | S| Sd  S(   Ni   (   R   RF   t   findunitR/   t   istranslatedR/  R;   t   pluralequationt   gettextt   c2pyR&  R0  (	   R7   t   singulart   pluralt   nR   R<  RR  t   pluralfnR&  (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   translate_messaget  s     (    N(G   R9   R:   R   R    t   PARSE_POOL_SIZEt   PARSE_POOL_CULL_FREQUENCYR   RI   R?   R  RM   R   t
   ForeignKeyR    R2   R;   R   R<   t   FilePathFieldR4   Rp   t   OneToOneFieldR!   R^   t	   CharFieldRJ   RV   t   dependenciesRW   Rb   Rk   Rl   t   propertyRm   Rq   Rs   R]   Ru   R\   R   t   checkerR~   R   R   R   R   R   Ri   R   Rg   Rh   R/   R   Rc   R   R6   R   t	   has_indexR   R   R   R   R   R  R   R   R!  RF  R   RO  RY  (    (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR>   _   sf   	*			
								
							,			'	1		L	c         C   s8   d |  | i  d d  | i  d d  | i  d d  f S(   Ns,   %s: %d of %d messages translated (%d fuzzy).t
   translatedi    t   totalt   fuzzy(   RK   (   t   versionR   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyR     s    c         K   s?   | p | o d  Sx$ t  i i   D] } t | |  q$ Wd  S(   N(   R    R?   RF   RE   (   R   t   instanceRD   t   rawRe   R;   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   scan_languages  s
     R   c         K   s?   | p | o d  Sx$ t  i i   D] } t | |  q$ Wd  S(   N(   R   R?   RF   RE   (   R   Rh  RD   Ri  Re   R<   (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   scan_projects  s
     ([   R   R  RS  R  R   R   R   t   django.confR    t	   django.dbR   R   t   django.db.models.signalsR   t   django.core.exceptionsR   t   django.utils.translationR   R   t   translate.filtersR   t   translate.searchR   R   t   translate.storageR	   t   translate.storage.baseR
   t   translate.misc.lruR   t   pootle.scriptsR   t   pootle_misc.utilR   R   R   t   pootle_misc.baseurlR   t   pootle_misc.aggregateR   R   t   pootle_store.utilR   t   pootle_store.modelsR   R   R   R   R   R   R   R   R   R   t   pootle_app.lib.utilR   t   pootle_project.modelsR   t   pootle_language.modelsR    t   pootle_app.models.directoryR!   t
   pootle_appR"   t   pootle_app.models.permissionsR#   t   pootle_app.models.signalsR$   R%   R&   t   pootle_app.project_treeR'   R(   R)   R*   R+   R,   t   objectR-   RE   RG   R   RH   RI   t   ModelR>   R   R4   Rj  t   connectRk  (    (    (    s>   /var/www/Pootle/local_apps/pootle_translationproject/models.pyt   <module>   s^   (	
	  ,	