Skip to content

Commit 9bd9f85

Browse files
committed
SXDEDPCXZIC-426 / fix dtv_exceeds_max_size_limit func
1 parent ded93a6 commit 9bd9f85

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

ckanext/datavic_odp_theme/helpers.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def format_list() -> list[str]:
4747
)
4848

4949
formats = [
50-
resource.format.upper().split('.')[-1] for resource in query if resource.format
50+
resource.format.upper().split(".")[-1] for resource in query if resource.format
5151
]
5252
unique_formats = set(formats)
5353

@@ -99,15 +99,15 @@ def get_package_release_date(pkg_dict: dict[str, Any]) -> str:
9999
@helper
100100
def featured_resource_preview(package: dict[str, Any]) -> Optional[dict[str, Any]]:
101101
"""Return a featured resource preview
102-
- It takes only CSV resources with an existing preview
103-
- Only resources uploaded to datastore
104-
- Only not historical resources
102+
- It takes only CSV resources with an existing preview
103+
- Only resources uploaded to datastore
104+
- Only not historical resources
105105
"""
106106

107107
featured_preview = None
108108

109-
resource_groups: list[list[dict[str, Any]]] = toolkit.h.group_resources_by_temporal_range(
110-
package.get("resources", [])
109+
resource_groups: list[list[dict[str, Any]]] = (
110+
toolkit.h.group_resources_by_temporal_range(package.get("resources", []))
111111
)
112112

113113
resources = resource_groups[0] if resource_groups else []
@@ -223,7 +223,15 @@ def dtv_exceeds_max_size_limit(resource_id: str) -> bool:
223223

224224
limit = conf.get_dtv_max_size_limit()
225225
filesize = resource.get("filesize")
226-
if filesize and filesize.isdigit() and int(filesize) >= int(limit):
226+
227+
if not filesize:
228+
return False
229+
230+
file_size_int = (
231+
int(filesize) if isinstance(filesize, str) and filesize.isdigit() else filesize
232+
)
233+
234+
if isinstance(file_size_int, (int, float)) and file_size_int >= int(limit):
227235
return True
228236

229237
return False
@@ -272,17 +280,12 @@ def datavic_datastore_dictionary(resource_id: str, resource_view_id: str):
272280
"""
273281
try:
274282
resource_view = toolkit.get_action("resource_view_show")(
275-
{},
276-
{"id": resource_view_id}
283+
{}, {"id": resource_view_id}
277284
)
278285
headers = [
279-
f for f in toolkit.get_action("datastore_search")(
280-
{},
281-
{
282-
"resource_id": resource_id,
283-
"limit": 0,
284-
"include_total": False
285-
}
286+
f
287+
for f in toolkit.get_action("datastore_search")(
288+
{}, {"resource_id": resource_id, "limit": 0, "include_total": False}
286289
)["fields"]
287290
if not f["id"].startswith("_")
288291
]
@@ -303,15 +306,19 @@ def datavic_update_org_error_dict(
303306
"""Internal CKAN logic makes a validation for resource file size. We want
304307
to show it as an error on the Logo field."""
305308
if error_dict.pop("upload", "") == ["File upload too large"]:
306-
error_dict["Logo"] = [(
307-
f"File size is too large. Select an image which is no larger than {datavic_max_image_size()}MB."
308-
)]
309+
error_dict["Logo"] = [
310+
(
311+
f"File size is too large. Select an image which is no larger than {datavic_max_image_size()}MB."
312+
)
313+
]
309314
elif "Unsupported upload type" in error_dict.pop("image_upload", [""])[0]:
310-
error_dict["Logo"] = [(
311-
"Image format is not supported. "
312-
"Select an image in one of the following formats: "
313-
"JPG, JPEG, GIF, PNG, WEBP."
314-
)]
315+
error_dict["Logo"] = [
316+
(
317+
"Image format is not supported. "
318+
"Select an image in one of the following formats: "
319+
"JPG, JPEG, GIF, PNG, WEBP."
320+
)
321+
]
315322

316323
return error_dict
317324

0 commit comments

Comments
 (0)