add file size to list view
This commit is contained in:
parent
b828c6f442
commit
f72ab30173
3 changed files with 25 additions and 2 deletions
|
|
@ -1,6 +1,17 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import configparser
|
import configparser
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def get_human_readable_filesize(num_bytes):
|
||||||
|
"""Return a human readable string of 'num_bytes'."""
|
||||||
|
print(num_bytes)
|
||||||
|
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
|
||||||
|
if abs(num_bytes) < 1024.0:
|
||||||
|
return f"{num_bytes:3.1f} {unit}B"
|
||||||
|
num_bytes /= 1024.0
|
||||||
|
return f"{num_bytes:.1f} YiB"
|
||||||
|
|
||||||
|
|
||||||
class RaincloudIOException(Exception):
|
class RaincloudIOException(Exception):
|
||||||
|
|
@ -65,7 +76,13 @@ class DirectoryHandler:
|
||||||
files = []
|
files = []
|
||||||
for p in file_paths:
|
for p in file_paths:
|
||||||
if p.name != "rc.conf":
|
if p.name != "rc.conf":
|
||||||
files.append(p.name)
|
print(p)
|
||||||
|
files.append(
|
||||||
|
{
|
||||||
|
"name": p.name,
|
||||||
|
"size": get_human_readable_filesize(os.path.getsize(p)),
|
||||||
|
}
|
||||||
|
)
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def get_absolute_path(self, directory):
|
def get_absolute_path(self, directory):
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,12 @@ body {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.file-size {
|
||||||
|
color: lightgrey;
|
||||||
|
font-size: 12px;
|
||||||
|
padding-left: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
form {
|
form {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% for f in files %}
|
{% for f in files %}
|
||||||
<div class="file">
|
<div class="file">
|
||||||
<p>{{ f }}</p>
|
<p>{{ f["name"] }}<span class="file-size">{{ f["size"] }}</span></p>
|
||||||
{% if config["download"] %}
|
{% if config["download"] %}
|
||||||
<a href="{{ config["directory"] }}/{{ f }}" class="button">Download</a>
|
<a href="{{ config["directory"] }}/{{ f }}" class="button">Download</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue