summaryrefslogtreecommitdiffstats
path: root/core/views/expo.py
diff options
context:
space:
mode:
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
'''