#NEWLINE# @ environmentfilter #NEWLINE# def do_sort( environment , value , reverse = False , case_sensitive = False , attribute = None ) : #NEWLINE# #INDENT# "Sort an iterable.  Per default it sorts ascending, if you pass it\n    true as first argument it will reverse the sorting.\n\n    If the iterable is made of strings the third parameter can be used to\n    control the case sensitiveness of the comparison which is disabled by\n    default.\n\n    .. sourcecode:: jinja\n\n        {% for item in iterable|sort %}\n            ...\n        {% endfor %}\n\n    It is also possible to sort by an attribute (for example to sort\n    by the date of an object) by specifying the `attribute` parameter:\n\n    .. sourcecode:: jinja\n\n        {% for item in iterable|sort(attribute='date') %}\n            ...\n        {% endfor %}\n\n    .. versionchanged:: 2.6\n       The `attribute` parameter was added.\n    " #NEWLINE# if ( not case_sensitive ) : #NEWLINE# #INDENT# def sort_func( item ) : #NEWLINE# #INDENT# if isinstance ( item , string_types ) : #NEWLINE# #INDENT# item = item . lower ( ) #NEWLINE# #UNINDENT# return item #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# sort_func = None #NEWLINE# #UNINDENT# if ( attribute is not None ) : #NEWLINE# #INDENT# getter = make_attrgetter ( environment , attribute ) #NEWLINE# def sort_func( item , processor = ( sort_func or ( lambda x : x ) ) ) : #NEWLINE# #INDENT# return processor ( getter ( item ) ) #NEWLINE# #UNINDENT# #UNINDENT# return sorted ( value , key = sort_func , reverse = reverse )