diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index 4af5fa0..64dda9b 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -158,14 +158,30 @@ class PageTests(TestCase): self.assertEqual(len(response.content), 6057) def test_cave_kataster_not_found(self): - # database not loaded, so no caves found - response = self.client.get('/cave/115') - self.assertEqual(response.status_code, 200) + # database not loaded, so no caves found; so looks for a generic expopage and fails + response = self.client.get('/1623/115.htm') + self.assertEqual(response.status_code, 404) content = response.content.decode() - ph = r"Cave Identifier not found in database" + ph = r"Page not found 1623/115.htm" phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + def test_caves_page(self): + response = self.client.get('/caves') + self.assertEqual(response.status_code, 200) + content = response.content.decode() + ph = r"Cave Number Index - kept updated" + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + + def test_caves_page_kataster_not_found(self): + response = self.client.get('/caves') + self.assertEqual(response.status_code, 200) + content = response.content.decode() + ph = r"115" + phmatch = re.search(ph, content) + self.assertIsNone(phmatch, "Failed to find expected text: '" + ph +"'") + def test_page_ss(self): response = self.client.get('/survey_scans/') self.assertEqual(response.status_code, 200) diff --git a/core/TESTS/tests_caves.py b/core/TESTS/tests_caves.py index 13152f7..dd8f1df 100644 --- a/core/TESTS/tests_caves.py +++ b/core/TESTS/tests_caves.py @@ -37,7 +37,7 @@ class FixtureTests(TestCase): def test_fix_cave_loaded115(self): c = Cave.objects.get(kataster_number='115') self.assertEqual(str(c.description_file), "1623/115.htm") - self.assertEqual(str(c.url), "1623/115.htm") + self.assertEqual(str(c.url), "1623/115.url") # intentional self.assertEqual(str(c.filename), "1623-115.html") # c.area is a 'ManyRelatedManager' object and not iterable @@ -135,7 +135,7 @@ class FixturePageTests(TestCase): def test_fix_cave_url115(self): ph = self.ph - response = self.client.get('/1623/115.htm') + response = self.client.get('/1623/115.url') # yes this is intentional, see the inserted data above & fixture self.assertEqual(response.status_code, 200) content = response.content.decode() diff --git a/core/fixtures/expo_caves.json b/core/fixtures/expo_caves.json index ff9ff79..d2728f7 100644 --- a/core/fixtures/expo_caves.json +++ b/core/fixtures/expo_caves.json @@ -14,7 +14,7 @@ "notes": "The Austrian Kataster has adopted a very perverse way of numbering things. Their numbers are as follows:
", "length": "SMK system total 54000m", "depth": "from entrance; SMK system total 1032m", "extent": "SMK system total 2812m", "survex_file": "smk-system.svx", "description_file": "1623/115.htm", - "url": "1623/115.htm", + "url": "1623/115.url", "filename": "1623-115.html", "area": [1, 8]}}, diff --git a/core/views/caves.py b/core/views/caves.py index 4956004..9e40c51 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -211,17 +211,21 @@ def rendercave(request, cave, slug, cave_id=''): '''Gets the data and files ready and then triggers Django to render the template. The resulting html contains urls which are dispatched independently, e.g. the 'download' link ''' - #print(" ! rendercave:'{}' slug:'{}' cave_id:'{}'".format(cave, slug, cave_id)) + # print(" ! rendercave:'{}' START slug:'{}' cave_id:'{}'".format(cave, slug, cave_id)) if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated: return render(request, 'nonpublic.html', {'instance': cave, 'cavepage': True, 'cave_id': cave_id}) else: - svxstem = Path(cave.survex_file).parent / Path(cave.survex_file).stem - svx3d = Path(cave.survex_file).stem - + # print(f" ! rendercave: slug:'{slug}' survex file:'{cave.survex_file}'") + try: + svx3d = Path(cave.survex_file).stem + svxstem = Path(settings.SURVEX_DATA) / Path(cave.survex_file) + # print(f" ! rendercave: slug:'{slug}' '' ++ '{svxstem}'") + except: + print(f" ! rendercave: slug:'{slug}' FAIL TO MANAGE survex file:'{cave.survex_file}'") # NOTE the template itself loads the 3d file using javascript before it loads anything else. # Django cannot see what this javascript is doing, so we need to ensure that the 3d file exists first. - # So only do this render if a valid .3d file exists. TO BE DONE + # So only do this render if a valid .3d file exists. TO BE DONE -Not yet as CaveView is currently disabled # see design docum in troggle/templates/cave.html # see rendercave() in troggle/core/views/caves.py templatefile = 'cave.html' @@ -229,40 +233,47 @@ def rendercave(request, cave, slug, cave_id=''): editable = True else: editable = False - #print(f" ! rendercave:'{cave}' using template '{templatefile}' svxstem:'{svxstem}' caveid:'{cave_id}' svx3d:'{svx3d}'") if not cave_id: cave_id = slug # cave.unofficial_number try: - r = render(request,templatefile, {'cave_editable': editable, 'settings': settings, 'cave': cave, 'cavepage': True, - 'cave_id': cave_id, 'svxstem': svxstem, 'svx3d':svx3d}) + 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 return r except: - raise - + message = f'Failed to render cave: {slug}' + return render(request,'errors/generic.html', {'message': message}) def cavepage(request, karea, subpath): '''Displays a cave description page accessed by kataster area number specifically + OR + accessed by cave.url specifically set in data, e.g. + "1623/000/000.html" <= cave-data/1623-000.html + "1623/41/115.htm" <= cave-data/1623-115.html + so we have to query the database to fine the URL as we cannot rely on the url actually telling us the cave by inspection. There are A LOT OF URLS to e.g. /1623/161/l/rl89a.htm which are IMAGES and html files in cave descriptions. These need to be handled HERE ''' - path = karea + subpath - #print(" ! cavepage:'{}' kataster area:'{}' rest of path:'{}'".format(path, karea, subpath)) + kpath = karea + subpath + # print(f" ! cavepage:'{kpath}' kataster area:'{karea}' rest of path:'{subpath}'") try: - cave = Cave.objects.get(url = path) # ideally this will be unique - return rendercave(request, cave, cave.slug()) + 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 - return expo.expopage(request, path) + return expo.expopage(request, str(kpath)) except Cave.MultipleObjectsReturned: - caves = Cave.objects.filter(url = path) + caves = Cave.objects.filter(url = kpath) # we should have a -several variant for the cave pages, not just the svxcaves: return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves }) except: - message = f'Failed to find cave: {path}' + message = f'Failed to find cave: {kpath}' return render(request,'errors/generic.html', {'message': message}) def cave(request, cave_id='', offical_name=''): @@ -292,27 +303,16 @@ def caveEntrance(request, slug): else: return render(request,'cave_entrances.html', {'cave': cave}) -def caveDescription(request, slug): - try: - cave = Cave.objects.get(caveslug__slug = slug) - except: - return render(request,'errors/badslug.html', {'badslug': slug}) +# def caveDescription(request, slug): + # try: + # cave = Cave.objects.get(caveslug__slug = slug) + # except: + # return render(request,'errors/badslug.html', {'badslug': slug}) - if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated: - return render(request,'nonpublic.html', {'instance': cave}) - else: - return render(request,'cave_uground_description.html', {'cave': cave}) - -def caveQMs(request, slug): - try: - cave = Cave.objects.get(caveslug__slug = slug) - except: - return render(request,'errors/badslug.html', {'badslug': slug}) - - if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated: - return render(request,'nonpublic.html', {'instance': cave}) - else: - return render(request,'cave_qms.html', {'cave': cave}) + # if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated: + # return render(request,'nonpublic.html', {'instance': cave}) + # else: + # return render(request,'cave_uground_description.html', {'cave': cave}) @login_required_if_public def edit_cave(request, slug=None): @@ -456,21 +456,6 @@ def edit_entrance(request, caveslug=None, slug=None): 'entletter': entletter }) -def qm(request,cave_id,qm_id,year,grade=None): - year=int(year) - try: - qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year) - return render(request,'qm.html',locals()) - except Cave.MultipleObjectsReturned: # entirely the wrong action, REPLACE with the right display - caves = Cave.objects.filter(kataster_number=cave_id) - return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves }) - - except QM.DoesNotExist: - url=urllib.parse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id) - if grade: - url += r'&grade=' + grade - return HttpResponseRedirect(url) - def ent(request, cave_id, ent_letter): cave = Cave.objects.filter(kataster_number = cave_id)[0] cave_and_ent = CaveAndEntrance.objects.filter(cave = cave).filter(entrance_letter = ent_letter)[0] @@ -497,6 +482,32 @@ def get_entrances(request, caveslug): return render(request,'errors/badslug.html', {'badslug': caveslug}) return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]}) +def caveQMs(request, slug): + try: + cave = Cave.objects.get(caveslug__slug = slug) + except: + return render(request,'errors/badslug.html', {'badslug': slug}) + + if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated: + return render(request,'nonpublic.html', {'instance': cave}) + else: + return render(request,'cave_qms.html', {'cave': cave}) + +def qm(request,cave_id,qm_id,year,grade=None): + year=int(year) + try: + qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year) + return render(request,'qm.html',locals()) + except Cave.MultipleObjectsReturned: # entirely the wrong action, REPLACE with the right display + caves = Cave.objects.filter(kataster_number=cave_id) + return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves }) + + except QM.DoesNotExist: + url=urllib.parse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id) + if grade: + url += r'&grade=' + grade + return HttpResponseRedirect(url) + def get_qms(request, caveslug): try: cave = Cave.objects.get(caveslug__slug = caveslug) diff --git a/core/views/uploads.py b/core/views/uploads.py index a2e72de..e1ba9d1 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -115,15 +115,16 @@ def scanupload(request, path=None): return(oldwallet(request, path)) if str(wallet).lower().endswith('indexpages'): - print(f'! - FORM scanupload - start {wallet} REDIRECT TO OLDWALLET') + # print(f'! - FORM scanupload - start {wallet} REDIRECT TO OLDWALLET') return(walletindex(request, path)) if not re.match('(19|20)\d\d[:#]\d\d', wallet): wallet = "2022:01" # improve this later - print(f'! - FORM scanupload - start {wallet}') + # print(f'! - FORM scanupload - start {wallet}') if path: - print(f'! - FORM scanupload - start wallet:{wallet}: path:{path}:') + pass + # print(f'! - FORM scanupload - start wallet:{wallet}: path:{path}:') if int(year) < 1977: year = "1977" if int(year) > 2050: diff --git a/templates/cave_uground_description.html b/templates/_cave_uground_description.html similarity index 100% rename from templates/cave_uground_description.html rename to templates/_cave_uground_description.html diff --git a/templates/svxcaveseveral.html b/templates/svxcaveseveral.html index f889acb..4149011 100644 --- a/templates/svxcaveseveral.html +++ b/templates/svxcaveseveral.html @@ -32,7 +32,7 @@
If you can see a filename here: [ {{cave.survex_file}} ] which does not match any in the list below including the directories beginning with caves-162X/ not just the filename, then (if logged on) you can - click here /cave/{{cave.slug}}/edit + click here /{{cave.slug}}_cave_edit to go to a form to correct the online data. Instructions for filling in this form are in this part of the survey handbook. diff --git a/templates/svxcavesingle.html b/templates/svxcavesingle.html index 4e62bf2..7a5917d 100644 --- a/templates/svxcavesingle.html +++ b/templates/svxcavesingle.html @@ -32,7 +32,7 @@ All the processing to extract the survex subdriectories and survex files is done
If you can see a filename here: [ {{cave.survex_file}} ] which does not match any in the list below including the directories beginning with caves-162X/
not just the filename, then (if logged on) you can
-click here /cave/{{cave.slug}}/edit
+click here {{cave.slug}}_cave_edit
to go to a form to correct the online data.
Instructions for filling in this form are in this part
of the survey handbook.
diff --git a/urls.py b/urls.py
index 8527700..28d5a58 100644
--- a/urls.py
+++ b/urls.py
@@ -7,13 +7,13 @@ from django.contrib import admin
from django.contrib import auth
from django.urls import path, reverse, resolve
-from troggle.core.views import caves, statistics, survex
+from troggle.core.views import statistics, survex
from troggle.core.views.scans import scansingle, allwallets
from troggle.core.views.drawings import dwgallfiles, dwgfilesingle
from troggle.core.views.uploads import dwgupload, scanupload, photoupload
from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage
from troggle.core.views.other import exportlogbook
-from troggle.core.views.caves import ent, cavepage
+from troggle.core.views.caves import ent, cavepage, caveindex, get_entrances, get_qms, edit_cave, cave3d, caveEntrance, edit_entrance, caveQMs, qm
from troggle.core.views.logbooks import get_logbook_entries, logbookentry, logbookSearch
from troggle.core.views.logbooks import notablepersons, person, get_people
from troggle.core.views.logbooks import expedition, personexpedition, Expeditions_tsvListView, Expeditions_jsonListView
@@ -78,8 +78,8 @@ trogglepatterns = [
path('expofiles/', include(expofilesurls)), # intercepted by Apache, if it is running.
path('expofiles', include(expofilesurls)), # curious interaction with the include() here, not just a slash problem.
- re_path(r'^caves$', caves.caveindex, name="caveindex"),
- re_path(r'^indxal.htm$', caves.caveindex, name="caveindex"), # ~420 hrefs to this url in expoweb files
+ re_path(r'^caves$', caveindex, name="caveindex"),
+ re_path(r'^indxal.htm$', caveindex, name="caveindex"), # ~420 hrefs to this url in expoweb files
re_path(r'^people/?$', notablepersons, name="notablepersons"),
re_path(r'^admin/doc/', include('django.contrib.admindocs.urls')), # needs docutils Python module (http://docutils.sf.net/).
@@ -119,25 +119,25 @@ trogglepatterns = [
# Internal. editfile.html template uses these internally
re_path(r'^getPeople/(?P