From 0488b129fc765d1ae16fa69888a7ea7179a76925 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 29 Dec 2023 10:38:27 +0000 Subject: [PATCH] Add user storage usage to modtools page --- app/template_filters.py | 8 ++++++++ app/templates/users/modtools.html | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/template_filters.py b/app/template_filters.py index 5e3dc99e..af170b0f 100644 --- a/app/template_filters.py +++ b/app/template_filters.py @@ -114,3 +114,11 @@ def last_it(it): for x in it: value = x return value + + +@app.template_filter() +def flatten(list): + ret = [] + for x in list: + ret.extend(x) + return ret diff --git a/app/templates/users/modtools.html b/app/templates/users/modtools.html index acf9db87..b19515f8 100644 --- a/app/templates/users/modtools.html +++ b/app/templates/users/modtools.html @@ -7,6 +7,23 @@ {% block pane %}

{{ _("Moderator Tools") }}

+ +

+ {{ _("Storage") }} +

+ +{% set all_releases = user.packages | map(attribute="releases") | flatten %} +{% set all_screenshots = user.packages | map(attribute="screenshots") | flatten %} +{% set release_size = ((all_releases | sum(attribute="file_size_bytes")) / 1048576) | round %} +{% set screenshot_size = ((all_screenshots | sum(attribute="file_size_bytes")) / 1048576) | round %} +

+ {{ _("Total storage usage is %(total_size)d MB (releases %(release_size)d MB, screenshots %(screenshot_size)d MB).", + release_size=release_size, screenshot_size=screenshot_size, total_size=release_size + screenshot_size) }} +
+ {{ _("%(releases)d releases and %(screenshots)d screenshots.", + releases=all_releases | length, screenshots=all_screenshots | length) }} +

+

{{ _("Edit Account") }}