Skip to content

fl_server_core.models.user

Classes:

Name Description
NotificationReceiver

Notification receiver base class.

User

User class.

Functions:

Name Description
create_auth_token

Ensure that an authentication token is created for every new user.

Classes

NotificationReceiver

Notification receiver base class.

Attributes:

Name Type Description
id UUID

Unique identifier for the notification receiver.

message_endpoint str

Endpoint to send the message to.

Source code in fl_server_core/models/user.py
class NotificationReceiver():
    """
    Notification receiver base class.
    """

    id: UUID
    """Unique identifier for the notification receiver."""
    message_endpoint: str
    """Endpoint to send the message to."""

Attributes

id instance-attribute
id: UUID

Unique identifier for the notification receiver.

message_endpoint instance-attribute
message_endpoint: str

Endpoint to send the message to.

User

Bases: AbstractUser, NotificationReceiver


              flowchart TD
              fl_server_core.models.user.User[User]
              fl_server_core.models.user.NotificationReceiver[NotificationReceiver]

                              fl_server_core.models.user.NotificationReceiver --> fl_server_core.models.user.User
                


              click fl_server_core.models.user.User href "" "fl_server_core.models.user.User"
              click fl_server_core.models.user.NotificationReceiver href "" "fl_server_core.models.user.NotificationReceiver"
            

User class.

Inherits from Django's AbstractUser and NotificationReceiver.

Attributes:

Name Type Description
actor BooleanField

Flag indicating whether the user is an actor.

client BooleanField

Flag indicating whether the user is a client.

id UUIDField

Unique identifier for the user.

message_endpoint URLField

Endpoint to send the message to.

Source code in fl_server_core/models/user.py
class User(AbstractUser, NotificationReceiver):
    """
    User class.

    Inherits from Django's AbstractUser and NotificationReceiver.
    """

    id: UUIDField = UUIDField(primary_key=True, editable=False, default=uuid4)
    """Unique identifier for the user."""
    actor: BooleanField = BooleanField(default=False)
    """Flag indicating whether the user is an actor."""
    client: BooleanField = BooleanField(default=False)
    """Flag indicating whether the user is a client."""
    message_endpoint: URLField = URLField()
    """Endpoint to send the message to."""

Attributes

actor class-attribute instance-attribute
actor: BooleanField = BooleanField(default=False)

Flag indicating whether the user is an actor.

client class-attribute instance-attribute
client: BooleanField = BooleanField(default=False)

Flag indicating whether the user is a client.

id class-attribute instance-attribute
id: UUIDField = UUIDField(primary_key=True, editable=False, default=uuid4)

Unique identifier for the user.

message_endpoint class-attribute instance-attribute
message_endpoint: URLField = URLField()

Endpoint to send the message to.

Functions

create_auth_token

create_auth_token(sender, instance=None, created=False, *args, **kwargs)

Ensure that an authentication token is created for every new user.

Parameters:

Name Type Description Default

sender

The model class.

required

instance

User

The actual instance being saved. Defaults to None.

None

created

bool

A boolean; True if a new record was created. Defaults to False.

False

*args

Additional arguments.

()

**kwargs

Arbitrary keyword arguments.

{}
Source code in fl_server_core/models/user.py
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, *args, **kwargs):
    """
    Ensure that an authentication token is created for every new user.

    Args:
        sender: The model class.
        instance (User, optional): The actual instance being saved. Defaults to None.
        created (bool, optional): A boolean; True if a new record was created. Defaults to False.
        *args: Additional arguments.
        **kwargs: Arbitrary keyword arguments.
    """
    if created:
        Token.objects.create(user=instance)