diff --git a/seahub/base/accounts.py b/seahub/base/accounts.py index 10d2f9aaf8..0966bb9ef8 100644 --- a/seahub/base/accounts.py +++ b/seahub/base/accounts.py @@ -278,11 +278,17 @@ class User(object): @property def contact_email(self): if not hasattr(self, '_cached_contact_email'): - email = Profile.objects.get_contact_email_by_user(self.username) - self._cached_contact_email = email + self._cached_contact_email = email2contact_email(self.username) return self._cached_contact_email + @property + def name(self): + if not hasattr(self, '_cached_nickname'): + self._cached_nickname = email2nickname(self.username) + + return self._cached_nickname + class DoesNotExist(Exception): pass @@ -842,3 +848,7 @@ class DetailedRegistrationForm(RegistrationForm): note = forms.CharField(widget=forms.TextInput( attrs=dict(attrs_dict, maxlength=100)), label=_("note"), required=note_required) + +# Move here to avoid circular import +from seahub.base.templatetags.seahub_tags import email2nickname, \ + email2contact_email diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index 78ccbd4c9f..892cc1275a 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -32,7 +32,8 @@ from seahub.base.accounts import User from seahub.base.models import UserLastLogin from seahub.base.decorators import sys_staff_required, require_POST from seahub.base.sudo_mode import update_sudo_mode_ts -from seahub.base.templatetags.seahub_tags import tsstr_sec, email2nickname +from seahub.base.templatetags.seahub_tags import tsstr_sec, email2nickname, \ + email2contact_email from seahub.auth import authenticate from seahub.auth.decorators import login_required, login_required_ajax from seahub.constants import GUEST_USER, DEFAULT_USER, DEFAULT_ADMIN, \ @@ -226,13 +227,8 @@ def can_view_sys_admin_repo(repo): def populate_user_info(user): """Populate contact email and name to user. """ - user_profile = Profile.objects.get_profile_by_user(user.email) - if user_profile: - user.contact_email = user_profile.contact_email - user.name = user_profile.nickname - else: - user.contact_email = '' - user.name = '' + user.contact_email = email2contact_email(user.email) + user.name = email2nickname(user.email) def _populate_user_quota_usage(user): """Populate space/share quota to user.