Skip to content

Commit 1f75324

Browse files
committed
chore: formatting
1 parent 23fddf9 commit 1f75324

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

invenio_rdm_records/proxies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
current_rdm_records_storage_service = LocalProxy(
4444
lambda: current_app.extensions["invenio-rdm-records"].storage_service
4545
)
46-
"""Helper proxy to get the current RDM-Records storage service."""
46+
"""Helper proxy to get the current RDM-Records storage service."""

invenio_rdm_records/services/storage/service.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
66
# it under the terms of the MIT License; see LICENSE file for more details.
77

8+
"""Storage Service."""
9+
810
import logging
11+
912
from flask import current_app
1013
from invenio_access.permissions import system_identity
1114
from invenio_search.engine import dsl
15+
1216
from invenio_rdm_records.records.models import RDMRecordQuota
1317

1418
logger = logging.getLogger(__name__)
1519

20+
1621
class StorageService:
1722
"""Service providing per-user storage quota information."""
1823

@@ -28,7 +33,10 @@ def default_quota(self):
2833
@property
2934
def max_additional_quota(self):
3035
"""Get the maximum additional quota allowed per user."""
31-
return current_app.config.get("RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE") or 150 * 10**9
36+
return (
37+
current_app.config.get("RDM_FILES_DEFAULT_MAX_ADDITIONAL_QUOTA_SIZE")
38+
or 150 * 10**9
39+
)
3240

3341
def _search_user_resources(self, user, drafts=False):
3442
"""Fetch user records or drafts."""
@@ -47,7 +55,9 @@ def _search_user_resources(self, user, drafts=False):
4755

4856
def _resolve_records_and_quotas(self, items, draft=False):
4957
"""Resolve search hits and fetch quotas."""
50-
cls = self.records_service.draft_cls if draft else self.records_service.record_cls
58+
cls = (
59+
self.records_service.draft_cls if draft else self.records_service.record_cls
60+
)
5161

5262
records = []
5363
parent_ids = set()
@@ -90,14 +100,16 @@ def _compute_usage(self, records, quotas):
90100
total_extra += extra_quota
91101
total_used += additional_used
92102

93-
results.append({
94-
"item": item,
95-
"record": record,
96-
"quota": quota,
97-
"used_bytes": used_bytes,
98-
"extra_quota": extra_quota,
99-
"additional_used": additional_used,
100-
})
103+
results.append(
104+
{
105+
"item": item,
106+
"record": record,
107+
"quota": quota,
108+
"used_bytes": used_bytes,
109+
"extra_quota": extra_quota,
110+
"additional_used": additional_used,
111+
}
112+
)
101113

102114
return results, total_extra, total_used
103115

@@ -115,8 +127,7 @@ def get_user_storage_usage(self, user, include_drafts=True):
115127
draft_data, extra_d, used_d = [], 0, 0
116128
if include_drafts:
117129
draft_data, extra_d, used_d = self._process_resources(
118-
self._search_user_resources(user, drafts=True),
119-
draft=True
130+
self._search_user_resources(user, drafts=True), draft=True
120131
)
121132

122133
return {

invenio_rdm_records/views.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from flask import Blueprint, abort, current_app, render_template
1616
from flask_login import current_user, login_required
1717
from invenio_records_resources.services.files.transfer import constants
18+
1819
from .proxies import current_rdm_records_storage_service
1920

2021
blueprint = Blueprint("invenio_rdm_records_ext", __name__)
@@ -120,6 +121,7 @@ def file_transfer_type():
120121

121122
return {"transfer_types": file_transfer_type_constants}
122123

124+
123125
def _format_storage(data):
124126
"""Format storage data for UI."""
125127
BYTES_TO_GB = 1e9
@@ -129,15 +131,19 @@ def _format_storage(data):
129131
item = e["item"]
130132
record = e["record"]
131133

132-
rows.append({
133-
"title": item.get("metadata", {}).get("title", "Empty title"),
134-
"url": item["links"]["self_html"],
135-
"additional_quota": round(e["extra_quota"] / BYTES_TO_GB, 1),
136-
"used": round(e["used_bytes"] / BYTES_TO_GB, 1),
137-
"total": round((data["default_quota"] + e["extra_quota"]) / BYTES_TO_GB, 1),
138-
"date": item.get("metadata", {}).get("publication_date", ""),
139-
"status": "Draft" if not record.is_published else "Published",
140-
})
134+
rows.append(
135+
{
136+
"title": item.get("metadata", {}).get("title", "Empty title"),
137+
"url": item["links"]["self_html"],
138+
"additional_quota": round(e["extra_quota"] / BYTES_TO_GB, 1),
139+
"used": round(e["used_bytes"] / BYTES_TO_GB, 1),
140+
"total": round(
141+
(data["default_quota"] + e["extra_quota"]) / BYTES_TO_GB, 1
142+
),
143+
"date": item.get("metadata", {}).get("publication_date", ""),
144+
"status": "Draft" if not record.is_published else "Published",
145+
}
146+
)
141147

142148
return {
143149
"default_quota": round(data["default_quota"] / BYTES_TO_GB, 1),
@@ -150,6 +156,7 @@ def _format_storage(data):
150156
"records": rows,
151157
}
152158

159+
153160
@blueprint.route("/account/settings/quota/", endpoint="storage_settings")
154161
@login_required
155162
def storage_settings():
@@ -164,4 +171,4 @@ def storage_settings():
164171
return render_template(
165172
"invenio_rdm_records/settings/storage.html",
166173
storage=storage,
167-
)
174+
)

0 commit comments

Comments
 (0)