From 701f5631f04d0420456bd47f864fc238b624ed82 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Fri, 23 Mar 2012 18:47:46 +0100 Subject: Use int() on the identifier and return nothing if there is nothing to return --- lib/mongo.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/mongo.py') diff --git a/lib/mongo.py b/lib/mongo.py index c3f2fab..0c4c71e 100644 --- a/lib/mongo.py +++ b/lib/mongo.py @@ -42,7 +42,7 @@ def _tree_to_list(tree, mailid, level, thread_list): def get_thread_list(table, threadid): db = connection[table] - thread = list(db.mails.find({'ThreadID': threadid}, + thread = list(db.mails.find({'ThreadID': int(threadid)}, sort=[('Date', pymongo.ASCENDING)])) tree = _build_thread(thread) @@ -55,9 +55,12 @@ def get_thread_list(table, threadid): def get_thread_name(table, threadid): db = connection[table] - thread = list(db.mails.find({'ThreadID': threadid}, - sort=[('Date', pymongo.ASCENDING)]))[0] - return thread['Subject'] + thread = list(db.mails.find({'ThreadID': int(threadid)}, + sort=[('Date', pymongo.ASCENDING)])) + if thread: + return thread[0]['Subject'] + else: + return '' def get_emails_thread(table, start_email, thread): db = connection[table] -- cgit