File size fixes
This commit is contained in:
parent
654a1e7191
commit
cb3b5a3c27
@ -66,9 +66,11 @@ class File(pydantic.BaseModel):
|
|||||||
|
|
||||||
def details(self, list: FileListWidget) -> QWidget:
|
def details(self, list: FileListWidget) -> QWidget:
|
||||||
del list
|
del list
|
||||||
|
file_size = self._format_bytes(self.file_size)
|
||||||
|
file_size_text = f"{file_size[0]:.2f} {file_size[1]}"
|
||||||
details = (
|
details = (
|
||||||
f"file id: {self.file_id}\nfile_name: {self.file_name}\n"
|
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}"
|
+ f"created at: {self.created_at}\nupdated at: {self.updated_at}"
|
||||||
)
|
)
|
||||||
label = QLabel()
|
label = QLabel()
|
||||||
@ -80,7 +82,7 @@ class File(pydantic.BaseModel):
|
|||||||
def _format_bytes(size: int):
|
def _format_bytes(size: int):
|
||||||
power = 2**10
|
power = 2**10
|
||||||
n = 0
|
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:
|
while size > power and n < 4:
|
||||||
size /= power
|
size /= power
|
||||||
n += 1
|
n += 1
|
||||||
|
Reference in New Issue
Block a user