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