From 6737e0395c4952aa3678a8308df819a37e9217f0 Mon Sep 17 00:00:00 2001 From: zhengxie Date: Mon, 28 Apr 2014 13:52:13 +0800 Subject: [PATCH] [api] refactor group_msg_to_json --- seahub/api2/utils.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index a09a097fb1..3ff0b8ade8 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -311,25 +311,21 @@ def get_timestamp(msgtimestamp): def group_msg_to_json(msg, get_all_replies): ret = { - 'from_email' : msg.from_email, - 'nickname' : email2nickname(msg.from_email), - 'timestamp' : get_timestamp(msg.timestamp), - 'msg' : msg.message, - 'msgid' : msg.id, + 'from_email': msg.from_email, + 'nickname': email2nickname(msg.from_email), + 'timestamp': get_timestamp(msg.timestamp), + 'msg': msg.message, + 'msgid': msg.id, } - try: - atts = MessageAttachment.objects.filter(group_message_id=msg.id) - except MessageAttachment.DoesNotExist: - atts = [] - atts_json = [] + atts = MessageAttachment.objects.filter(group_message_id=msg.id) for att in atts: att_json = { - 'path' : att.path, - 'repo' : att.repo_id, - 'type' : att.attach_type, - 'src' : att.src, + 'path': att.path, + 'repo': att.repo_id, + 'type': att.attach_type, + 'src': att.src, } atts_json.append(att_json) if len(atts_json) > 0: