mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 19:20:05 -03:30
Merge pull request #282 from chrismeyersfsu/fix-cleanup_deleted
Replaced crafty logic that tried to detect the User but, wrongfully, …
This commit is contained in:
@@ -40,24 +40,24 @@ class Command(BaseCommand):
|
|||||||
yield submodel
|
yield submodel
|
||||||
|
|
||||||
def cleanup_model(self, model):
|
def cleanup_model(self, model):
|
||||||
name_field = None
|
|
||||||
|
'''
|
||||||
|
Presume the '_deleted_' string to be in the 'name' field unless considering the User model.
|
||||||
|
When considering the User model, presume the '_d_' string to be in the 'username' field.
|
||||||
|
'''
|
||||||
|
name_field = 'name'
|
||||||
|
name_prefix = '_deleted_'
|
||||||
|
if model is User:
|
||||||
|
name_field = 'username'
|
||||||
|
name_prefix = '_d_'
|
||||||
active_field = None
|
active_field = None
|
||||||
n_deleted_items = 0
|
n_deleted_items = 0
|
||||||
for field in model._meta.fields:
|
for field in model._meta.fields:
|
||||||
if field.name in ('name', 'username'):
|
|
||||||
name_field = field.name
|
|
||||||
if field.name in ('is_active', 'active'):
|
if field.name in ('is_active', 'active'):
|
||||||
active_field = field.name
|
active_field = field.name
|
||||||
if not name_field:
|
|
||||||
self.logger.warning('skipping model %s, no name field', model)
|
|
||||||
return n_deleted_items
|
|
||||||
if not active_field:
|
if not active_field:
|
||||||
self.logger.warning('skipping model %s, no active field', model)
|
self.logger.warning('skipping model %s, no active field', model)
|
||||||
return n_deleted_items
|
return n_deleted_items
|
||||||
if name_field == 'username' and active_field == 'is_active':
|
|
||||||
name_prefix = '_d_'
|
|
||||||
else:
|
|
||||||
name_prefix = '_deleted_'
|
|
||||||
qs = model.objects.filter(**{
|
qs = model.objects.filter(**{
|
||||||
active_field: False,
|
active_field: False,
|
||||||
'%s__startswith' % name_field: name_prefix,
|
'%s__startswith' % name_field: name_prefix,
|
||||||
|
|||||||
Reference in New Issue
Block a user