mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 22:52:26 +00:00
Avoid lazy eval problems with django queryset
This commit is contained in:
parent
9053a752b1
commit
6e569566ed
2 changed files with 11 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue