Skip to content

Commit

Permalink
fixed reading specific level sorting conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
KenjiTakahashi committed Apr 12, 2013
1 parent 125131f commit e48e5b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
- Global options stored in ~/.tdrc.
- Dropped colorama.
- Sorting by multiple conditions.

== 0.2.1 (12.04.2013):
- Fixed reading specifing level sorting conditions from .td/.tdrc files.
3 changes: 2 additions & 1 deletion td/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ def _modify(submodel, i):
_new.append(_mark(v, i) + [_modify(v[4], i + 1)])
else:
_new.append(_mark(v, i) + [_modify(v[4], i + 1)])
for index, reverse in sortLevels.get(i) or sortAll:
levels = sortLevels.get(i) or sortLevels.get(str(i))
for index, reverse in levels or sortAll:
_new = sorted(_new, key=lambda e: e[index], reverse=reverse)
return _new
return _modify(self.data, 1)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ def test_sort_second_level_by_name_and_priority(self):
["testname3", 5, "", False, []]
]

def test_sort_with_level_specified_as_string(self):
# JSON corner case
sort = ([], {"1": [(0, True)]})
result = self.model.modify(sort=sort)
assert result == [
["testname2", 3, "", False, []],
["testname1", 4, "", True, []]
]

def test_done_all_levels(self):
self.addSecondLevel()
done = ([(None, None, True)], {})
Expand Down

0 comments on commit e48e5b1

Please sign in to comment.