From a41fb9031f190b7b5463dfa2324f0ac2517e0f3e Mon Sep 17 00:00:00 2001 From: zhengxie Date: Mon, 23 Jun 2014 14:41:04 +0800 Subject: [PATCH] Fix notice email bug --- .../management/commands/send_notices.py | 8 ++++---- seahub/notifications/models.py | 16 ++++++++-------- .../templates/notifications/notice_email.html | 4 ++-- seahub/views/ajax.py | 12 ++++++++++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/seahub/notifications/management/commands/send_notices.py b/seahub/notifications/management/commands/send_notices.py index 5b9f402477..688f44887b 100644 --- a/seahub/notifications/management/commands/send_notices.py +++ b/seahub/notifications/management/commands/send_notices.py @@ -59,7 +59,7 @@ class Command(BaseCommand): notice.user_msg_from = escape(email2nickname(user_msg_from)) notice.user_msg_from_avatar_url = self.get_avatar_url(user_msg_from) - notice.user_msg_url = reverse('user_msg_list', args=[notice.detail]) + notice.user_msg_url = reverse('user_msg_list', args=[user_msg_from]) notice.user_msg = message return notice @@ -80,7 +80,7 @@ class Command(BaseCommand): def format_grpmsg_reply(self, notice): d = notice.grpmsg_reply_detail_to_dict() - message = d.get['reply_msg'] + message = d.get('reply_msg') notice.group_msg_reply_url = reverse('msg_reply_new') notice.group_msg_reply_from = escape(email2nickname(d['reply_from'])) @@ -133,8 +133,8 @@ class Command(BaseCommand): args=[username]) notice.grpjoin_group_url = reverse('group_members', args=[group_id]) notice.grpjoin_username = username - notice.grpjoin_group_name = group.group_name, - notice.grpjoin_request_msg = join_request_msg, + notice.grpjoin_group_name = group.group_name + notice.grpjoin_request_msg = join_request_msg return notice def do_action(self): diff --git a/seahub/notifications/models.py b/seahub/notifications/models.py index eba0b401c8..d5fd348439 100644 --- a/seahub/notifications/models.py +++ b/seahub/notifications/models.py @@ -416,9 +416,9 @@ class UserNotification(models.Model): def grpmsg_reply_detail_to_dict(self): """Parse group message reply detail, returns dict contains - ``msg_id`` and ``reply_from``. + ``msg_id``, ``reply_from`` and ``reply_msg``. - NOTE: ``reply_from`` may be ``None``. + NOTE: ``reply_from`` and ``reply_msg`` may be ``None``. Arguments: - `self`: @@ -435,15 +435,15 @@ class UserNotification(models.Model): if isinstance(detail, int): # Compatible with existing records msg_id = detail reply_from = None - return {'msg_id': msg_id, 'reply_from': reply_from} + reply_msg = None + return {'msg_id': msg_id, 'reply_from': reply_from, + 'reply_msg': reply_msg} elif isinstance(detail, dict): msg_id = detail['msg_id'] reply_from = detail['reply_from'] - if 'reply_msg' in detail: - reply_msg = detail['reply_msg'] - return {'msg_id': msg_id, 'reply_from': reply_from, 'reply_msg': reply_msg} - else: - return {'msg_id': msg_id, 'reply_from': reply_from} + reply_msg = detail.get('reply_msg') + return {'msg_id': msg_id, 'reply_from': reply_from, + 'reply_msg': reply_msg} else: raise self.InvalidDetailError, 'Wrong detail format of group message reply' diff --git a/seahub/notifications/templates/notifications/notice_email.html b/seahub/notifications/templates/notifications/notice_email.html index 282e42722e..73c841182c 100644 --- a/seahub/notifications/templates/notifications/notice_email.html +++ b/seahub/notifications/templates/notifications/notice_email.html @@ -5,7 +5,7 @@ {% block email_con %} {% autoescape off %} -

{% blocktrans with name=to_user|email2nickname %}Hi {{ name }},{% endblocktrans %}

+

{% blocktrans with name=to_user|email2nickname %}Hi, {{ name }}{% endblocktrans %}

{% blocktrans count num=notice_count %} @@ -30,7 +30,7 @@ You've got {{num}} new notices on {{ site_name }}: {% elif notice.is_grpmsg_reply %} - {% blocktrans with user=notice.group_msg_reply_from reply_url=notice.group_msg_reply_url%}{{user}} replied yourgroup discussion{% endblocktrans %} + {% blocktrans with user=notice.group_msg_reply_from reply_url=notice.group_msg_reply_url%}{{user}} replied your group discussion{% endblocktrans %} {{ notice.timestamp }} {% elif notice.is_repo_share_msg %} diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index 90fe0f0147..fea63c4099 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -1319,11 +1319,19 @@ def get_popup_notices(request): elif notice.is_group_msg(): d = notice.group_message_detail_to_dict() - notice.msg_from = d.get('msg_from') + if d.get('msg_from') is not None: + notice.msg_from = d.get('msg_from') + else: + from seahub.avatar.util import get_default_avatar_url + notice.default_avatar_url = get_default_avatar_url() elif notice.is_grpmsg_reply(): d = notice.grpmsg_reply_detail_to_dict() - notice.msg_from = d.get('reply_from') + if d.get('reply_from') is not None: + notice.msg_from = d.get('reply_from') + else: + from seahub.avatar.util import get_default_avatar_url + notice.default_avatar_url = get_default_avatar_url() elif notice.is_file_uploaded_msg(): from seahub.avatar.util import get_default_avatar_url