mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
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:
parent
bf6a4ad747
commit
144cddaf39
2 changed files with 26 additions and 24 deletions
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue