web/action.py
changeset 254 b1eda3dd844a
parent 0 b97547f5f1fa
child 631 99f5852f8604
equal deleted inserted replaced
253:57e88c0ba286 254:b1eda3dd844a
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 from cubicweb.common.appobject import AppRsetObject
     9 from cubicweb.common.appobject import AppRsetObject
    10 from cubicweb.common.registerers import action_registerer
    10 from cubicweb.common.registerers import action_registerer
    11 from cubicweb.common.selectors import add_etype_selector, \
    11 from cubicweb.common.selectors import add_etype_selector, \
    12      searchstate_selector, searchstate_accept_one_selector, \
    12      match_search_state, searchstate_accept_one, \
    13      searchstate_accept_one_but_etype_selector
    13      searchstate_accept_one_but_etype
    14     
    14     
    15 _ = unicode
    15 _ = unicode
    16 
    16 
    17 
    17 
    18 class Action(AppRsetObject):
    18 class Action(AppRsetObject):
    19     """abstract action. Handle the .search_states attribute to match
    19     """abstract action. Handle the .search_states attribute to match
    20     request search state. 
    20     request search state. 
    21     """
    21     """
    22     __registry__ = 'actions'
    22     __registry__ = 'actions'
    23     __registerer__ = action_registerer
    23     __registerer__ = action_registerer
    24     __selectors__ = (searchstate_selector,)
    24     __selectors__ = (match_search_state,)
    25     # by default actions don't appear in link search mode
    25     # by default actions don't appear in link search mode
    26     search_states = ('normal',) 
    26     search_states = ('normal',) 
    27     property_defs = {
    27     property_defs = {
    28         'visible':  dict(type='Boolean', default=True,
    28         'visible':  dict(type='Boolean', default=True,
    29                          help=_('display the action or not')),
    29                          help=_('display the action or not')),
   113 
   113 
   114 class AddEntityAction(Action):
   114 class AddEntityAction(Action):
   115     """link to the entity creation form. Concrete class must set .etype and
   115     """link to the entity creation form. Concrete class must set .etype and
   116     may override .vid
   116     may override .vid
   117     """
   117     """
   118     __selectors__ = (add_etype_selector, searchstate_selector)
   118     __selectors__ = (add_etype_selector, match_search_state)
   119     vid = 'creation'
   119     vid = 'creation'
   120     etype = None
   120     etype = None
   121     
   121     
   122     def url(self):
   122     def url(self):
   123         return self.build_url(vid=self.vid, etype=self.etype)
   123         return self.build_url(vid=self.vid, etype=self.etype)
   125 
   125 
   126 class EntityAction(Action):
   126 class EntityAction(Action):
   127     """an action for an entity. By default entity actions are only
   127     """an action for an entity. By default entity actions are only
   128     displayable on single entity result if accept match.
   128     displayable on single entity result if accept match.
   129     """
   129     """
   130     __selectors__ = (searchstate_accept_one_selector,)
   130     __selectors__ = (searchstate_accept_one,)
   131     schema_action = None
   131     schema_action = None
   132     condition = None
   132     condition = None
   133     
   133     
   134     @classmethod
   134     @classmethod
   135     def accept(cls, user, etype):
   135     def accept(cls, user, etype):
   215 
   215 
   216 class LinkToEntityAction2(LinkToEntityAction):
   216 class LinkToEntityAction2(LinkToEntityAction):
   217     """LinkToEntity action where the action is not usable on the same
   217     """LinkToEntity action where the action is not usable on the same
   218     entity's type as the one refered by the .etype attribute
   218     entity's type as the one refered by the .etype attribute
   219     """
   219     """
   220     __selectors__ = (searchstate_accept_one_but_etype_selector,)
   220     __selectors__ = (searchstate_accept_one_but_etype,)
   221     
   221