92 |
92 |
93 def possible_actions(self, **kwargs): |
93 def possible_actions(self, **kwargs): |
94 """Return possible actions on this result set. Should always be called with the same |
94 """Return possible actions on this result set. Should always be called with the same |
95 arguments so it may be computed only once. |
95 arguments so it may be computed only once. |
96 """ |
96 """ |
|
97 if not kwargs: |
|
98 raise ValueError("ResultSet.possible_actions is expecting to receive " |
|
99 "keywords arguments to be able to compute access to " |
|
100 "the cache only once but you provided none.") |
|
101 |
97 key = tuple(sorted(kwargs.items())) |
102 key = tuple(sorted(kwargs.items())) |
98 if self._actions_cache is None: |
103 if self._actions_cache is None: |
99 actions = self.req.vreg['actions'].poss_visible_objects( |
104 actions = self.req.vreg['actions'].poss_visible_objects( |
100 self.req, rset=self, **kwargs) |
105 self.req, rset=self, **kwargs) |
101 self._actions_cache = (key, actions) |
106 self._actions_cache = (key, actions) |
102 return actions |
107 return actions |
103 else: |
108 else: |
104 assert key == self._actions_cache[0], \ |
109 if key != self._actions_cache[0]: |
105 'unexpected new arguments for possible actions (%s vs %s)' % ( |
110 raise ValueError("ResultSet.possible_actions expects to always " |
106 key, self._actions_cache[0]) |
111 "receive the same arguments to compute the " |
|
112 "cache once, but you've call it with the " |
|
113 "arguments: '%s' that aren't the same as the " |
|
114 "previously used combinaison '%s'" % (key, self._actions_cache[0])) |
107 return self._actions_cache[1] |
115 return self._actions_cache[1] |
108 |
116 |
109 def __len__(self): |
117 def __len__(self): |
110 """returns the result set's size""" |
118 """returns the result set's size""" |
111 return self.rowcount |
119 return self.rowcount |