ó
á‘Xc           @   sV   d  Z  d d l m Z d d l m Z m Z d d l m Z d e f d „  ƒ  YZ d S(   s5    XTMPageFormatter class
    Extends ZPTPageFormatter
iÿÿÿÿ(   t   ZPTPageFormatter(   t	   cmp_alphat
   cmp_simple(   t   Configt   XTMPageFormatterc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sß   Obtains XTM data from xtm.Handler and puts it into templates context
       'DataStore', 'ContentFormatter', 'encoding' and 'XTMHandler' objects must be added
       to Config before, instanciating object of this class
    c         C   s#   t  j d ƒ |  _ t j |  ƒ d S(   sÁ   Initilize XTMPageFormatter
           'DataStore', 'ContentFormatter', 'encoding' and 'XTMHandler' objects must be added
           to Config before, instanciating object of this class
        t
   XTMHandlerN(   R   t   gett   xtmR    t   __init__(   t   self(    (    s"   lib/medus/page/XTMPageFormatter.pyR      s    c         C   s9   |  j  j ƒ  j j ƒ  } | j t ƒ | j d | ƒ | S(   s3   Add objects to the context for zpt template toc.zptt   topics(   R   t   getTopicMapR
   t   keyst   sortR   t	   addGlobal(   R	   t   contextt   fieldsR   (    (    s"   lib/medus/page/XTMPageFormatter.pyt   _context_toc   s    c         C   s   | d } | j  d | ƒ | j  d |  j j |  j j | ƒ ƒ j |  j ƒ ƒ |  j j | ƒ } | j	 t
 ƒ | j  d | ƒ | S(   s4   Add objects to the context for zpt template view.zptt   wnt   titlet   contentt   associations(   R   t	   formattert   formatt	   datastoret   readt   decodet   encodingR   t   getTopicAssociationsR   R   (   R	   R   R   R   R   (    (    s"   lib/medus/page/XTMPageFormatter.pyt   _context_view   s    
4c   	      C   s0  | d } | j  d | ƒ | j  d |  j j | ƒ j |  j ƒ ƒ |  j j ƒ  } | j t ƒ | j  d | ƒ |  j j	 ƒ  } | j t ƒ | j  d | ƒ |  j j
 | ƒ } | j t ƒ | j  d | ƒ |  j j | ƒ rô |  j j | ƒ rô d p÷ d } | j  d	 | ƒ |  j j | ƒ } | j  d
 | ƒ | S(   s4   Add objects to the context for zpt template edit.zptR   R   R   t   rolesR
   R   t   Truet    t
   couldeletet   exists(   R   R   R   R   R   R   t   getRolesR   R   t	   getTopicsR   R   t   hasTopict	   isBuiltIn(	   R	   R   R   R   R   R
   R   R!   R"   (    (    s"   lib/medus/page/XTMPageFormatter.pyt   _context_edit+   s"    
(1c   	      C   sw  |  j  j ƒ  } | j t ƒ | j d | ƒ |  j  j ƒ  } | j t ƒ | j d | ƒ d } } | j d ƒ } | rÂ | j d | j |  j	 ƒ ƒ | j d |  j
 j | ƒ ƒ | j d t ƒ n  | j d ƒ d k rS| j d ƒ d	 k rù | d } n  | j d
 ƒ d	 k r| d
 } n  |  j  j | | ƒ } | j d | ƒ | j d t ƒ n  | j d | ƒ | j d | ƒ | S(   s6   Add objects to the context for zpt template search.zptR   R
   t   queryt   searchresultst   searcht   formt   filtert   rtopict   anyt   rolet   filterresultst   getrolet   gettopicN(   R   R#   R   R   R   R$   t   NoneR   R   R   R   R*   R   R,   (	   R	   R   R   R   R
   R/   R-   R(   R0   (    (    s"   lib/medus/page/XTMPageFormatter.pyt   _context_searchF   s.    
(   t   __name__t
   __module__t   __doc__R   R   R   R'   R4   (    (    (    s"   lib/medus/page/XTMPageFormatter.pyR      s   				N(   R7   R    t   xtm.utilR   R   t	   medus.cfgR   R   (    (    (    s"   lib/medus/page/XTMPageFormatter.pyt   <module>   s   