summaryrefslogtreecommitdiffstats
path: root/core/views/uploads.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-09-23 00:48:35 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2023-09-23 00:48:35 +0300
commit9c05cb6af034882c15d16f07f5f7733e08b4c738 (patch)
tree17e424b85243d7e84d9c72bb99e74bdf8ef5bf55 /core/views/uploads.py
parent017f916ef922bd11b1e745ccc4fa4bccd843f1d4 (diff)
downloadtroggle-9c05cb6af034882c15d16f07f5f7733e08b4c738.tar.gz
troggle-9c05cb6af034882c15d16f07f5f7733e08b4c738.tar.bz2
troggle-9c05cb6af034882c15d16f07f5f7733e08b4c738.zip
rotatable images & text
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r--core/views/uploads.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index dd9f60d..8bec24e 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -406,6 +406,16 @@ def expofilerename(request, filepath):
Currently this just does files within wallets i.e. in /surveyscans/
and it returns control to the original wallet edit page
"""
+ def is_rotatable(path):
+ """If file is a JPG but has no filename extension, then it must be renamed
+ before it can be rotated.
+ """
+ print(f"{path}: '{Path(path).suffix.lower()}'")
+ if Path(path).suffix.lower() in [".png", ".jpg", ".jpeg"]:
+ return True
+ else:
+ return False
+
def rotate_image():
wallet = str(Path(filepath).parent).lstrip("surveyscans/")
cwd = settings.SCANS_ROOT / wallet
@@ -455,7 +465,9 @@ def expofilerename(request, filepath):
"filesize": filesize,
"files": files,
"walletpath": walletpath,
+ "wallet": wallet,
"notpics": notpics,
+ "rotatable": rotatable,
},
)
@@ -474,8 +486,11 @@ def expofilerename(request, filepath):
else:
filename = Path(filepath).name
walletpath = Path(filepath).parent
+ wallet = Path(walletpath).name
folder = actualpath.parent
filesize = f"{actualpath.stat().st_size:,}"
+ rotatable= is_rotatable(filename)
+
if not actualpath.is_relative_to(Path(settings.SCANS_ROOT)):
message = f'\n Can only do rename within wallets (expofiles/surveyscans/) currently, sorry. "{actualpath}" '
@@ -494,10 +509,10 @@ def expofilerename(request, filepath):
for d in f.iterdir():
dirs.append(f"{f.name}/{d.name}")
if f.is_file():
- if Path(f.name).suffix.lower() in [".jpg", ".jpeg", ".png"]:
+ if is_rotatable(f.name): # should allow all images here which can be thumsized, not just rotatables. e.g. PDF
files.append(f.name)
else:
- notpics.append(f.name)
+ notpics.append(f.name)
except FileNotFoundError:
files.append(
"(Error. There should be at least one filename visible here. Try refresh.)"
@@ -537,6 +552,7 @@ def expofilerename(request, filepath):
"filesize": filesize,
"files": files,
"walletpath": walletpath,
+ "wallet": wallet,
"notpics": notpics,
"rename_bad": rename_bad,
},