2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00

tidy up entranceSlug all now deleted

This commit is contained in:
Philip Sargent 2023-03-28 20:30:00 +01:00
parent e7d9e9402a
commit 9ffe3f690b
5 changed files with 10 additions and 75 deletions

View File

@ -157,13 +157,13 @@ class EntranceForm(ModelForm):
return self.cleaned_data
# This next line is called from the templates/edit_cave2.html template.
# 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
class EntranceLetterForm(ModelForm):
"""Form to link entrances to caves, along with an entrance number.

View File

@ -25,11 +25,11 @@ Gcave_count = None
"""
todo = """
- Find out why we have separate objects CaveSlug and EntranceSlug and why
- Find out why we have separate objects CaveSlug and why
these are not just a single field on the Model. Do we ever need more
than one slug per cave or entrance? Surely that would break everything??
- Can we rewrite things to eliminate the CaveSlug and EntranceSlug Classes and objects? Surely
- Can we rewrite things to eliminate the CaveSlug and objects? Surely
foreign keys work fine ?!
- Why do we have CaveAndEntrance objects ? Surely entranceletter belong son the Entrance object?
@ -259,15 +259,6 @@ class Cave(TroggleModel):
pass
return lowestareas[0]
# class EntranceSlug(models.Model):
# """If the Entrance is deleted, then this EntranceSlug is deleted too
# """
# entrance = models.ForeignKey("Entrance", on_delete=models.CASCADE)
# slug = models.SlugField(max_length=50, unique=True)
# # primary = models.BooleanField(default=False)
class Entrance(TroggleModel):
MARKING_CHOICES = (
("P", "Paint"),

View File

@ -11,7 +11,7 @@ from troggle.core.models.troggle import Expedition, TroggleModel
"""
todo = """
- Can we rewrite things to eliminate the CaveSlug and EntranceSlug Classes and objects? Surely
- Can we rewrite things to eliminate the CaveSlug and objects? Surely
foreign keys work fine ?!
"""

View File

@ -10,7 +10,7 @@ from django.urls import NoReverseMatch
import troggle.settings as settings
from troggle.core.forms import CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm
from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup # EntranceSlug,
from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup
from troggle.core.models.logbooks import CaveSlug, QM
from troggle.core.utils import write_and_commit
from troggle.core.views import expo
@ -407,8 +407,10 @@ def edit_cave(request, path="", slug=None):
def edit_entrance(request, path="", caveslug=None, slug=None):
"""This is the form that edits the entrance data for a single entrance and writes out
an XML file in the :expoweb: repo folder
The format for the file being saved is in templates/dataformat/entrance.xml
Warning. This uses Django deep magic.
Warning. This uses Django deep magic for multiple forms and the CaveAndEntrance class.
It does save the data into into the database directly, not by parsing the file.
"""
@ -419,7 +421,6 @@ def edit_entrance(request, path="", caveslug=None, slug=None):
return render(request, "errors/badslug.html", {"badslug": f"{slug} {caveslug} - from edit_entrance()"})
if slug:
# entrance = Entrance.objects.get(entranceslug__slug=slug)
caveAndEntrance = CaveAndEntrance.objects.get(entrance=entrance, cave=cave)
entlettereditable = False
else:
@ -441,9 +442,6 @@ def edit_entrance(request, path="", caveslug=None, slug=None):
entrance.cached_primary_slug = slugname
entrance.filename = slugname + ".html"
entrance.save()
# if slug is None:
# es = EntranceSlug(entrance=entrance, slug=slugname, primary=True)
# es.save()
entrance_file = entrance.file_output()
cave_file = cave.file_output()
write_and_commit([entrance_file, cave_file], f"Online edit of {cave}{entletter}")
@ -485,29 +483,12 @@ def ent(request, cave_id, ent_letter):
def cave_debug(request):
ents = Entrance.objects.all().order_by('id')
#slugs = self.entranceslug_set.filter()
return render(
request,
"cave_debug.html",
{"ents": ents},
)
# def entranceSlug(request, slug):
# '''This seems to be a fossil, but I am not sure...
# '''
# entrance = Entrance.objects.get(entranceslug__slug = slug)
# if entrance.non_public and not request.user.is_authenticated:
# return render(request,'nonpublic.html', {'instance': entrance})
# else:
# return render(request,'entranceslug.html', {'entrance': entrance})
# def surveyindex(request):
# '''The template does not exist, there is no URL which calls this, so it is a fossil
# '''
# surveys=Survey.objects.all()
# expeditions=Expedition.objects.order_by("-year")
# return render(request,'survey.html',locals())
def get_entrances(request, caveslug):
try:

View File

@ -5,7 +5,7 @@ from pathlib import Path
from django.conf import settings
from django.db import transaction
from troggle.core.models.caves import Area, Cave, CaveAndEntrance, Entrance, GetCaveLookup #EntranceSlug,
from troggle.core.models.caves import Area, Cave, CaveAndEntrance, Entrance, GetCaveLookup
from troggle.core.models.logbooks import CaveSlug
from troggle.core.models.troggle import DataIssue
from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS, EXPOWEB, SURVEX_DATA
@ -46,16 +46,6 @@ def dummy_entrance(k, slug, msg="DUMMY"):
marking="?",
)
if ent:
# try: # Now create a entranceslug object
# EntranceSlug(entrance=ent, slug=slug)
# except:
# message = f" ! {k:11s} {msg} cave SLUG '{slug}' create failure"
# DataIssue.objects.create(parser="entrances", message=message, url=f"{slug}")
# print(message)
# # ent.cached_slug = slug
# # ent.filename = slug + ".html"
# # ent.save()
return ent
else:
message = f" ! {k:11s} {msg}-{slug} {k} entrance create failure"
@ -81,14 +71,6 @@ def set_dummy_entrance(id, slug, cave, msg="DUMMY"):
message = f' ! Entrance Dummy setting failure, slug:"{slug}" cave id :"{id}" '
DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}")
print(message)
# try:
# EntranceSlug.objects.update_or_create(entrance=entrance, slug=slug)
# except:
# # raise
# message = f' ! EntranceSlug setting failure for Dummy cave, slug:"{slug}" cave id :"{id}" '
# DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}")
# print(message)
def make_areas():
print(" - Creating Areas 1623, 1624, 1627 and 1626")
@ -372,25 +354,6 @@ def readentrance(filename):
message = f" ! - More than one slug for an entrance: {entrance}, slugs: {slugs}. Aborting."
DataIssue.objects.create(parser="entrances", message=message, url=f"/cave/{slug}/edit/")
print(message)
# for slug in slugs:
# # print("entrance slug:{} filename:{}".format(slug, filename))
# try:
# EntranceSlug.objects.update_or_create(entrance=e, slug=slug)
# except:
# # need to cope with duplicates
# message = f" ! FAILED to get precisely one ENTRANCE when updating using: cave_entrance/{filename}"
# DataIssue.objects.create(parser="entrances", message=message, url=f"/cave/{slug}/edit/")
# # kents = EntranceSlug.objects.all().filter(entrance=e, slug=slug, primary=primary)
# kents = EntranceSlug.objects.all().filter(entrance=e, slug=slug)
# for k in kents:
# message = " ! - DUPLICATE in db. entrance:" + str(k.entrance) + ", slug:" + str(k.slug())
# DataIssue.objects.create(parser="entrances", message=message, url=f"/cave/{slug}/edit/")
# print(message)
# for k in kents:
# if k.slug() is not None:
# print(" ! - OVERWRITING this one: slug:" + str(k.slug()))
# k.notes = "DUPLICATE entrance found on import. Please fix\n" + k.notes
def readcave(filename):
"""Reads an enrance description from the .html file