mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 06:32: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
|
@classmethod
|
||||||
def mass_archive(cls, users_list):
|
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)
|
cls.mass_unassign_ips(users_list)
|
||||||
users_list.update(state=User.STATE_ARCHIVE)
|
users_list.update(state=User.STATE_ARCHIVE)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mass_full_archive(cls, users_list):
|
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_unassign_ips(users_list)
|
||||||
cls.mass_delete_data(users_list)
|
cls.mass_delete_data(users_list)
|
||||||
users_list.update(state=User.STATE_FULL_ARCHIVE)
|
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)
|
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:
|
if not full_archive:
|
||||||
to_archive_list = to_archive_list.exclude(state=User.STATE_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 "valider" in request.POST:
|
||||||
if full_archive:
|
if full_archive:
|
||||||
User.mass_full_archive(to_archive_list)
|
User.mass_full_archive(to_archive_list)
|
||||||
else:
|
else:
|
||||||
User.mass_archive(to_archive_list)
|
User.mass_archive(to_archive_list)
|
||||||
messages.success(request, _("%s users were archived.") %
|
messages.success(request, _("%s users were archived.") %
|
||||||
number_to_archive
|
to_archive_list.count()
|
||||||
)
|
)
|
||||||
return redirect(reverse('users:index'))
|
return redirect(reverse('users:index'))
|
||||||
to_archive_list = re2o_paginator(request, to_archive_list, pagination_number)
|
to_archive_list = re2o_paginator(request, to_archive_list, pagination_number)
|
||||||
|
|
Loading…
Reference in a new issue