diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-12-14 19:14:20 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-12-14 19:14:20 +0100 |
commit | a132cf2b84bd250514c33e6393e9d9ef31b0b7c9 (patch) | |
tree | 31e2b5d32df22d45a8e052c274cbea7992de17ce /hyperkitty/lib | |
parent | 90d3f91df7851b97f07b903f353497742f80d325 (diff) | |
download | hyperkitty-a132cf2b84bd250514c33e6393e9d9ef31b0b7c9.tar.gz hyperkitty-a132cf2b84bd250514c33e6393e9d9ef31b0b7c9.tar.xz hyperkitty-a132cf2b84bd250514c33e6393e9d9ef31b0b7c9.zip |
Sort replies by thread, with indentation
Diffstat (limited to 'hyperkitty/lib')
-rw-r--r-- | hyperkitty/lib/__init__.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py index 52b6bdc..14bde15 100644 --- a/hyperkitty/lib/__init__.py +++ b/hyperkitty/lib/__init__.py @@ -23,6 +23,7 @@ import urllib from hashlib import md5 import datetime +import networkx as nx from django.conf import settings @@ -86,3 +87,23 @@ def get_display_dates(year, month, day): end_date = begin_date + datetime.timedelta(days=1) return begin_date, end_date + + +def sort_thread(thread): + def walk_successors(msgid, level, result): + obj = graph.node[msgid]["obj"] + obj.level = level + result.append(obj) + level += 1 + for succ in sorted(graph.successors(msgid), + key=lambda m: graph.node[m]["num"]): + walk_successors(succ, level, result) + level -= 1 + graph = nx.DiGraph() + for index, email in enumerate(thread.emails): + graph.add_node(email.message_id, num=index, obj=email) + if email.in_reply_to is not None: + graph.add_edge(email.in_reply_to, email.message_id) + result = [] + walk_successors(thread.starting_email.message_id, 0, result) + return result |