Skip to content

Commit

Permalink
refactor!: reduce complexity reorder for
Browse files Browse the repository at this point in the history
fix C901 'update_user_data' is too complex (11)
  • Loading branch information
johanseto committed Jul 10, 2024
1 parent f7710cf commit 197409a
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions eox_nelp/user_profile/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,17 @@ def update_user_data(request):
# This extra code block is required since the method update_account_settings just
# allows to update fields defined in the AccountUserSerializer and the AccountLegacyProfileSerializer
# so some fields like first_name and last_name are not editable in the standad implementation.
extra_account_user_fields = getattr(settings, "EXTRA_ACCOUNT_USER_FIELDS", [])

if extra_account_user_fields:
for field, value in request.data.items():
if field in extra_account_user_fields and hasattr(request.user, field):
setattr(request.user, field, value)

request.user.save()

# This extra code block is required since the method update_account_settings just
# allows to update fields defined in the AccountUserSerializer and the AccountLegacyProfileSerializer
# so some fields related ExtraInfo are not editable in the standad implementation.

extra_account_user_fields = getattr(settings, "EXTRA_ACCOUNT_USER_FIELDS", [])
required_user_extra_info_fields = getattr(settings, 'REQUIRED_USER_EXTRA_INFO_FIELDS', [])
if required_user_extra_info_fields:
for field, value in request.data.items():
if field in required_user_extra_info_fields:
save_extrainfo_field(request.user, field, value)

for field, value in request.data.items():
if field in extra_account_user_fields and hasattr(request.user, field):
setattr(request.user, field, value)
request.user.save()
if field in required_user_extra_info_fields:
save_extrainfo_field(request.user, field, value)

except errors.AccountValidationError as err:
return Response({"field_errors": err.field_errors}, status=status.HTTP_400_BAD_REQUEST)
Expand Down

0 comments on commit 197409a

Please sign in to comment.