ó
}c‹Ac           @   sh   d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l m	 Z	 d e f d „  ƒ  YZ
 d S(   s    ZPTPageFormatter class
    If you want to implement new PageFormatter that uses ZPT:
    extend this class and create new _context_ methods. 
iÿÿÿÿ(   t	   simpleTALt   simpleTALESt   simpleTALUtilsN(   t   SimplePageFormatter(   t   Configt   ZPTPageFormatterc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s*   ZPT page formatting
       'DataStore', 'ContentFormatter' and 'encoding' objects must be added to Config before,
       instanciating object of this class
       Local variables initialised in the Base class constructor:
         self.datastore
         self.formatter
         self.encoding
    c         C   s  | j  d ƒ p d } t j d d ƒ } | j d i t j  d ƒ d 6t j  d ƒ d 6t j  d ƒ d 6t j  d	 ƒ d	 6ƒ t |  d
 | ƒ | | ƒ } t t j j	 t j  d ƒ d j	 | d g ƒ ƒ d ƒ } t
 j | |  j ƒ } | j ƒ  t j ƒ  } | j | | |  j ƒ | j ƒ  S(   sV   fields - dict of HTTP pears. Returns formatted page string, according to fields['job']t   jobt   viewt   allowPythonPathi   t   cfgt   versiont   linkt   logot   csst	   _context_t   zpt_patht    s   .zptt   r(   t   getR   t   Contextt	   addGlobalR   t   getattrt   opent   ost   patht   joinR    t   compileHTMLTemplatet   encodingt   closeR   t   FastStringOutputt   expandt   getvalue(   t   selft   fieldsR   t   contextt   templateFilet   templatet   fastFile(    (    s"   lib/medus/page/ZPTPageFormatter.pyt   getpage   s    6
c         C   sR   | d } | j  d | ƒ | j  d |  j j |  j j | ƒ ƒ j |  j ƒ ƒ | S(   s4   Add objects to the context for zpt template view.zptt   wnt   titlet   content(   R   t	   formattert   formatt	   datastoret   readt   decodeR   (   R    R"   R!   R'   (    (    s"   lib/medus/page/ZPTPageFormatter.pyt   _context_view-   s    
4c         C   sh   | d } | j  d | ƒ | j  d |  j j | ƒ j |  j ƒ ƒ |  j j | ƒ } | j  d | ƒ | S(   s4   add objects to the context for zpt template edit.zptR'   R(   R)   t
   couldelete(   R   R,   R-   R.   R   t   exists(   R    R"   R!   R'   R0   (    (    s"   lib/medus/page/ZPTPageFormatter.pyt   _context_edit5   s    
(c         C   sR   | d } | j  d | ƒ | j  d |  j j |  j j | ƒ ƒ j |  j ƒ ƒ | S(   s5   add objects to the context for zpt template print.zptR'   R(   R)   (   R   R*   R+   R,   R-   R.   R   (   R    R"   R!   R'   (    (    s"   lib/medus/page/ZPTPageFormatter.pyt   _context_print?   s    
4c         C   s-   |  j  j ƒ  } | j ƒ  | j d | ƒ | S(   s3   add objects to the context for zpt template toc.zptt   topics(   R,   t   listdatat   sortR   (   R    R"   R!   t	   wikipages(    (    s"   lib/medus/page/ZPTPageFormatter.pyt   _context_tocF   s    
c         C   s    | j  d |  j j d ƒ ƒ | S(   s7   add objects to the context for zpt template changes.zptt   changesi   (   R   R,   t
   getchanges(   R    R"   R!   (    (    s"   lib/medus/page/ZPTPageFormatter.pyt   _context_changesM   s    c         C   sT   | j  d ƒ } | rP | j d | j |  j ƒ ƒ | j d |  j j | ƒ ƒ n  | S(   s6   add objects to the context for zpt template search.zptt   queryt   searchresults(   R   R   R.   R   R,   t   search(   R    R"   R!   R<   (    (    s"   lib/medus/page/ZPTPageFormatter.pyt   _context_searchR   s
    (
   t   __name__t
   __module__t   __doc__R&   R/   R2   R3   R8   R;   R?   (    (    (    s"   lib/medus/page/ZPTPageFormatter.pyR      s   			
			(   RB   t	   simpletalR    R   R   t   os.pathR   R   t	   medus.cfgR   R   (    (    (    s"   lib/medus/page/ZPTPageFormatter.pyt   <module>   s
   