Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
1c11a56f
Commit
1c11a56f
authored
Nov 24, 2016
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move sort algorithm outside class
parent
97b83c84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
topydo/lib/Sorter.py
topydo/lib/Sorter.py
+13
-10
No files found.
topydo/lib/Sorter.py
View file @
1c11a56f
...
...
@@ -71,6 +71,16 @@ def get_field_function(p_field):
return
result
def
_apply_sort_functions
(
p_todos
,
p_functions
):
sorted_todos
=
p_todos
for
function
,
order
in
reversed
(
p_functions
):
sorted_todos
=
sorted
(
sorted_todos
,
key
=
function
,
reverse
=
(
order
==
'desc'
))
return
sorted_todos
class
Sorter
(
object
):
"""
This class sorts a todo list.
...
...
@@ -109,21 +119,14 @@ class Sorter(object):
sort operation is done first, relying on the stability of the sorted()
function.
"""
sorted_todos
=
p_todos
for
function
,
order
in
reversed
(
self
.
sortfunctions
):
sorted_todos
=
sorted
(
sorted_todos
,
key
=
function
,
reverse
=
(
order
==
'desc'
))
return
sorted_todos
return
_apply_sort_functions
(
p_todos
,
self
.
sortfunctions
)
def
group
(
self
,
p_todos
):
"""
Groups the todos according to the given group string. Assumes that the
given todos have already been sorted with self.sort().
Groups the todos according to the given group string.
"""
# preorder todos for the group sort
for
function
,
_
in
self
.
groupfunctions
:
p_todos
=
sorted
(
p_todos
,
key
=
function
)
p_todos
=
_apply_sort_functions
(
p_todos
,
self
.
groupfunctions
)
# initialize result with a single group
result
=
OrderedDict
([((),
p_todos
)])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment