Commit 6e569566 authored by detraz's avatar detraz

Avoid lazy eval problems with django queryset

parent 9053a752
......@@ -591,11 +591,21 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
@classmethod
def mass_archive(cls, users_list):
"""Mass Archive several users, take a queryset
Copy Queryset to avoid eval problem with queryset update"""
#Force eval of queryset
bool(users_list)
users_list = users_list.all()
cls.mass_unassign_ips(users_list)
users_list.update(state=User.STATE_ARCHIVE)
@classmethod
def mass_full_archive(cls, users_list):
"""Mass Archive several users, take a queryset
Copy Queryset to avoid eval problem with queryset update"""
#Force eval of queryset
bool(users_list)
users_list = users_list.all()
cls.mass_unassign_ips(users_list)
cls.mass_delete_data(users_list)
users_list.update(state=User.STATE_FULL_ARCHIVE)
......
......@@ -785,14 +785,13 @@ def mass_archive(request):
to_archive_list = User.objects.exclude(id__in=all_has_access()).exclude(id__in=all_has_access(search_time=date)).exclude(state=User.STATE_NOT_YET_ACTIVE).exclude(state=User.STATE_FULL_ARCHIVE)
if not full_archive:
to_archive_list = to_archive_list.exclude(state=User.STATE_ARCHIVE)
number_to_archive = to_archive_list.count()
if "valider" in request.POST:
if full_archive:
User.mass_full_archive(to_archive_list)
else:
User.mass_archive(to_archive_list)
messages.success(request, _("%s users were archived.") %
number_to_archive
to_archive_list.count()
)
return redirect(reverse('users:index'))
to_archive_list = re2o_paginator(request, to_archive_list, pagination_number)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment