web/action.py
branchtls-sprint
changeset 1433 091ac3ba5d51
parent 1432 2c3711d4570b
child 1536 1e695b78d085
equal deleted inserted replaced
1432:2c3711d4570b 1433:091ac3ba5d51
    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     __select__ = yes()
    23     __select__ = yes()
    24     
    24 
    25     property_defs = {
    25     property_defs = {
    26         'visible':  dict(type='Boolean', default=True,
    26         'visible':  dict(type='Boolean', default=True,
    27                          help=_('display the action or not')),
    27                          help=_('display the action or not')),
    28         'order':    dict(type='Int', default=99,
    28         'order':    dict(type='Int', default=99,
    29                          help=_('display order of the action')),
    29                          help=_('display order of the action')),
    32                                      'useractions', 'siteactions', 'hidden'),
    32                                      'useractions', 'siteactions', 'hidden'),
    33                          help=_('context where this component should be displayed')),
    33                          help=_('context where this component should be displayed')),
    34     }
    34     }
    35     site_wide = True # don't want user to configuration actions eproperties
    35     site_wide = True # don't want user to configuration actions eproperties
    36     category = 'moreactions'
    36     category = 'moreactions'
    37     
    37 
    38     def url(self):
    38     def url(self):
    39         """return the url associated with this action"""
    39         """return the url associated with this action"""
    40         raise NotImplementedError
    40         raise NotImplementedError
    41     
    41 
    42     def html_class(self):
    42     def html_class(self):
    43         if self.req.selected(self.url()):
    43         if self.req.selected(self.url()):
    44             return 'selected'
    44             return 'selected'
    45         if self.category:
    45         if self.category:
    46             return 'box' + self.category.capitalize()
    46             return 'box' + self.category.capitalize()
    50     """non registered action used to build boxes. Unless you set them
    50     """non registered action used to build boxes. Unless you set them
    51     explicitly, .vreg and .schema attributes at least are None.
    51     explicitly, .vreg and .schema attributes at least are None.
    52     """
    52     """
    53     category = None
    53     category = None
    54     id = None
    54     id = None
    55     
    55 
    56     def __init__(self, req, rset, title, path, **kwargs):
    56     def __init__(self, req, rset, title, path, **kwargs):
    57         Action.__init__(self, req, rset)
    57         Action.__init__(self, req, rset)
    58         self.title = req._(title)
    58         self.title = req._(title)
    59         self._path = path
    59         self._path = path
    60         self.__dict__.update(kwargs)
    60         self.__dict__.update(kwargs)
    61         
    61 
    62     def url(self):
    62     def url(self):
    63         return self._path
    63         return self._path
    64 
    64 
    65 
    65 
    66 class LinkToEntityAction(Action):
    66 class LinkToEntityAction(Action):
    72     """
    72     """
    73     __select__ = (match_search_state('normal') & one_line_rset()
    73     __select__ = (match_search_state('normal') & one_line_rset()
    74                   & partial_relation_possible(action='add')
    74                   & partial_relation_possible(action='add')
    75                   & partial_may_add_relation())
    75                   & partial_may_add_relation())
    76     registered = accepts_compat(Action.registered)
    76     registered = accepts_compat(Action.registered)
    77     
    77 
    78     category = 'addrelated'
    78     category = 'addrelated'
    79                 
    79 
    80     def url(self):
    80     def url(self):
    81         current_entity = self.rset.get_entity(self.row or 0, self.col or 0)
    81         current_entity = self.rset.get_entity(self.row or 0, self.col or 0)
    82         linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self))
    82         linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self))
    83         return self.build_url(vid='creation', etype=self.etype,
    83         return self.build_url(vid='creation', etype=self.etype,
    84                               __linkto=linkto,
    84                               __linkto=linkto,
    89     """DEPRECATED / BACKWARD COMPAT
    89     """DEPRECATED / BACKWARD COMPAT
    90     """
    90     """
    91     registered = deprecate(condition_compat(accepts_compat(Action.registered)),
    91     registered = deprecate(condition_compat(accepts_compat(Action.registered)),
    92                            msg='EntityAction is deprecated, use Action with '
    92                            msg='EntityAction is deprecated, use Action with '
    93                            'appropriate selectors')
    93                            'appropriate selectors')
    94     
    94