EntranceSlug removed from data model.

This commit is contained in:
Philip Sargent 2023-03-28 19:26:37 +01:00
parent 5738da8566
commit 9a28e93ac6
4 changed files with 33 additions and 60 deletions

View File

@ -60,7 +60,9 @@ class Area(TroggleModel):
class CaveAndEntrance(models.Model): 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 is deleted too
""" """
cave = models.ForeignKey("Cave", on_delete=models.CASCADE) cave = models.ForeignKey("Cave", on_delete=models.CASCADE)
@ -156,8 +158,6 @@ class Cave(TroggleModel):
pass pass
else: else:
self.official_name.lower() 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 return Path(settings.URL_ROOT) / self.url # not good Django style.. NEEDS actual URL
def url_parent(self): def url_parent(self):
@ -260,12 +260,12 @@ class Cave(TroggleModel):
return lowestareas[0] return lowestareas[0]
class EntranceSlug(models.Model): # class EntranceSlug(models.Model):
"""If the Entrance is deleted, then this EntranceSlug is deleted too # """If the Entrance is deleted, then this EntranceSlug is deleted too
""" # """
entrance = models.ForeignKey("Entrance", on_delete=models.CASCADE) # entrance = models.ForeignKey("Entrance", on_delete=models.CASCADE)
slug = models.SlugField(max_length=50, unique=True) # slug = models.SlugField(max_length=50, unique=True)
# primary = models.BooleanField(default=False) # # primary = models.BooleanField(default=False)
class Entrance(TroggleModel): class Entrance(TroggleModel):
@ -385,27 +385,9 @@ class Entrance(TroggleModel):
return self.findability != "S" or not self.has_photo or self.marking != "T" return self.findability != "S" or not self.has_photo or self.marking != "T"
def get_absolute_url(self): 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)) res = "/".join((self.get_root().cave.get_absolute_url(), self.title))
return res 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): def cavelist(self):
rs = [] rs = []
for e in CaveAndEntrance.objects.filter(entrance=self): for e in CaveAndEntrance.objects.filter(entrance=self):

View File

@ -10,7 +10,7 @@ from django.urls import NoReverseMatch
import troggle.settings as settings import troggle.settings as settings
from troggle.core.forms import CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm 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.models.logbooks import CaveSlug, QM
from troggle.core.utils import write_and_commit from troggle.core.utils import write_and_commit
from troggle.core.views import expo from troggle.core.views import expo

View File

@ -5,7 +5,7 @@ from pathlib import Path
from django.conf import settings from django.conf import settings
from django.db import transaction 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.logbooks import CaveSlug
from troggle.core.models.troggle import DataIssue from troggle.core.models.troggle import DataIssue
from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS, EXPOWEB, SURVEX_DATA from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS, EXPOWEB, SURVEX_DATA
@ -46,19 +46,19 @@ def dummy_entrance(k, slug, msg="DUMMY"):
marking="?", marking="?",
) )
if ent: if ent:
try: # Now create a entranceslug object # try: # Now create a entranceslug object
EntranceSlug(entrance=ent, slug=slug) # EntranceSlug(entrance=ent, slug=slug)
except: # except:
message = f" ! {k:11s} {msg}-{slug} entrance create failure" # message = f" ! {k:11s} {msg} cave SLUG '{slug}' create failure"
DataIssue.objects.create(parser="entrances", message=message, url=f"{slug}") # DataIssue.objects.create(parser="entrances", message=message, url=f"{slug}")
print(message) # print(message)
# ent.cached_slug = slug # # ent.cached_slug = slug
# ent.filename = slug + ".html" # # ent.filename = slug + ".html"
# ent.save() # # ent.save()
return ent return ent
else: 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}") DataIssue.objects.create(parser="entrances", message=message, url=f"{slug}")
print(message) print(message)
raise 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}") DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}")
print(message) print(message)
try: # try:
EntranceSlug.objects.update_or_create(entrance=entrance, slug=slug) # EntranceSlug.objects.update_or_create(entrance=entrance, slug=slug)
except: # except:
# raise # # raise
message = f' ! EntranceSlug setting failure for Dummy cave, slug:"{slug}" cave id :"{id}" ' # message = f' ! EntranceSlug setting failure for Dummy cave, slug:"{slug}" cave id :"{id}" '
DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}") # DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}")
print(message) # print(message)
def make_areas(): def make_areas():
print(" - Creating Areas 1623, 1624, 1627 and 1626") print(" - Creating Areas 1623, 1624, 1627 and 1626")
@ -283,13 +283,6 @@ def do_pending_cave(k, url, area):
try: try:
set_dummy_entrance(k, slug, cave, msg="PENDING") 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: 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}' [{slug}] {k}"
# message = f" ! {k:11s} PENDING entrance + cave UNION create failure '{cave}' [{ent}]" # 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) other_description = getXML(entrancecontents, "other_description", maxItems=1, context=context)
bearings = getXML(entrancecontents, "bearings", maxItems=1, context=context) bearings = getXML(entrancecontents, "bearings", maxItems=1, context=context)
url = getXML(entrancecontents, "url", 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( e, state = Entrance.objects.update_or_create(
name=name[0], name=name[0],
non_public={ non_public={

View File

@ -7,8 +7,8 @@
<h2 id="cmult">Entrances</h2> <h2 id="cmult">Entrances</h2>
<table> <table>
<tr><th>ent</th> <tr><th>entrance</th>
<th>cached_slug</th> <th>ent slug</th>
<th>N slugs</th> <th>N slugs</th>
<th>slugs</th> <th>slugs</th>
</tr> </tr>
@ -21,12 +21,10 @@
{{ent.slug}} {{ent.slug}}
</td> </td>
<td> <td>
{{ent.entranceslug_set.all|length }} -
</td> </td>
<td> <td>
{% for s in ent.entranceslug_set.all %} -
{{s.slug}},
{% endfor %}
</td> </td>
{% endfor %} {% endfor %}