Skip to content

module/project.py

module.project

Project

Project

Project module

Source code in module/project.py
class Project:
    ''' Project module '''
    @staticmethod
    def create(pid: str, name: str, owners: list[str], action_date: str) -> dict[str, Any]:
        ''' Create project

        Args:
            pid (str): Project id.
            name (str): Project name.
            owners (list): List of owner's uids.
            action_date: The date at the event first date.

        Returns:
            Return the added data.

        '''
        projectdb = ProjectDB(pid)

        data = projectdb.default()
        data['name'] = name
        data['owners'].extend(owners)
        data['action_date'] = arrow.get(action_date).timestamp()

        return projectdb.add(data)

    @staticmethod
    def all() -> Cursor[dict[str, Any]]:
        ''' List all project

        Returns:
            Return all projects and order by `action_date`(desc).

        '''
        return ProjectDB(pid='').find({}, sort=(('action_date', -1), ))

    @staticmethod
    def get(pid: str) -> Optional[dict[str, Any]]:
        ''' Get project info

        Args:
            pid (str): Project id.

        Returns:
            Return the project info.

        '''
        return ProjectDB(pid).find_one({'_id': pid})

    @staticmethod
    def update(pid: str, data: dict[str, Any]) -> None:
        ''' update data

        Args:
            pid (str): Project id.
            data (dict): The data to update. These fields can be updated:
                         `name`, `desc`, `volunteer_certificate_hours`, `calendar`,
                         `mailling_staff`, `mailling_leader`, `shared_drive`,
                         `mattermost_ch_id`, `traffic_fee_doc`, `gitlab_project_id`,
                         `parking_card`.

        '''
        _data = {}
        for k in ('name', 'desc', 'volunteer_certificate_hours', 'calendar',
                  'mailling_staff', 'mailling_leader', 'shared_drive', 'mattermost_ch_id',
                  'traffic_fee_doc', 'gitlab_project_id', 'parking_card'):
            if k in data:
                _data[k] = data[k]

                if isinstance(_data[k], str):
                    _data[k] = _data[k].strip()

        if 'volunteer_certificate_hours' in _data:
            _data['volunteer_certificate_hours'] = int(
                _data['volunteer_certificate_hours'])

        ProjectDB(pid).find_one_and_update({'_id': pid}, {'$set': _data})

all staticmethod

all() -> Cursor[dict[str, Any]]

List all project

Returns:

Type Description
Cursor[dict[str, Any]]

Return all projects and order by action_date(desc).

Source code in module/project.py
@staticmethod
def all() -> Cursor[dict[str, Any]]:
    ''' List all project

    Returns:
        Return all projects and order by `action_date`(desc).

    '''
    return ProjectDB(pid='').find({}, sort=(('action_date', -1), ))

create staticmethod

create(
    pid: str, name: str, owners: list[str], action_date: str
) -> dict[str, Any]

Create project

Parameters:

Name Type Description Default
pid str

Project id.

required
name str

Project name.

required
owners list

List of owner's uids.

required
action_date str

The date at the event first date.

required

Returns:

Type Description
dict[str, Any]

Return the added data.

Source code in module/project.py
@staticmethod
def create(pid: str, name: str, owners: list[str], action_date: str) -> dict[str, Any]:
    ''' Create project

    Args:
        pid (str): Project id.
        name (str): Project name.
        owners (list): List of owner's uids.
        action_date: The date at the event first date.

    Returns:
        Return the added data.

    '''
    projectdb = ProjectDB(pid)

    data = projectdb.default()
    data['name'] = name
    data['owners'].extend(owners)
    data['action_date'] = arrow.get(action_date).timestamp()

    return projectdb.add(data)

get staticmethod

get(pid: str) -> Optional[dict[str, Any]]

Get project info

Parameters:

Name Type Description Default
pid str

Project id.

required

Returns:

Type Description
Optional[dict[str, Any]]

Return the project info.

Source code in module/project.py
@staticmethod
def get(pid: str) -> Optional[dict[str, Any]]:
    ''' Get project info

    Args:
        pid (str): Project id.

    Returns:
        Return the project info.

    '''
    return ProjectDB(pid).find_one({'_id': pid})

update staticmethod

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

update data

Parameters:

Name Type Description Default
pid str

Project id.

required
data dict

The data to update. These fields can be updated: name, desc, volunteer_certificate_hours, calendar, mailling_staff, mailling_leader, shared_drive, mattermost_ch_id, traffic_fee_doc, gitlab_project_id, parking_card.

required
Source code in module/project.py
@staticmethod
def update(pid: str, data: dict[str, Any]) -> None:
    ''' update data

    Args:
        pid (str): Project id.
        data (dict): The data to update. These fields can be updated:
                     `name`, `desc`, `volunteer_certificate_hours`, `calendar`,
                     `mailling_staff`, `mailling_leader`, `shared_drive`,
                     `mattermost_ch_id`, `traffic_fee_doc`, `gitlab_project_id`,
                     `parking_card`.

    '''
    _data = {}
    for k in ('name', 'desc', 'volunteer_certificate_hours', 'calendar',
              'mailling_staff', 'mailling_leader', 'shared_drive', 'mattermost_ch_id',
              'traffic_fee_doc', 'gitlab_project_id', 'parking_card'):
        if k in data:
            _data[k] = data[k]

            if isinstance(_data[k], str):
                _data[k] = _data[k].strip()

    if 'volunteer_certificate_hours' in _data:
        _data['volunteer_certificate_hours'] = int(
            _data['volunteer_certificate_hours'])

    ProjectDB(pid).find_one_and_update({'_id': pid}, {'$set': _data})