Ñò
ï¯vLc           @   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 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 „  Z d „  Z d d d „ Z d „  Z h d d 6d d 6d d 6d d d d „ Z d S(   iÿÿÿÿ(   t   PermissionDenied(   t   modelformset_factory(   t   ugettext(   t	   mark_safe(   t   render_to_response(   t   RequestContext(   t	   ErrorList(   t   l(   t   paginate(   t   get_matching_permissionst   check_permission(   t   get_profilec            s   ‡  f d †  } | S(   Nc            s7   |  i  i p t t d ƒ ƒ ‚ n ˆ  |  | | Ž Sd  S(   Ns,   You do not have rights to administer Pootle.(   t   usert   is_superuserR    t   _(   t   requestt   argst   kwargs(   t   f(    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   decorated_f$   s    (    (   R   R   (    (   R   s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   user_is_admin#   s    c            s   ‡  f d †  } | S(   Nc            s   ‡ ‡  f d †  } | S(   Nc            s^   t  t |  i ƒ | i ƒ |  _ t ˆ  |  ƒ o ˆ |  | | | Ž St t d | i ƒ ƒ ‚ d  S(   Ns(   You do not have rights to administer %s.(	   R	   R   R   t	   directoryt   permissionsR
   R    R   t   fullname(   R   t   path_objR   R   (   t   permission_codeR   (    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyR   -   s    (    (   R   R   (   R   (   R   s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   wrap_f,   s    (    (   R   R   (    (   R   s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   has_permission+   s    t   codec            sH  d „  } d „  } ‡  f d †  } g  } y· |  i  d } g  } | i D] }	 |	 d j o | |	 qE qE ~ }
 | | |
 | ƒ x^ t |  i  ƒ D]M \ } } | d o
 d } n d } | | |
 | ƒ | | |
 | | | ƒ qŒ WWnZ t j
 oN | i d	 ƒ | i d
 ƒ | i t d ƒ ƒ | i d ƒ | i d ƒ n Xd i | ƒ S(   sÝ  Create an HTML table from the formset. The first form in the
    formset is used to obtain a list of the fields that need to be
    displayed. All these fields not appearing in 'exclude' will be
    placed into consecutive columns.

    Errors, if there are any, appear in the row above the form which
    triggered any errors.

    If the forms are based on database models, the order of the
    columns is determined by the order of the fields in the model
    specification.c         S   s   |  i  d ƒ x` | D]X } |  i  d ƒ | i | i d  j	 o! |  i  t | i | i ƒ ƒ n |  i  d ƒ q W|  i  d ƒ d  S(   Ns   <tr>
s   <th>s   </th>
s   </tr>
(   t   appendt   fieldst   labelt   Nonet   unicode(   t   resultR   t   formt   field(    (    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt
   add_headerC   s     !c         S   sˆ   t  | i ƒ d j on |  i d ƒ xM | D]E } |  i d ƒ |  i | i i | t ƒ  ƒ i ƒ  ƒ |  i d ƒ q* W|  i d ƒ n d  S(   Ni    s   <tr>
s   <td>s   </td>
s   </tr>
(   t   lent   errorsR   t   getR   t   as_ul(   R"   R   R#   R$   (    (    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt
   add_errorsL   s     %c            sT  |  i  d | ƒ x/t | ƒ D]!\ } } |  i  d | ƒ | d j o |  i  | d i ƒ  ƒ n | ˆ  j o« ˆ  | i j o› | o” t | ƒ o1 |  i  | | i ƒ ƒ |  i  | | i ƒ  ƒ q2t | | i ˆ  ƒ } |  i  d | d | i ˆ  d ƒ |  i  | | i ƒ  ƒ n |  i  | | i ƒ  ƒ |  i  d ƒ q W|  i  d	 ƒ d  S(
   Ns   <tr class="%s">
s   <td class="%s">i    t   ids	   <a href='s   '>s   </a>s   </td>
s   </tr>
(   R   t	   enumeratet	   as_hiddent   initialt   callablet   instanceR   t	   as_widget(   R"   R   R#   t   linkt   zebrat   iR$   (   t	   linkfield(    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   add_widgetsW   s      $$i    R+   i   t   oddt   evens   <tr>
s   <td>
s   No files in this project.s   </td>
s   </tr>
u    (   t   formsR   R,   t
   IndexErrorR   R   t   join(   t   formsetR2   R5   R%   R*   R6   R"   t
   first_formt   _[1]R$   R   R4   R#   R3   (    (   R5   s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   form_set_as_table7   s,    			5 
c         K   sÖ   t  | |  } | d j o | i i ƒ  } n |  i d j oo |  i oe t |  | ƒ } | |  i d | i ƒ} | i ƒ  o | i	 ƒ  n | t
 d ƒ | f S| i ƒ  } n t |  | ƒ } | d | i ƒ d | f S(   s†   With the Django model class 'model_class' and the Django form class 'form_class',
    construct a Django formset which can manipulate t   POSTt   querysets?   There are errors in the form. Please review the problems below.N(   R   R    t   objectst   allt   methodR@   R   t   object_listt   is_validt   saveR   t   filter(   R   t   model_classRA   R   t   formset_classRB   R<   (    (    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   process_modelformset†   s    t    t   titlet   formidt
   submitnamec         K   s‘  t  |  | d | | \ } }	 }
 h t t | | | ƒ ƒ d 6| d 6|
 d 6h t d ƒ d 6| i d d ƒ d 6t d	 ƒ d
 6| d d 6| d d 6|	 d 6d 6} d | j o | d | d <n d | j o | d | d <n d | j o | d | d <n d | j o | d | d <n d | j o | d | d <n d | j o | d | d <n d | j o | d | d <n t | | d t |  ƒ ƒS(   NRA   t   formset_textR<   RB   t   Homet   homeRM   RL   s   Save Changest   savechangesRO   RN   t	   error_msgt   textt   translation_projectt   projectt   languaget   source_languageR   t   navitemst	   feed_patht   context_instance(   RK   R   R?   R   R(   R   R   (   R   t   templateRI   t
   model_argsR2   R5   RA   R   R<   t   msgRB   t   template_vars(    (    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   edit­   s6    !N(   t   django.core.exceptionsR    t   django.forms.modelsR   t   django.utils.translationR   R   t   django.utils.safestringR   t   django.shortcutsR   t   django.templateR   t   django.forms.utilR   t   pootle_misc.baseurlR   t   pootle_misc.utilR   t   pootle_app.models.permissionsR	   R
   t   pootle_profile.modelsR   R   R   R    R?   RK   Ra   (    (    (    s9   /var/www/Pootle/local_apps/pootle_app/views/admin/util.pyt   <module>   s    		O	(