entities/__init__.py
branchstable
changeset 7143 0517e3bf0b84
parent 6039 6e84db1b3e44
child 7827 9bbf83f68bcc
equal deleted inserted replaced
7142:c47381851a3e 7143:0517e3bf0b84
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
   119         return value
   119         return value
   120 
   120 
   121     # edition helper functions ################################################
   121     # edition helper functions ################################################
   122 
   122 
   123     def linked_to(self, rtype, role, remove=True):
   123     def linked_to(self, rtype, role, remove=True):
   124         """if entity should be linked to another using __linkto form param for
   124         """if entity should be linked to another using '__linkto' form param for
   125         the given relation/role, return eids of related entities
   125         the given relation/role, return eids of related entities
   126 
   126 
   127         This method is consuming matching link-to information from form params
   127         This method is consuming matching link-to information from form params
   128         if `remove` is True (by default).
   128         if `remove` is True (by default). Computed values are stored into a
       
   129         `cw_linkto` attribute, a dictionary with (relation, role) as key and
       
   130         linked eids as value.
   129         """
   131         """
   130         try:
   132         try:
   131             return self.__linkto[(rtype, role)]
   133             return self.cw_linkto[(rtype, role)]
   132         except AttributeError:
   134         except AttributeError:
   133             self.__linkto = {}
   135             self.cw_linkto = {}
   134         except KeyError:
   136         except KeyError:
   135             pass
   137             pass
   136         linktos = list(self._cw.list_form_param('__linkto'))
   138         linktos = list(self._cw.list_form_param('__linkto'))
   137         linkedto = []
   139         linkedto = []
   138         for linkto in linktos[:]:
   140         for linkto in linktos[:]:
   142                 # hidden input
   144                 # hidden input
   143                 if remove:
   145                 if remove:
   144                     linktos.remove(linkto)
   146                     linktos.remove(linkto)
   145                     self._cw.form['__linkto'] = linktos
   147                     self._cw.form['__linkto'] = linktos
   146                 linkedto.append(typed_eid(eid))
   148                 linkedto.append(typed_eid(eid))
   147         self.__linkto[(rtype, role)] = linkedto
   149         self.cw_linkto[(rtype, role)] = linkedto
   148         return linkedto
   150         return linkedto
   149 
   151 
   150     # server side helpers #####################################################
   152     # server side helpers #####################################################
   151 
   153 
   152 # XXX:  store a reference to the AnyEntity class since it is hijacked in goa
   154 # XXX:  store a reference to the AnyEntity class since it is hijacked in goa