From e48ae64576fd75f1a0a4d15f02a3905e7ddacb6b Mon Sep 17 00:00:00 2001 From: zhengxie Date: Mon, 8 Aug 2016 18:19:00 +0800 Subject: [PATCH] [inst] Update user table --- .../templates/institutions/useradmin.html | 7 +++-- .../institutions/useradmin_search.html | 7 +++-- seahub/institutions/views.py | 4 ++- seahub/views/sysadmin.py | 29 +++++++++---------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/seahub/institutions/templates/institutions/useradmin.html b/seahub/institutions/templates/institutions/useradmin.html index 5d5a86eac9..733bf8d8d7 100644 --- a/seahub/institutions/templates/institutions/useradmin.html +++ b/seahub/institutions/templates/institutions/useradmin.html @@ -13,7 +13,7 @@ {% if users %} - + @@ -22,7 +22,10 @@ {% for user in users %} -
{% trans "Email" %}{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %} {% trans "Status" %} {% trans "Space Used" %} {% trans "Create At / Last Login" %}
{{ user.email }} + + {{ user.email }} + {% if user.name %}
{{ user.name }}{% endif %} + {% if user.contact_email %}
{{ user.contact_email }}{% endif %}
diff --git a/seahub/institutions/templates/institutions/useradmin_search.html b/seahub/institutions/templates/institutions/useradmin_search.html index b58038f51f..0bae96a935 100644 --- a/seahub/institutions/templates/institutions/useradmin_search.html +++ b/seahub/institutions/templates/institutions/useradmin_search.html @@ -15,7 +15,7 @@ {% if users %} - + @@ -24,7 +24,10 @@ {% for user in users %} -
{% trans "Email" %}{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %} {% trans "Status" %} {% trans "Space Used" %} {% trans "Create At / Last Login" %}
{{ user.email }} + + {{ user.email }} + {% if user.name %}
{{ user.name }}{% endif %} + {% if user.contact_email %}
{{ user.contact_email }}{% endif %}
diff --git a/seahub/institutions/views.py b/seahub/institutions/views.py index 4870850886..b0662fb741 100644 --- a/seahub/institutions/views.py +++ b/seahub/institutions/views.py @@ -21,7 +21,7 @@ from seahub.institutions.decorators import (inst_admin_required, from seahub.profile.models import Profile, DetailedProfile from seahub.utils import is_valid_username, clear_token from seahub.utils.rpc import mute_seafile_api -from seahub.views.sysadmin import email_user_on_activation +from seahub.views.sysadmin import email_user_on_activation, populate_user_info logger = logging.getLogger(__name__) @@ -75,6 +75,7 @@ def useradmin(request): if u.username == request.user.username: u.is_self = True + populate_user_info(u) _populate_user_quota_usage(u) for e in last_logins: @@ -110,6 +111,7 @@ def useradmin_search(request): if u.username == request.user.username: u.is_self = True + populate_user_info(u) _populate_user_quota_usage(u) for e in last_logins: diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index fb32a07080..c6d4f9f5e2 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -112,6 +112,17 @@ def can_view_sys_admin_repo(repo): else: return False +def populate_user_info(user): + """Populate contact email and nickname 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 = '' + def _populate_user_quota_usage(user): """Populate space/share quota to user. @@ -190,17 +201,10 @@ def sys_user_admin(request): else: trial_users = [] for user in users: - 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 = '' - if user.email == request.user.email: user.is_self = True + populate_user_info(user) _populate_user_quota_usage(user) # check user's role @@ -1458,16 +1462,9 @@ def user_search(request): else: trial_users = [] for user in users: + populate_user_info(user) _populate_user_quota_usage(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 = '' - # check user's role if user.role == GUEST_USER: user.is_guest = True