File size fixes

This commit is contained in:
StNicolay 2024-08-09 20:44:44 +03:00
parent 654a1e7191
commit cb3b5a3c27
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D

View File

@ -66,9 +66,11 @@ class File(pydantic.BaseModel):
def details(self, list: FileListWidget) -> QWidget:
del list
file_size = self._format_bytes(self.file_size)
file_size_text = f"{file_size[0]:.2f} {file_size[1]}"
details = (
f"file id: {self.file_id}\nfile_name: {self.file_name}\n"
+ f"file_size: {self._format_bytes(self.file_size)}\n"
+ f"file_size: {file_size_text}\n"
+ f"created at: {self.created_at}\nupdated at: {self.updated_at}"
)
label = QLabel()
@ -80,7 +82,7 @@ class File(pydantic.BaseModel):
def _format_bytes(size: int):
power = 2**10
n = 0
power_labels = {0: "", 1: "kilo", 2: "mega", 3: "giga", 4: "tera"}
power_labels = {0: "", 1: "kibi", 2: "mebi", 3: "gibi", 4: "tebi"}
while size > power and n < 4:
size /= power
n += 1