only save() user if there are changes
This commit is contained in:
parent
1544032ac9
commit
de7997f1b1
|
@ -64,15 +64,29 @@ class Command(BaseCommand):
|
|||
account = OIDCAccount.objects.get(user__email=user_dict['email'])
|
||||
except OIDCAccount.DoesNotExist:
|
||||
continue
|
||||
had_changes = False
|
||||
for claim in cut_users.claim_mappings.all():
|
||||
if '{{' in claim.claim or '{%' in claim.claim:
|
||||
template = Template(claim.claim)
|
||||
attribute_value = template.render(context=user_dict)
|
||||
else:
|
||||
attribute_value = user_dict.get(claim.claim)
|
||||
try:
|
||||
old_attribute_value = getattr(account.user, claim.attribute)
|
||||
except AttributeError:
|
||||
try:
|
||||
old_attribute_value = getattr(account.user.attributes, claim.attribute)
|
||||
except AttributeError:
|
||||
old_attribute_value = None
|
||||
if old_attribute_value == attribute_value:
|
||||
continue
|
||||
had_changes = True
|
||||
setattr(account.user, claim.attribute, attribute_value)
|
||||
try:
|
||||
setattr(account.user.attributes, claim.attribute, attribute_value)
|
||||
except AttributeError:
|
||||
pass
|
||||
account.user.save()
|
||||
if had_changes:
|
||||
if verbose:
|
||||
print('had changes, saving %r' % account.user)
|
||||
account.user.save()
|
||||
|
|
Reference in New Issue