Skip to content

Commit

Permalink
Making the collection order_by more flexible.
Browse files Browse the repository at this point in the history
Allows for passing either a string of the attribute or a iterable of the attributes to order by.
  • Loading branch information
Zoramite committed Nov 10, 2017
1 parent cce70f6 commit fa57ddc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions grow/pods/collection.py
Expand Up @@ -263,8 +263,11 @@ def list_categories(self):
def list_docs(self, order_by=None, locale=utils.SENTINEL, reverse=None,
include_hidden=False, recursive=True, inject=False):
reverse = False if reverse is None else reverse
order_by = 'order' if order_by is None else order_by
key = operator.attrgetter(order_by, 'pod_path')
if order_by is None:
order_by = ('order', 'pod_path')
elif isinstance(order_by, basestring):
order_by = (order_by, 'pod_path')
key = operator.attrgetter(*order_by)
sorted_docs = structures.SortedCollection(key=key)
if inject:
injected_docs = self.pod.inject_preprocessors(collection=self)
Expand Down

0 comments on commit fa57ddc

Please sign in to comment.