mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 08:41:51 +00:00
Merge branch 'python3-new' of ssh://expo.survex.com/home/expo/troggle into python3-new
This commit is contained in:
commit
2f42f488ab
@ -12,6 +12,7 @@ from django.urls import reverse
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||
from django.urls import NoReverseMatch
|
||||
|
||||
import troggle.settings as settings
|
||||
from troggle.core.views import expo
|
||||
@ -235,11 +236,13 @@ def rendercave(request, cave, slug, cave_id=''):
|
||||
editable = False
|
||||
if not cave_id:
|
||||
cave_id = slug # cave.unofficial_number
|
||||
try:
|
||||
context = {'cave_editable': editable, 'settings': settings, 'cave': cave, 'cavepage': True,
|
||||
context = {'cave_editable': editable, 'settings': settings, 'cave': cave, 'cavepage': True,
|
||||
'cave_id': cave_id, 'svxstem': str(svxstem), 'svx3d':svx3d}
|
||||
r = render(request, templatefile, context) # crashes here if url not set up for 'edit_cave' in urls.py
|
||||
try:
|
||||
r = render(request, templatefile, context) # crashes here with NoReverseMatch if url not set up for 'edit_cave' in urls.py
|
||||
return r
|
||||
except NoReverseMatch:
|
||||
raise
|
||||
except:
|
||||
message = f'Failed to render cave: {slug}'
|
||||
return render(request,'errors/generic.html', {'message': message})
|
||||
@ -261,23 +264,27 @@ def cavepage(request, karea, subpath):
|
||||
|
||||
try:
|
||||
cave = Cave.objects.get(url = kpath) # ideally this will be unique
|
||||
# print(f" ! cavepage: url={kpath} -- {cave}")
|
||||
r = rendercave(request, cave, cave.slug())
|
||||
return r
|
||||
|
||||
except Cave.DoesNotExist:
|
||||
# probably a link to text or an image e.g. 1623/161/l/rl89a.htm i.e. an expoweb page
|
||||
# cannot assume that this is a simple cave page, for a cave we don't know.
|
||||
# print(f" ! cavepage: url={kpath} A cave of this name does not exist")
|
||||
return expo.expopage(request, kpath)
|
||||
except Cave.MultipleObjectsReturned:
|
||||
caves = Cave.objects.filter(url = kpath)
|
||||
# print(f" ! cavepage: url={kpath} multiple caves exist")
|
||||
# we should have a -several variant for the cave pages, not just the svxcaves:
|
||||
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves })
|
||||
|
||||
try:
|
||||
r = rendercave(request, cave, cave.slug())
|
||||
return r
|
||||
except NoReverseMatch:
|
||||
raise
|
||||
except:
|
||||
message = f'Failed to find cave: {kpath}'
|
||||
message = f'Failed to render cave: {kpath} (it does exist and is unique) because of a Django URL resolution error. Check urls.py.'
|
||||
return render(request,'errors/generic.html', {'message': message})
|
||||
|
||||
return rendercave(request, cave, cave.slug(), cave_id=cave_id)
|
||||
# return rendercave(request, cave, cave.slug(), cave_id=cave_id)
|
||||
|
||||
def caveEntrance(request, slug):
|
||||
try:
|
||||
|
@ -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
|
||||
'''
|
||||
|
@ -527,7 +527,7 @@ div#scene {
|
||||
<p><a href="https://aardgoose.github.io/CaveView.js/">CaveView</a> display of the .3d file is temporarily disabled while we fix things (Nov.2021). See <a href="/handbook/computing/todo.html">/handbook/computing/todo.html</a>.
|
||||
<a href="/survexfile">All survex files</a>
|
||||
<a href="{% if cave.kataster_number %}{% url "cave3d" cave.kataster_number %}{% else %}{% url "cave3d" cave.unofficial_number %}{% endif %}">3d file download</a>
|
||||
<a href="{% url "survexcavessingle" cave.kataster_number %}">This survex file</a>
|
||||
<a href="{% if cave.kataster_number %}{% url "survexcavessingle" cave.kataster_number %}">This survex file</a> {% endif %}">
|
||||
|
||||
<div id='scene'></div>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user