From 9a28e93ac605b320a998707542ae409ba235cde1 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 28 Mar 2023 19:26:37 +0100 Subject: [PATCH] EntranceSlug removed from data model. --- core/models/caves.py | 36 ++++++++----------------------- core/views/caves.py | 2 +- parsers/caves.py | 45 +++++++++++++++++---------------------- templates/cave_debug.html | 10 ++++----- 4 files changed, 33 insertions(+), 60 deletions(-) diff --git a/core/models/caves.py b/core/models/caves.py index 4737c82..8d94086 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -60,7 +60,9 @@ class Area(TroggleModel): class CaveAndEntrance(models.Model): - """CASCADE means that if the cave or the entrance is deleted, then this CaveAndEntrance + """This class is ONLY used to create a FormSet for editing the cave and all its + entrances in one form. + CASCADE means that if the cave or the entrance is deleted, then this CaveAndEntrance is deleted too """ cave = models.ForeignKey("Cave", on_delete=models.CASCADE) @@ -156,8 +158,6 @@ class Cave(TroggleModel): pass else: self.official_name.lower() - # 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): @@ -260,12 +260,12 @@ class Cave(TroggleModel): 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 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): @@ -385,27 +385,9 @@ class Entrance(TroggleModel): return self.findability != "S" or not self.has_photo or self.marking != "T" def get_absolute_url(self): - # ancestor_titles='/'.join([subcave.title for subcave in self.get_ancestors()]) - # if ancestor_titles: - # res = '/'.join((self.get_root().cave.get_absolute_url(), ancestor_titles, self.title)) - # else: - # res = '/'.jocavein((self.get_root().cave.get_absolute_url(), self.title)) - # return res res = "/".join((self.get_root().cave.get_absolute_url(), self.title)) return res - #REPLACE this with a slug filed on the Entrance itself - # def slug(self): - # """Returns the first slug with primary=True that it can find, - # if there are none with primary=True, then it returns the first slug it finds - # """ - # if not self.cached_slug: - # slugs = self.entranceslug_set.filter() - # if slugs: - # self.cached_slug = slugs[0].slug - # self.save() - # return self.cached_slug - def cavelist(self): rs = [] for e in CaveAndEntrance.objects.filter(entrance=self): diff --git a/core/views/caves.py b/core/views/caves.py index 6771798..25a7fee 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -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, EntranceSlug, GetCaveLookup +from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup # EntranceSlug, from troggle.core.models.logbooks import CaveSlug, QM from troggle.core.utils import write_and_commit from troggle.core.views import expo diff --git a/parsers/caves.py b/parsers/caves.py index 4e1f171..e5e6811 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -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, EntranceSlug, GetCaveLookup +from troggle.core.models.caves import Area, Cave, CaveAndEntrance, Entrance, GetCaveLookup #EntranceSlug, from troggle.core.models.logbooks import CaveSlug from troggle.core.models.troggle import DataIssue from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS, EXPOWEB, SURVEX_DATA @@ -46,19 +46,19 @@ 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}-{slug} entrance create failure" - DataIssue.objects.create(parser="entrances", message=message, url=f"{slug}") - print(message) + # 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() + # # ent.cached_slug = slug + # # ent.filename = slug + ".html" + # # ent.save() return ent else: - message = f" ! {k:11s} {msg} cave SLUG '{slug}' create failure" + message = f" ! {k:11s} {msg}-{slug} {k} entrance create failure" DataIssue.objects.create(parser="entrances", message=message, url=f"{slug}") print(message) raise @@ -82,13 +82,13 @@ def set_dummy_entrance(id, slug, cave, msg="DUMMY"): 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) + # 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") @@ -283,13 +283,6 @@ def do_pending_cave(k, url, area): try: set_dummy_entrance(k, slug, cave, msg="PENDING") - # ent = dummy_entrance(k, slug, msg="PENDING") - # ceinsts = CaveAndEntrance.objects.update_or_create(cave=cave, entrance_letter="", entrance=ent) - # for ceinst in ceinsts: - # if str(ceinst) == str(cave): # magic runes... why is the next value a Bool? - # ceinst.cave = cave - # ceinst.save() - # break except: message = f" ! {k:11s} PENDING entrance + cave UNION create failure '{cave}' [{slug}] {k}" # message = f" ! {k:11s} PENDING entrance + cave UNION create failure '{cave}' [{ent}]" @@ -341,7 +334,7 @@ def readentrance(filename): other_description = getXML(entrancecontents, "other_description", maxItems=1, context=context) bearings = getXML(entrancecontents, "bearings", maxItems=1, context=context) url = getXML(entrancecontents, "url", maxItems=1, context=context) - # if len(non_public) == 1 and len(slugs) >= 1 and len(name) >= 1 and len(entrance_description) == 1 and len(explorers) == 1 and len(map_description) == 1 and len(location_description) == 1 and len(lastvisit) == 1 and len(approach) == 1 and len(underground_description) == 1 and len(marking) == 1 and len(marking_comment) == 1 and len(findability) == 1 and len(findability_description) == 1 and len(alt) == 1 and len(northing) == 1 and len(easting) == 1 and len(tag_station) == 1 and len(exact_station) == 1 and len(other_station) == 1 and len(other_description) == 1 and len(bearings) == 1 and len(url) == 1: + e, state = Entrance.objects.update_or_create( name=name[0], non_public={ diff --git a/templates/cave_debug.html b/templates/cave_debug.html index 6ff51c0..dee9518 100644 --- a/templates/cave_debug.html +++ b/templates/cave_debug.html @@ -7,8 +7,8 @@

Entrances

- - + + @@ -21,12 +21,10 @@ {{ent.slug}} {% endfor %}
entcached_slug
entranceent slug N slugs slugs
- {{ent.entranceslug_set.all|length }} +- - {% for s in ent.entranceslug_set.all %} - {{s.slug}}, - {% endfor %} +-