summaryrefslogtreecommitdiffstats
path: root/core/views/expo.py
diff options
context:
space:
mode:
authorMartin Green <martin.speleo@gmail.com>2022-06-23 19:02:10 +0100
committerMartin Green <martin.speleo@gmail.com>2022-06-23 19:02:10 +0100
commit2f42f488abedd93f06074d9d28582b111777135e (patch)
tree06ce347088253fe8ac7f8375cae75c511ae70b11 /core/views/expo.py
parentf1e800d8bf4ff389cecc34f494e87604cd4fd7ac (diff)
parent16c6aed65fa65d0b13ff134d2be172ab0448a508 (diff)
downloadtroggle-2f42f488abedd93f06074d9d28582b111777135e.tar.gz
troggle-2f42f488abedd93f06074d9d28582b111777135e.tar.bz2
troggle-2f42f488abedd93f06074d9d28582b111777135e.zip
Merge branch 'python3-new' of ssh://expo.survex.com/home/expo/troggle into python3-new
Diffstat (limited to 'core/views/expo.py')
-rw-r--r--core/views/expo.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/core/views/expo.py b/core/views/expo.py
index 90ddeb9..d2a5d88 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -1,5 +1,8 @@
import os
import re
+
+from sys import getfilesystemencoding as sys_getfilesystemencoding
+
from pathlib import Path
from urllib.parse import urljoin, unquote as urlunquote
from urllib.request import urlopen
@@ -126,7 +129,12 @@ def expowebpage(request, expowebpath, path):
# Should not get here if the path has suffix "_edit"
print(f' - 404 error in expowebpage() {path}')
return render(request, 'pagenotfound.html', {'path': path}, status="404")
-
+
+ # print(f' - {sys_getfilesystemencoding()=}')
+ if (sys_getfilesystemencoding() != "utf-8"):
+ return HttpResponse(default_head + '<h3>UTF-8 Parsing Failure:<br>Default file encoding on this Troggle installation is not UTF-8:<br>failure detected in expowebpage in views.expo.py</h3> Please Please reconfigure Debian/Apache/Django to fix this, i.e. contact Wookey. </body' )
+
+ # This next bit can be drastically simplified now that we know that the system encoding actually is utf-8
try:
with open(expowebpath / path, "r", encoding='utf-8') as o:
html = o.read()
@@ -221,9 +229,13 @@ def expopage(request, path):
# do not redirect to a file path without the slash as we may get in a loop. Let the user fix it:
return render(request, 'dirnotfound.html', {'path': path, 'subpath': path[0:-1]})
- # So it must be a file in /expoweb/ but not .htm or .html probably an image
+ # So it must be a file in /expoweb/ but not .htm or .html probably an image, maybe a txt file
filetobeopened = expowebpath / path
-
+
+ # print(f' - {sys_getfilesystemencoding()=}')
+ if (sys_getfilesystemencoding() != "utf-8"):
+ return HttpResponse(default_head + '<h3>UTF-8 Parsing Failure:<br>Default file encoding on this Troggle installation is not UTF-8:<br>failure detected in expowebpage in views.expo.py</h3> Please Please reconfigure Debian/Apache/Django to fix this, i.e. contact Wookey. </body' )
+
try:
content = open(filetobeopened, "rb")
content_type=getmimetype(path)
@@ -279,6 +291,10 @@ def editexpopage(request, path):
except Cave.DoesNotExist:
pass
+ print(f' - {sys_getfilesystemencoding()=}')
+ if (sys_getfilesystemencoding() != "utf-8"):
+ return HttpResponse(default_head + '<h3>UTF-8 Parsing Failure:<br>Default file encoding on this Troggle installation is not UTF-8:<br>failure detected in expowebpage in views.expo.py</h3> Please Please reconfigure Debian/Apache/Django to fix this, i.e. contact Wookey. </body' )
+
try:
filepath = Path(settings.EXPOWEB) / path
o = open(filepath, "r", encoding="utf8")
@@ -350,8 +366,6 @@ def editexpopage(request, path):
pageform = ExpoPageForm({"html": body, "title": "Missing"})
return render(request, 'editexpopage.html', {'path': path, 'form': pageform, })
-
-
class ExpoPageForm(forms.Form):
'''The form used by the editexpopage function
'''