Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Showing with 29 additions and 6 deletions.
  1. +29 −6 substanced/sdi/views/folder.py
View
35 substanced/sdi/views/folder.py
@@ -396,6 +396,8 @@ def main(global_config, **settings):
columns=custom_user_columns)
config.scan()
+ XXX TODO Document ``sort_index``, ``reverse``, ``filter_text``.
+ sort_index now also takes a string which looks up the catalog index.
"""
folder = self.context
request = self.request
@@ -420,6 +422,28 @@ def main(global_config, **settings):
text = catalog['text']
q = q & text.eq(filter_text)
+ # BR: sort_index can be a string with the name of the catalog index,
+ # or, the index object itself. If it is a name, it is looked up. XXX
+ # Untested!!! XXX TODO!!!
+ #
+ # CM: this should be a tuple of (catalog_name, index_name) at least,
+ # and optionally a callback that accepts the folder, and which returns
+ # the index object. This logic should not be done here; it should
+ # be done in views that call this method instead.
+
+ if isinstance(sort_index, basestring):
+ try:
+ sort_index = catalog[sort_index]
+ except KeyError:
+ keys = tuple(catalog.keys())
+ raise KeyError(
+ (
+ 'Index %r is missing from the catalog. '
+ 'If sort_index is a string, then it must match the '
+ 'name of a catalog index. %r' % (sort_index, keys)
+ )
+ )
+
if folder.is_ordered() and sort_index is None:
# hypatia resultset.sort will call IFolder.sort method
sort_index = folder
@@ -539,9 +563,8 @@ def show(self):
sortDir = True # True ascending, or False descending.
reverse = (not sortDir)
- # XXX sortCol not implemented
folder_length, records = self._folder_contents(
- 0, minimum_load, reverse=reverse
+ 0, minimum_load, reverse=reverse, sort_index=sortCol
)
items = {
@@ -593,19 +616,19 @@ def show_json(self):
def _get_json(self):
request = self.request
-
if 'from' in request.params:
start = int(request.params.get('from'))
end = int(request.params.get('to'))
- # sort_col = request.params.get('sortCol') # XXX ignored
+ sort_col = request.params.get('sortCol')
sort_dir = request.params.get('sortDir') in ('true', 'True')
filter_text = request.params.get('filter', '').strip()
reverse = (not sort_dir)
- # XXX sortCol not implemented
+
folder_length, records = self._folder_contents(
- start, end, reverse=reverse, filter_text=filter_text
+ start, end, reverse=reverse, filter_text=filter_text,
+ sort_index=sort_col,
)
items = {

No commit comments for this range

Something went wrong with that request. Please try again.