summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/views/expo.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/core/views/expo.py b/core/views/expo.py
index 66dffd0..6256aab 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -1,6 +1,9 @@
import os
import re
import subprocess
+
+from sys import getfilesystemencoding as sys_getfilesystemencoding
+
from pathlib import Path
from urllib.parse import urljoin, unquote as urlunquote
from urllib.request import urlopen
@@ -125,7 +128,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()
@@ -220,9 +228,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)
@@ -278,6 +290,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")
@@ -361,7 +377,7 @@ def write_and_commit(filepath, content):
cwd = filepath.parent
filename = filepath.name
git = settings.GIT
- # GIT see also core/models/cave.py writetrogglefile()
+ # GIT see also core/models/caves.py writetrogglefile()
# GIT see also core/views/uploads.py dwgupload()
try: