diff --git a/core/forms.py b/core/forms.py index aeaa7ed..88f8345 100644 --- a/core/forms.py +++ b/core/forms.py @@ -226,13 +226,11 @@ class EntranceForm(ModelForm): return self.cleaned_data -# This next line is called from the templates/edit_cave.html template. -# This is sufficient to create an entire entry for for the cave fields automatically -# http://localhost:8000/cave/new/ -# using django built-in Deep Magic. https://docs.djangoproject.com/en/dev/topics/forms/modelforms/ -# for forms which map directly onto a Django Model -CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=("cave",)) -# This is used only in edit_entrance() in views/caves.py +# # This next line is sufficient to create an entire entry for for the cave fields automatically +# # using django built-in Deep Magic. https://docs.djangoproject.com/en/dev/topics/forms/modelforms/ +# # for forms which map directly onto a Django Model +# CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=("cave",)) +# # This is used only in templates/editcave.html which is called only to edit caves in core/views/cave.py class EntranceLetterForm(ModelForm): """Form to link entrances to caves, along with an entrance number. diff --git a/core/views/caves.py b/core/views/caves.py index 4af4217..6c11519 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -1,5 +1,6 @@ import os import re +import django import subprocess import tempfile import zipfile @@ -14,7 +15,7 @@ from django.shortcuts import render, redirect from django.urls import NoReverseMatch, reverse import troggle.settings as settings -from troggle.core.forms import CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm +from troggle.core.forms import CaveForm, EntranceForm, EntranceLetterForm # CaveAndEntranceFormSet, from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup, get_cave_leniently from troggle.core.models.logbooks import QM from troggle.core.models.wallets import Wallet @@ -472,8 +473,7 @@ def edit_cave(request, path="", slug=None): if request.POST: form = CaveForm(request.POST, instance=cave) - #ceFormSet = CaveAndEntranceFormSet(request.POST) - if form.is_valid(): # and ceFormSet.is_valid(): + if form.is_valid(): print(f'edit_cave(): POST is valid. Editing {cave}') cave = form.save(commit=False) # print(cave) @@ -489,10 +489,6 @@ def edit_cave(request, path="", slug=None): cs = CaveSlug(cave=cave, slug=slug, primary=True) print(f"edit_cave(): New CaveSlug saved {slug}") cs.save() - #ceinsts = ceFormSet.save(commit=False) - #for ceinst in ceinsts: - # ceinst.cave = cave - # ceinst.save() try: cave_file = cave.file_output() write_and_commit([cave_file], f"Online edit of cave {cave}") @@ -523,20 +519,24 @@ def edit_cave(request, path="", slug=None): raise form = CaveForm(instance=cave, initial={'cave_slug': cave.slug()}) - #ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all()) else: form = CaveForm() - #ceFormSet = CaveAndEntranceFormSet(queryset=CaveAndEntrance.objects.none()) + # The way formsets are rendered chnaged between Django 4 and Django 5 + major, _, _, _, _ = django.VERSION + if major < 5: + tabletype = "table" + else: + tabletype = "div" + print(f"edit_cave(): returning render() with tabletype={tabletype} {django.VERSION} ") + - print(f"edit_cave(): returning render()") return render( request, "editcave.html", { "form": form, "cave": cave, - "message": message, "year": current_expo(), - #"caveAndEntranceFormSet": ceFormSet, + "message": message, "year": current_expo(), "tabletype": tabletype, "path": path + "/", # used for saving images if attached }, ) diff --git a/templates/editcave.html b/templates/editcave.html index 6f7b741..05fc243 100644 --- a/templates/editcave.html +++ b/templates/editcave.html @@ -59,8 +59,9 @@ at troggle/core/forms.py ass this uses a Django magic form creation thinggy. -->

{{message}}

{% csrf_token %} - {{ form }} - {{caveAndEntranceFormSet}}
+ {% if tabletype == 'table' %}{% else %}
{% endif %} + {{ form }} + {% if tabletype == 'table' %}
{% else %}{% endif %}

diff --git a/templates/html_editor_scripts_css.html b/templates/html_editor_scripts_css.html index d3ddc68..d16cdaf 100644 --- a/templates/html_editor_scripts_css.html +++ b/templates/html_editor_scripts_css.html @@ -32,7 +32,7 @@ z-index: 20; } - .HTMLarea { width:1000px;} + .HTMLarea { width:100%;} .popup-overlay.active { /*displays pop-up when "active" class is present*/ @@ -70,7 +70,7 @@