From db3d1ff4ef924ae104de53a533dc5a02d4069ea7 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 14 Sep 2023 14:15:16 +0300 Subject: [PATCH] ROTATE image option --- core/views/uploads.py | 33 ++++++++++++++++++++++++++++++++- settings.py | 4 ++++ templates/renameform.html | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/core/views/uploads.py b/core/views/uploads.py index 655738f..9fd9d44 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -407,7 +407,37 @@ def expofilerename(request, filepath): and it returns control to the original wallet edit page """ def rotate_image(): - print("ROTATE") + wallet = str(Path(filepath).parent).lstrip("surveyscans/") + cwd = settings.SCANS_ROOT / wallet + print(f"ROTATE \n{cwd=} \n{filename=}") + mogrify = settings.MOGRIFY + rot = subprocess.run( + [mogrify, "-rotate", "90", filename], cwd=cwd, capture_output=True, text=True + ) + msgdata = ( + rot.stderr + + "\n" + + rot.stdout + + "\nreturn code: " + + str(rot.returncode) + ) + message = f'! - ROTATE - Success: rotated this file {filename}.' + msgdata + print(message) + if rot.returncode != 0: + msgdata = ( + "Ask a nerd to fix this.\n\n" + + rot.stderr + + "\n\n" + + rot.stdout + + "\n\nreturn code: " + + str(rot.returncode) + ) + message = ( + f"! - ROTATE - CANNOT blurk for this file {filename}. \n" + + msgdata + ) + print(message) + return simple_get() def simple_get(): @@ -427,6 +457,7 @@ def expofilerename(request, filepath): ) if filepath: + # using EXPOFILES not SCANS_ROOT in case we want to extend this to other parts of the system actualpath = Path(settings.EXPOFILES) / Path(filepath) else: message = f'\n File to rename not specified "{filepath}"' diff --git a/settings.py b/settings.py index e428b9c..80a1de2 100644 --- a/settings.py +++ b/settings.py @@ -31,7 +31,11 @@ EPOCH = date.fromisoformat('1970-01-01') # default value, then gets overwritten by real secrets SECRET_KEY = "not-the-real-secret-key-a#vaeozn0---^fj!355qki*vj2" +# executables: GIT = "git" # command for running git +CAVERN = "cavern" # for parsing .svx files and producing .3d files +SURVEXPORT = "survexport" # for parsing .3d files and producing .pos files +MOGRIFY = "mogrify" # for rotating images # Note that this builds upon the django system installed # global settings in diff --git a/templates/renameform.html b/templates/renameform.html index aae489b..1217968 100644 --- a/templates/renameform.html +++ b/templates/renameform.html @@ -1,10 +1,10 @@ {% extends "base.html" %} -{% block title %}File rename form{% endblock %} +{% block title %}File rename or rotate form{% endblock %} {% block content %} -

Renaming "{{filename}}"

+

Renaming or Rotating "{{filename}}"

@@ -23,26 +23,49 @@ {% csrf_token %}
+ for="renametoname">type in the new name for this file



- +
+
+ {% csrf_token %} + +



- Full urlencoded path for this file in expofiles is
{{filepath|urlencode}} + Full urlencoded path for this file in expofiles is {{filepath|urlencode}}
-
+{% for np in notpics %} + {{np}}
+{% endfor %} +
+{% for filename in files %} + +
+ +
{{filename}} +
+
+ +{% empty %} +No files found.
+{% endfor %} + {% endblock %} \ No newline at end of file