From 94252a94feea6f8050f64fc3a7edf854d363afbc Mon Sep 17 00:00:00 2001 From: Martin Green Date: Sun, 31 Jul 2022 17:08:28 +0200 Subject: [PATCH] Edit caves in the same parent URL as the final file --- core/models/caves.py | 3 +++ core/views/caves.py | 2 +- templates/menu.html | 2 +- urls.py | 10 +++++----- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/models/caves.py b/core/models/caves.py index 8cd658c..20a7a96 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -145,6 +145,9 @@ class Cave(TroggleModel): #return settings.URL_ROOT + '/cave/' + href + '/' #return urljoin(settings.URL_ROOT, reverse('cave',kwargs={'cave_id':href,})) # WRONG. This produces /cave/161 and should be /1623/161 return Path(settings.URL_ROOT) / self.url # not good Django style.. NEEDS actual URL + + def url_parent(self): + return self.url.rsplit("/", 1)[0] def __str__(self, sep = ": "): return str(self.slug()) diff --git a/core/views/caves.py b/core/views/caves.py index 44dbb80..b56eacb 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -294,7 +294,7 @@ def caveEntrance(request, slug): return render(request,'cave_entrances.html', {'cave': cave}) @login_required_if_public -def edit_cave(request, slug=None): +def edit_cave(request, path = "", slug=None): '''This is the form that edits all the cave data and writes out an XML file in the :expoweb: repo folder The format for the file being saved is in templates/dataformat/cave.xml diff --git a/templates/menu.html b/templates/menu.html index 2dd44f6..8953eed 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -43,7 +43,7 @@ {% if editable %}
  • Edit this page
  • {% endif %} -{% if cave_editable %}
  • Edit this cave
  • {% endif %} +{% if cave_editable %}
  • Edit this cave
  • {% endif %} {% endif %} diff --git a/urls.py b/urls.py index e02c4f0..1c17b21 100644 --- a/urls.py +++ b/urls.py @@ -60,7 +60,7 @@ else: path('', expofilessingle, name="single"), # local copy of EXPOFILES ] -# see https://docs.djangoproject.com/en/dev/topics/auth/default/ +# see https://docs.djangoproject.com/en/dev/topics/auth/default/tiny # The URLs provided by include('django.contrib.auth.urls') are: # # accounts/login/ [name='login'] @@ -130,7 +130,7 @@ trogglepatterns = [ #re_path(r'^cave/description/([^/]+)/?$', caves.caveDescription), #!!!BAD, local links fail.. #re_path(r'^cave/(?P[^/]+)/?$', caves.cave, name="cave"), # used only in testing !? XXXXXXXXXXXXXXXXXXXXXXXXXX #re_path(r'^cave/(?P[^/]+)/?(?P[^/])$', ent), #!!!BAD, local links fail..# view_caves.ent - re_path(r'^(?P[^/]+)_cave_edit/$', edit_cave, name="edit_cave"), # edit_cave needed by cave.html template for url matching + re_path(r'^(?P.*)/(?P[^/]+)_cave_edit/$', edit_cave, name="edit_cave"), # edit_cave needed by cave.html template for url matching re_path(r'^(.*)_edit$', editexpopage, name="editexpopage"), re_path(r'^(?P\d\d\d\d)(?P.*)$', cavepage, name="cavepage"), # shorthand /1623/264 or 1623/161/top.htm # Note that urls eg '/1623/161/l/rl89a.htm' are handled by cavepage which redirects them to 'expopage' # Note that _edit$ for a cave description page in a subfolder e.g. /1623/204/204.html_edit gets caught here and breaks with 404 @@ -172,11 +172,11 @@ trogglepatterns = [ # The tunnel and therion drawings files pages path('dwgfiles', dwgallfiles, name="dwgallfiles"), - path('dwgfiles/', dwgallfiles, name="dwgallfiles"), + path('dwgfiles/', dwgallfiles, name="dwgallfiles"), path('dwgdataraw/', dwgfilesingle, name="dwgfilesingle"), # QMs pages - must precede other /caves pages? - re_path(r'^cave/qms/([^/]+)/?$', caveQMs, name="caveQMs"), + re_path(r'^cave/qms/([^/]+)/?$', caveQMs, name="caveQMs"), re_path(r'^cave/qms/(?P[^/]+)/(?P\d\d\d\d)-(?P\d*)(?P[ABCDXV\?]?)-?(?P[a-zA-Z]+.*)?$', qm, name="qm"), # Dogs breakfast # the resolution of a QM uses several fields together, there is no clean slug field. Artefact of history. @@ -198,7 +198,7 @@ trogglepatterns = [ re_path(r'^new_image_form/(?P.*)', new_image_form, name = 'new_image_form'), -# Final catchall which also serves expoweb handbook pages and images +# Final catchall which also serves expoweb handbook pages and imagestiny re_path(r'^(.*)$', expopage, name="expopage"), # CATCHALL assumed relative to EXPOWEB ]