From 9c05cb6af034882c15d16f07f5f7733e08b4c738 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sat, 23 Sep 2023 00:48:35 +0300 Subject: [PATCH] rotatable images & text --- core/views/uploads.py | 20 ++++++++++++++++++-- templates/renameform.html | 7 ++++++- templates/walletform.html | 26 +++++++++++++++----------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/core/views/uploads.py b/core/views/uploads.py index dd9f60daa..8bec24e26 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, }, diff --git a/templates/renameform.html b/templates/renameform.html index f543057fd..35bcbeb3f 100644 --- a/templates/renameform.html +++ b/templates/renameform.html @@ -37,15 +37,20 @@
+ {% if rotatable %}
{% csrf_token %}
- + {% else %} +

Not a rotatable image. + {% endif %}


Full urlencoded path for this file in expofiles is {{filepath|urlencode}} +

+ Return to wallet {{wallet}} diff --git a/templates/walletform.html b/templates/walletform.html index 84d47b2ad..aff70fead 100644 --- a/templates/walletform.html +++ b/templates/walletform.html @@ -15,6 +15,10 @@ {% else %}

Wallet {{wallet}}

{% endif %} +
{% csrf_token %} @@ -29,13 +33,13 @@

-{{prevy}} +{{prevy}}  ...  {{recent_year}}:{{recent_number}} ← {{wallet}} → {{year}}:{{next}}  ...  -{{nexty}} +{{nexty}}

@@ -58,10 +62,10 @@ {% endif %} -
Do NOT invent your own filenaming scheme.
Click for more details.
-
We have a 20-year old scheme for naming scanned files,

-Name the scanned pages "notes-cavepassagename.jpg" etc., (or notes-1.jpg if you must, but self-describing filenames are much better). This is important as a script detects whether these files exist (with names beginning "notes..", "plan.." and "elev..") and if you name them something else it will hassle you unnecessarily. (Or you can use this format cavepassagename5-notes.jpg if you like.) -Handbook: Creating a Wallet
+
Troggle needs standardised filenames. Use
"notes1-myhole.jpg", "notes2-myhole.jpg" etc. for in-cave notes,
"plan1-myhole.jpg" for the first page of the drawn up plan,
"elev3-myhole.jpg" for p3 of the drawn up elevation.

Click for more details.

+

Please do NOT invent your own filenaming scheme. We have a 20-year old scheme for naming scanned files,

+Name the scanned pages "notes-cavepassagename.jpg" etc., or notes-1.jpg if you like, but self-describing filenames are better. This is important as a script detects whether these files exist (with names beginning "notes..", "plan.." and "elev..") and if you name them something else it will hassle you unnecessarily. (Or you can use this format cavepassagename5-notes.jpg if you like.) See how this works in the Handbook: Creating a Wallet +

The 'plan..' and 'elev..' scans are for fully drawn-up Tunnel or Therion plans or elevations. If you have hand-sketches, then these are 'notes..' as are the raw survex survey data numbers.

{% if filesaved %} @@ -76,14 +80,14 @@ Handbook: Creating a Wallet {% for f in files %} - » {{ f}}
+ » {{ f}}   -  Rename or Rotate
{% empty %}

<No files in this wallet. > {% endfor %}

{% endif %} @@ -135,7 +139,7 @@ Handbook: Creating a Wallet {% if cave %}Cave ID: - {% if caveobject %}{{cave}} which implies "{{caveobject}}"
+ {% if caveobject %}{{cave}} which implies "{{caveobject}}"
{% else %} {{cave}}
{% endif %} @@ -143,7 +147,7 @@ Handbook: Creating a Wallet Survey area: {{psg}}
{% endif %} {% if svxfiles %}Survex files: {% for svx in svxfiles %} - {{svx}} + {{svx}} {% endfor %}
{% endif %} @@ -238,7 +242,7 @@ Handbook: Creating a Wallet
JSON
- {{metadataurl}}
+ {{metadataurl}}
     {{metadata}}