mdrs-client-python/mdrsclient/models/folder.py

59 lines
1.4 KiB
Python
Raw Normal View History

2023-05-01 20:00:32 +09:00
from typing import Final
from pydantic.dataclasses import dataclass
2023-05-09 14:38:13 +09:00
from mdrsclient.models.file import File
2023-05-01 20:00:32 +09:00
from mdrsclient.models.utils import iso8601_to_user_friendly
ACCESS_LEVEL_NAMES: Final[dict[int, str]] = {
-1: "Storage",
0: "Private",
1: "CBS Open",
2: "PW Open",
3: "Public",
}
@dataclass(frozen=True)
class FolderSimple:
id: str
pid: str | None
name: str
access_level: int
lock: bool
lab_id: int
description: str
created_at: str
updated_at: str
restrict_opened_at: str | None
@property
def access_level_name(self) -> str:
return ACCESS_LEVEL_NAMES[self.access_level]
@property
def lock_name(self) -> str:
return "locked" if self.lock else "unlocked"
@property
def created_at_name(self) -> str:
return iso8601_to_user_friendly(self.created_at)
@property
def updated_at_name(self) -> str:
return iso8601_to_user_friendly(self.updated_at)
@dataclass(frozen=True)
class Folder(FolderSimple):
metadata: list[dict]
sub_folders: list[FolderSimple]
files: list[File]
path: str
def find_sub_folder(self, name: str) -> FolderSimple | None:
return next((x for x in self.sub_folders if x.name == name), None)
def find_file(self, name: str) -> File | None:
return next((x for x in self.files if x.name == name), None)