From 16570c746ecfa4fe5b4ab3ef0db79c2168ed2bbe Mon Sep 17 00:00:00 2001 From: plt Date: Sat, 30 Mar 2013 10:26:49 +0800 Subject: [PATCH] Add discuss module to public group, do not show email in user profile --- base/accounts.py | 3 +- base/templatetags/seahub_tags.py | 23 +++- group/templates/group/group_discuss.html | 6 +- ...anonymous.html => group_info_for_pub.html} | 0 group/views.py | 100 +++++++++--------- profile/settings.py | 3 + profile/templates/profile/user_profile.html | 23 ++-- profile/urls.py | 2 +- profile/views.py | 31 +++--- 9 files changed, 110 insertions(+), 81 deletions(-) rename group/templates/group/{group_info_for_anonymous.html => group_info_for_pub.html} (100%) diff --git a/base/accounts.py b/base/accounts.py index 7aca6c1459..d443c80b66 100644 --- a/base/accounts.py +++ b/base/accounts.py @@ -14,7 +14,7 @@ from registration import signals from seaserv import ccnet_threaded_rpc, unset_repo_passwd, is_passwd_set from profile.models import Profile -from seahub.utils import get_user_repos + UNUSABLE_PASSWORD = '!' # This will never be a valid hash @@ -155,6 +155,7 @@ class User(object): """ Remove all repo decryption passwords stored on server. """ + from seahub.utils import get_user_repos owned_repos, shared_repos, groups_repos, public_repos = get_user_repos(self) def has_repo(repos, repo): diff --git a/base/templatetags/seahub_tags.py b/base/templatetags/seahub_tags.py index 4ca40e89d7..968df5523c 100644 --- a/base/templatetags/seahub_tags.py +++ b/base/templatetags/seahub_tags.py @@ -14,10 +14,12 @@ from django.utils.translation import ungettext from django.utils.translation import pgettext from profile.models import Profile -from profile.settings import NICKNAME_CACHE_TIMEOUT, NICKNAME_CACHE_PREFIX +from profile.settings import NICKNAME_CACHE_TIMEOUT, NICKNAME_CACHE_PREFIX, \ + EMAIL_ID_CACHE_TIMEOUT, EMAIL_ID_CACHE_PREFIX from seahub.cconvert import CConvert from seahub.po import TRANSLATION_MAP from seahub.shortcuts import get_first_object_or_none +from base.accounts import User register = template.Library() @@ -227,6 +229,25 @@ def email2nickname(value): nickname = profile.nickname if profile else value.split('@')[0] cache.set(NICKNAME_CACHE_PREFIX+value, nickname, NICKNAME_CACHE_TIMEOUT) return nickname + +@register.filter(name='email2id') +def email2id(value): + """ + Return the user id of an email or -1. + """ + if not value: + return -1 + + user_id = cache.get(EMAIL_ID_CACHE_PREFIX+value) + if not user_id: + try: + user = User.objects.get(email=value) + user_id = user.id + except User.DoesNotExist: + user_id = -1 + cache.set(EMAIL_ID_CACHE_PREFIX+value, user_id, EMAIL_ID_CACHE_TIMEOUT) + return user_id + @register.filter(name='url_target_blank') def url_target_blank(text): diff --git a/group/templates/group/group_discuss.html b/group/templates/group/group_discuss.html index 888a40cf59..1666dc7470 100644 --- a/group/templates/group/group_discuss.html +++ b/group/templates/group/group_discuss.html @@ -30,7 +30,7 @@