ó
âèÄ[c           @   s@   d  Z  d d l m Z d d l m Z d e f d     YZ d S(   s8    XTMFormProcessor class
    Extends SimpleFormProcessor
iÿÿÿÿ(   t   SimpleFormProcessor(   t   Configt   XTMFormProcessorc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s¶   Obtains XTM data from forms and saves/removes it into/from xtm file
      'DataStore' 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 XTMFormProcessor
          'DataStore' 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   XTMFormProcessor.pyR      s    c         C   sP   | d } |  j  j |  } |  j j | | d  | sL |  j  j |  n  d S(   s@   Process save form input. Create new XTM Topic ir such not existst   wnt   textN(   R   t   hasTopict	   datastoret   writet   addTopic(   R   t   fieldsR   t   topic_exists(    (    s   XTMFormProcessor.pyt
   _form_save   s
    
c         C   sŒ   | d } |  j  j |  } |  j j |  r |  j j |  r |  j j |  xK |  j j |  D]4 \ } } } |  j j |  sd |  j j |  qd qd Wn  | rž |  j  j |  n  d S(   s2   Remove given wikifile and XTM information about itR   N(	   R   t   existsR   R
   t	   isBuiltInt   removeTopict   getTopicAssociationst   removeAssociationt   remove(   R   R   R   t   file_existst   assidt   rolet   topic(    (    s   XTMFormProcessor.pyt   _form_delete    s    
%"c         C   s&   |  j  j | d | d | d  d S(   s   Create new XTM associationR   R   t   rtopicN(   R   t   addAssociation(   R   R   (    (    s   XTMFormProcessor.pyt   _form_associate/   s    c         C   su   d | k r | d p d } | rq t  |  t  g   k r^ x1 | D] } |  j j |  qA Wqq |  j j |  n  d S(   s    Remove selected XTM associationst   assidst    N(   t   typeR   R   (   R   R   R   t   id(    (    s   XTMFormProcessor.pyt   _form_removeassoc3   s    c         C   s   d | d <d S(   s   Process filter queryt   searcht   jobN(    (   R   R   (    (    s   XTMFormProcessor.pyt   _form_filter>   s    (	   t   __name__t
   __module__t   __doc__R   R   R   R   R#   R&   (    (    (    s   XTMFormProcessor.pyR   
   s   					N(   R)   R    t	   medus.cfgR   R   (    (    (    s   XTMFormProcessor.pyt   <module>   s   