Skip to content

Commit

Permalink
'Solution'
Browse files Browse the repository at this point in the history
  • Loading branch information
kucherenkodmytro committed Dec 6, 2023
1 parent 8f5a31d commit f82a73c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions services/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from django.contrib.auth import get_user_model
from django.http import Http404
from django.shortcuts import get_object_or_404

from db.models import User
Expand Down Expand Up @@ -38,22 +39,22 @@ def update_user(
first_name: str = None,
last_name: str = None
) -> Union[User, None]:

user = get_user(user_id)

if username:
user.username = username
if password:
user.set_password(password)
if email:
user.email = email
if first_name:
user.first_name = first_name
if last_name:
user.last_name = last_name
try:
user = get_user(user_id)

if username:
user.username = username
if password:
user.set_password(password)
if email:
user.email = email
if first_name:
user.first_name = first_name
if last_name:
user.last_name = last_name

user.save()

return user

return None
except Http404:
return None

0 comments on commit f82a73c

Please sign in to comment.