~sloecode/sloecode/1.0

« back to all changes in this revision

Viewing changes to sloecode/lib/filters.py

  • Committer: Thomi Richards
  • Date: 2012-03-04 04:35:48 UTC
  • mfrom: (109.1.36 trunk)
  • Revision ID: thomi.richards@canonical.com-20120304043548-xlo68ox0cckxeph1
Merged from trunk, in preparation with 1.1 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Custom filters for Jinja2 templates
 
2
"""
 
3
 
 
4
 
 
5
from operator import attrgetter, methodcaller
 
6
 
 
7
 
 
8
def do_attrsort(objs, attr):
 
9
    return sorted(objs, key=attrgetter(attr))
 
10
 
 
11
def do_methodsort(objs, method):
 
12
    return sorted(objs, key=methodcaller(method))
 
13
 
 
14
 
 
15
FILTERS = {
 
16
    'attrsort':   do_attrsort,
 
17
    'methodsort': do_methodsort,
 
18
}
 
19