added docstrings

This commit is contained in:
Corban-Lee Jones 2024-03-20 09:13:03 +00:00
parent 20945e0003
commit 7ec74e1055
3 changed files with 39 additions and 1 deletions

View File

@ -2,6 +2,7 @@
import logging
from django.http import HttpResponse
from django.contrib.auth.backends import BaseBackend
from .models import DiscordUser
@ -17,10 +18,23 @@ class DiscordAuthenticationBackend(BaseBackend):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def authenticate(self, request, discord_user_data: dict) -> DiscordUser:
def authenticate(self, request: HttpResponse, discord_user_data: dict) -> DiscordUser:
"""
Creates or finds an existing user, and returns it.
"Authenticate" may not be the best name for this method...
Parameters
----------
request : django.http.HttpResponse
The HTTP request object.
discord_user_data : dict
A dictionary containing the raw user data.
Returns
-------
DiscordUser
The newly created or existing instance of DiscordUser,
based on the provided `discord_user_data`.
"""
log.debug(discord_user_data)
@ -41,6 +55,16 @@ class DiscordAuthenticationBackend(BaseBackend):
"""
Fetch a user from their ID.
Returns NoneType if not found.
Parameters
----------
user_id : int
The identifier for the discord user.
Returns
-------
DiscordUser | None
Either the DiscordUser or None if not found.
"""
try:

View File

@ -15,6 +15,16 @@ class DiscordUserOAuth2Manager(BaseUserManager):
def create_user(self, discord_user_data: dict, **extra_fields):
"""
Create a user from their discord data.
Parameters
----------
discord_user_data : dict
The raw discord user data
Returns
-------
DiscordUser
The newly created DiscordUser instance.
"""
username = discord_user_data.get("username")

View File

@ -135,6 +135,10 @@ class Subscription(models.Model):
)
class Meta:
"""
Metadata for the Subscription Model.
"""
verbose_name = "subscription"
verbose_name_plural = "subscriptions"
get_latest_by = "-creation_datetime"