mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
Fixed errors when creating new caves and entrances via the website. Moved slug logic to forms (previously checked in). This allows slug uniqueness to be validated in the form
This commit is contained in:
parent
941100a8a3
commit
10ff8a5aab
@ -352,23 +352,12 @@ def edit_cave(request, path="", slug=None):
|
|||||||
if form.is_valid() and ceFormSet.is_valid():
|
if form.is_valid() and ceFormSet.is_valid():
|
||||||
# print(f'! POST is valid. {cave}')
|
# print(f'! POST is valid. {cave}')
|
||||||
cave = form.save(commit=False)
|
cave = form.save(commit=False)
|
||||||
if slug is None:
|
|
||||||
for a in form.cleaned_data["area"]:
|
cave.filename = form.cleaned_data["cave_slug"] + ".html"
|
||||||
if a.kat_area():
|
|
||||||
myArea = a.kat_area()
|
|
||||||
if form.cleaned_data["kataster_number"]:
|
|
||||||
myslug = f"{myArea}-{form.cleaned_data['kataster_number']}"
|
|
||||||
else:
|
|
||||||
myslug = f"{myArea}-{form.cleaned_data['unofficial_number']}"
|
|
||||||
else:
|
|
||||||
myslug = slug
|
|
||||||
# Converting a PENDING cave to a real cave by saving this form
|
|
||||||
myslug = myslug.replace("-PENDING-", "-")
|
|
||||||
cave.filename = myslug + ".html"
|
|
||||||
cave.save()
|
cave.save()
|
||||||
form.save_m2m()
|
form.save_m2m()
|
||||||
if slug is None:
|
if slug is None:
|
||||||
cs = CaveSlug(cave=cave, slug=myslug, primary=True)
|
cs = CaveSlug(cave=cave, slug=form.cleaned_data["cave_slug"], primary=True)
|
||||||
cs.save()
|
cs.save()
|
||||||
ceinsts = ceFormSet.save(commit=False)
|
ceinsts = ceFormSet.save(commit=False)
|
||||||
for ceinst in ceinsts:
|
for ceinst in ceinsts:
|
||||||
@ -386,16 +375,18 @@ def edit_cave(request, path="", slug=None):
|
|||||||
return render(request, "errors/generic.html", {"message": message})
|
return render(request, "errors/generic.html", {"message": message})
|
||||||
|
|
||||||
return HttpResponseRedirect("/" + cave.url)
|
return HttpResponseRedirect("/" + cave.url)
|
||||||
else:
|
|
||||||
message = f"! POST data is INVALID {cave}"
|
|
||||||
print(message)
|
|
||||||
else:
|
else:
|
||||||
# re-read cave data from file.
|
if slug is not None:
|
||||||
filename = str(cave.slug() +".html")
|
# re-read cave data from file.
|
||||||
read_cave(filename, cave=cave)
|
filename = str(cave.slug() +".html")
|
||||||
|
read_cave(filename, cave=cave)
|
||||||
|
|
||||||
form = CaveForm(instance=cave)
|
form = CaveForm(instance=cave, initial={'cave_slug': cave.slug()})
|
||||||
ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
|
ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
|
||||||
|
else:
|
||||||
|
form = CaveForm()
|
||||||
|
ceFormSet = CaveAndEntranceFormSet(queryset=CaveAndEntrance.objects.none())
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
@ -426,18 +417,20 @@ def edit_entrance(request, path="", caveslug=None, entslug=None):
|
|||||||
except:
|
except:
|
||||||
return render(request, "errors/badslug.html", {"badslug": f"for cave {caveslug} - from edit_entrance()"})
|
return render(request, "errors/badslug.html", {"badslug": f"for cave {caveslug} - from edit_entrance()"})
|
||||||
|
|
||||||
try:
|
if entslug:
|
||||||
entrance = Entrance.objects.get(slug=entslug)
|
try:
|
||||||
except:
|
entrance = Entrance.objects.get(slug=entslug)
|
||||||
return render(request, "errors/badslug.html", {"badslug": f"for entrance {slug} - from edit_entrance()"})
|
except:
|
||||||
|
return render(request, "errors/badslug.html", {"badslug": f"for entrance {entslug} - from edit_entrance()"})
|
||||||
|
else:
|
||||||
|
entrance = None
|
||||||
|
|
||||||
if entslug:
|
if entslug:
|
||||||
# print(f"{caveslug=} {entslug=} {path=}")
|
# print(f"{caveslug=} {entslug=} {path=}")
|
||||||
caveAndEntrance = CaveAndEntrance.objects.get(entrance=entrance, cave=cave)
|
caveAndEntrance = CaveAndEntrance.objects.get(entrance=entrance, cave=cave)
|
||||||
entlettereditable = False
|
entlettereditable = False
|
||||||
else:
|
else:
|
||||||
entrance = Entrance()
|
caveAndEntrance = CaveAndEntrance(cave=cave, entrance=Entrance())
|
||||||
caveAndEntrance = CaveAndEntrance(cave=cave, entrance=entrance)
|
|
||||||
entlettereditable = True
|
entlettereditable = True
|
||||||
|
|
||||||
if request.POST:
|
if request.POST:
|
||||||
@ -461,19 +454,24 @@ def edit_entrance(request, path="", caveslug=None, entslug=None):
|
|||||||
cave_file = cave.file_output()
|
cave_file = cave.file_output()
|
||||||
entrance.save()
|
entrance.save()
|
||||||
write_and_commit([entrance_file, cave_file], f"Online edit of entrance {entrance.slug}")
|
write_and_commit([entrance_file, cave_file], f"Online edit of entrance {entrance.slug}")
|
||||||
|
entrance_letter.entrance = entrance
|
||||||
if entslug is None:
|
if entslug is None:
|
||||||
entrance_letter.save()
|
entrance_letter.save()
|
||||||
return HttpResponseRedirect("/" + cave.url)
|
return HttpResponseRedirect("/" + cave.url)
|
||||||
else:
|
else:
|
||||||
# re-read entrance data from file.
|
if entrance:
|
||||||
filename = str(entrance.slug +".html")
|
# re-read entrance data from file.
|
||||||
read_entrance(filename, ent=entrance)
|
filename = str(entrance.slug +".html")
|
||||||
|
read_entrance(filename, ent=entrance)
|
||||||
|
|
||||||
form = EntranceForm(instance=entrance)
|
form = EntranceForm(instance=entrance)
|
||||||
if entslug is None:
|
if entslug is None:
|
||||||
entletter = EntranceLetterForm()
|
entletter = EntranceLetterForm()
|
||||||
|
else:
|
||||||
|
entletter = caveAndEntrance.entrance_letter
|
||||||
else:
|
else:
|
||||||
entletter = caveAndEntrance.entrance_letter
|
form = EntranceForm()
|
||||||
|
entletter = EntranceLetterForm()
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
{% include 'html_editor_pop_ups.html' %}
|
{% include 'html_editor_pop_ups.html' %}
|
||||||
<h2>{{message}}</h2>
|
<h2>{{message}}</h2>
|
||||||
<form action="" method="post">{% csrf_token %}
|
<form action="" method="post">{% csrf_token %}
|
||||||
<table>{{ form }}<!-- begin caveAndEntranceFormSet-->{{caveAndEntranceFormSet}}<!--end caveAndEntranceFormSet--></table>
|
<table>{{ form }}
|
||||||
|
<!-- begin caveAndEntranceFormSet-->{{caveAndEntranceFormSet}}<!--end caveAndEntranceFormSet--></table>
|
||||||
<p><input type="submit" value="Submit" /></p>
|
<p><input type="submit" value="Submit" /></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<form id="new_image_form" action="{% url 'new_image_form' path %}" method="post" enctype="multipart/form-data">
|
<form id="new_image_form" action="{% url 'new_image_form' path %}" method="post" enctype="multipart/form-data" class="dropzone">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<input type="submit" value="Submit">
|
<input type="submit" value="Submit">
|
||||||
|
Loading…
Reference in New Issue
Block a user