mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 10:58:33 +00:00
admin export users to excel
Optimize database query when get user's name and contact email
This commit is contained in:
@@ -296,13 +296,28 @@ def sys_useradmin_export_excel(request):
|
|||||||
_("Space Usage") + "(MB)", _("Space Quota") + "(MB)",
|
_("Space Usage") + "(MB)", _("Space Quota") + "(MB)",
|
||||||
_("Create At"), _("Last Login"), _("Admin"), _("LDAP(imported)"),]
|
_("Create At"), _("Last Login"), _("Admin"), _("LDAP(imported)"),]
|
||||||
|
|
||||||
|
# only operate 100 users for every `for` loop
|
||||||
|
looped = 0
|
||||||
|
limit = 100
|
||||||
data_list = []
|
data_list = []
|
||||||
|
|
||||||
last_logins = UserLastLogin.objects.filter(username__in=[x.email for x in users])
|
while looped < len(users):
|
||||||
for user in users:
|
|
||||||
|
|
||||||
|
current_users = users[looped:looped+limit]
|
||||||
|
|
||||||
|
last_logins = UserLastLogin.objects.filter(username__in=[x.email \
|
||||||
|
for x in current_users])
|
||||||
|
user_profiles = Profile.objects.filter(user__in=[x.email \
|
||||||
|
for x in current_users])
|
||||||
|
|
||||||
|
for user in current_users:
|
||||||
# populate name and contact email
|
# populate name and contact email
|
||||||
populate_user_info(user)
|
user.contact_email = ''
|
||||||
|
user.name = ''
|
||||||
|
for profile in user_profiles:
|
||||||
|
if profile.user == user.email:
|
||||||
|
user.contact_email = profile.contact_email
|
||||||
|
user.name = profile.nickname
|
||||||
|
|
||||||
# populate space usage and quota
|
# populate space usage and quota
|
||||||
MB = get_file_size_unit('MB')
|
MB = get_file_size_unit('MB')
|
||||||
@@ -365,6 +380,9 @@ def sys_useradmin_export_excel(request):
|
|||||||
|
|
||||||
data_list.append(row)
|
data_list.append(row)
|
||||||
|
|
||||||
|
# update `looped` value when `for` loop finished
|
||||||
|
looped += limit
|
||||||
|
|
||||||
wb = write_xls('users', head, data_list)
|
wb = write_xls('users', head, data_list)
|
||||||
if not wb:
|
if not wb:
|
||||||
messages.error(request, _(u'Failed to export Excel'))
|
messages.error(request, _(u'Failed to export Excel'))
|
||||||
|
Reference in New Issue
Block a user