Address code review comments from PR getpelican/pelican#1348

The text about the sort-by-key function comes from:
https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange

Minor style cleanup as well.
This commit is contained in:
Mark Lee 2014-05-20 13:53:02 -07:00
commit 144cddaf39
2 changed files with 26 additions and 24 deletions

View file

@ -465,17 +465,13 @@ def process_translations(content_list, order_by=None):
a.translations = [x for x in items if x != a]
if order_by:
if hasattr(order_by, '__call__'):
if callable(order_by):
try:
index.sort(key=order_by)
except:
if hasattr(order_by, 'func_name'):
logger.error("Error sorting with function %s" % order_by.func_name)
else:
logger.error("Error sorting with function %r" % order_by)
elif order_by == 'filename':
index.sort(key=lambda x:os.path.basename(
x.source_path or ''))
except Exception:
logger.error('Error sorting with function {}'.format(order_by))
elif order_by == 'basename':
index.sort(key=lambda x: os.path.basename(x.source_path or ''))
elif order_by != 'slug':
index.sort(key=attrgetter(order_by))