59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
from typing import Final
|
|
|
|
from pydantic.dataclasses import dataclass
|
|
|
|
from mdrsclient.models import File
|
|
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)
|