Skip to content

models/users_db.py

models.users_db

User database

TobeVolunteerDB

Bases: DBBase

TobeVolunteer Collection

Source code in models/users_db.py
class TobeVolunteerDB(DBBase):  # pylint: disable=abstract-method
    ''' TobeVolunteer Collection '''

    def __init__(self) -> None:
        super().__init__('tobe_volunteer')

    def add(self, data: dict[str, Any]) -> None:
        ''' add

        Args:
            data (dict): The data to insert / update.

        '''
        self.find_one_and_update(
            {'_id': data['uid']},
            {'$set': data},
            upsert=True,
            return_document=ReturnDocument.AFTER,
        )

add

add(data: dict[str, Any]) -> None

add

Parameters:

Name Type Description Default
data dict

The data to insert / update.

required
Source code in models/users_db.py
def add(self, data: dict[str, Any]) -> None:
    ''' add

    Args:
        data (dict): The data to insert / update.

    '''
    self.find_one_and_update(
        {'_id': data['uid']},
        {'$set': data},
        upsert=True,
        return_document=ReturnDocument.AFTER,
    )

UsersDB

Bases: DBBase

UsersDB Collection

Source code in models/users_db.py
class UsersDB(DBBase):  # pylint: disable=abstract-method
    ''' UsersDB Collection '''

    def __init__(self) -> None:
        super().__init__('users')

    def index(self) -> None:
        ''' To make collection's index

        Indexs:
            - `mail`
            - `property.suspend`

        '''
        self.create_index([('mail', 1), ])
        self.create_index([('property.suspend', 1), ])

    @staticmethod
    def new(mail: str) -> dict[str, Any]:
        ''' New user account

        Args:
            mail (str): Mail address.

        Returns:
            Return the user base object and the `_id` it will be the user id.

        TODO:
            ``mail`` bind to login oauth account. Maybe need ``alias`` for
            some case like one user have more mail account to register.

        '''
        return {
            '_id': f'{uuid4().fields[0]:08x}',
            'mail': mail,
            'created_at': int(time()),
        }

    def add(self, data: dict[str, Any]) -> dict[str, Any]:
        ''' Add data

        Args:
            data (dict): The data to insert / update.

        Returns:
            Return the inserted / updated data.

        '''
        return self.find_one_and_update(
            {'_id': data['_id']},
            {'$set': data},
            upsert=True,
            return_document=ReturnDocument.AFTER,
        )

add

add(data: dict[str, Any]) -> dict[str, Any]

Add data

Parameters:

Name Type Description Default
data dict

The data to insert / update.

required

Returns:

Type Description
dict[str, Any]

Return the inserted / updated data.

Source code in models/users_db.py
def add(self, data: dict[str, Any]) -> dict[str, Any]:
    ''' Add data

    Args:
        data (dict): The data to insert / update.

    Returns:
        Return the inserted / updated data.

    '''
    return self.find_one_and_update(
        {'_id': data['_id']},
        {'$set': data},
        upsert=True,
        return_document=ReturnDocument.AFTER,
    )

index

index() -> None

To make collection's index

Indexs
  • mail
  • property.suspend
Source code in models/users_db.py
def index(self) -> None:
    ''' To make collection's index

    Indexs:
        - `mail`
        - `property.suspend`

    '''
    self.create_index([('mail', 1), ])
    self.create_index([('property.suspend', 1), ])

new staticmethod

new(mail: str) -> dict[str, Any]

New user account

Parameters:

Name Type Description Default
mail str

Mail address.

required

Returns:

Type Description
dict[str, Any]

Return the user base object and the _id it will be the user id.

TODO

mail bind to login oauth account. Maybe need alias for some case like one user have more mail account to register.

Source code in models/users_db.py
@staticmethod
def new(mail: str) -> dict[str, Any]:
    ''' New user account

    Args:
        mail (str): Mail address.

    Returns:
        Return the user base object and the `_id` it will be the user id.

    TODO:
        ``mail`` bind to login oauth account. Maybe need ``alias`` for
        some case like one user have more mail account to register.

    '''
    return {
        '_id': f'{uuid4().fields[0]:08x}',
        'mail': mail,
        'created_at': int(time()),
    }