Made user services async
This commit is contained in:
parent
55fc73efe7
commit
864a7741e6
1 changed files with 11 additions and 11 deletions
|
@ -3,40 +3,40 @@ from django.contrib.auth.models import User
|
|||
from typing import Optional
|
||||
|
||||
|
||||
def create_user_information(user: User, *, display_name: Optional[str] = None) -> UserInformation:
|
||||
"""Create a UserInformation object for the given user.
|
||||
async def create_user_information(user: User, *, display_name: Optional[str] = None) -> UserInformation:
|
||||
"""Async. Create a UserInformation object for the given user.
|
||||
|
||||
@param user: The user to create the UserInformation object for.
|
||||
@param display_name: The display name for the user. If None, the user's username will be used.
|
||||
@return: The created UserInformation object.
|
||||
"""
|
||||
user_information = UserInformation.objects.create(user=user, display_name=user.username)
|
||||
user_information = await UserInformation.objects.acreate(user=user, display_name=user.username)
|
||||
|
||||
# Use the given display name if provided.
|
||||
if display_name is not None:
|
||||
user_information.display_name = display_name
|
||||
user_information.save()
|
||||
await user_information.asave()
|
||||
|
||||
return user_information
|
||||
|
||||
|
||||
def get_user_information(user: User) -> UserInformation:
|
||||
"""Get the UserInformation object for the given user.
|
||||
async def get_user_information(user: User) -> UserInformation:
|
||||
"""Async. Get the UserInformation object for the given user.
|
||||
|
||||
@param user: The user to get the UserInformation object for.
|
||||
@return: The UserInformation object for the given user.
|
||||
"""
|
||||
return UserInformation.objects.get(user)
|
||||
return await UserInformation.objects.aget(user)
|
||||
|
||||
|
||||
def set_user_display_name(user: User, display_name: Optional[str] = None) -> UserInformation:
|
||||
"""Set the display name for the given user.
|
||||
async def set_user_display_name(user: User, display_name: Optional[str] = None) -> UserInformation:
|
||||
"""Async. Set the display name for the given user.
|
||||
|
||||
@param user: The user to set the display name for.
|
||||
@param display_name: The display name to set for the user. If None, the user's username will be used.
|
||||
@return: The UserInformation object for the given user.
|
||||
"""
|
||||
user_information = UserInformation.objects.get(user)
|
||||
user_information = await UserInformation.objects.aget(user)
|
||||
|
||||
# Set the display name to the given display name, or the user's username if None.
|
||||
if display_name is not None:
|
||||
|
@ -44,5 +44,5 @@ def set_user_display_name(user: User, display_name: Optional[str] = None) -> Use
|
|||
else:
|
||||
user_information.display_name = user.username
|
||||
|
||||
user_information.save()
|
||||
await user_information.asave()
|
||||
return user_information
|
||||
|
|
Loading…
Reference in a new issue