From bbc13c4eb9a426f483aac48a97e76a1a1b08f053 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 28 Mar 2023 17:08:55 +0100 Subject: [PATCH] remove 'primary' concept from entrance slugs. tested. --- core/models/caves.py | 19 +++++++------------ core/views/caves.py | 2 +- parsers/caves.py | 10 ++++------ templates/cave_debug.html | 6 +++--- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/core/models/caves.py b/core/models/caves.py index bae8eb5..fc3e80f 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -265,7 +265,7 @@ class EntranceSlug(models.Model): """ entrance = models.ForeignKey("Entrance", on_delete=models.CASCADE) slug = models.SlugField(max_length=50, unique=True) - primary = models.BooleanField(default=False) + # primary = models.BooleanField(default=False) class Entrance(TroggleModel): @@ -284,7 +284,7 @@ class Entrance(TroggleModel): alt = models.TextField(blank=True, null=True) approach = models.TextField(blank=True, null=True) bearings = models.TextField(blank=True, null=True) - cached_primary_slug = models.CharField(max_length=200, blank=True, null=True) + cached_slug = models.CharField(max_length=200, blank=True, null=True) easting = models.TextField(blank=True, null=True) entrance_description = models.TextField(blank=True, null=True) exact_station = models.TextField(blank=True, null=True) @@ -398,17 +398,12 @@ class Entrance(TroggleModel): """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_primary_slug: - primarySlugs = self.entranceslug_set.filter(primary=True) - if primarySlugs: - self.cached_primary_slug = primarySlugs[0].slug + if not self.cached_slug: + slugs = self.entranceslug_set.filter() + if slugs: + self.cached_slug = slugs[0].slug self.save() - else: - slugs = self.entranceslug_set.filter() - if slugs: - self.cached_primary_slug = slugs[0].slug - self.save() - return self.cached_primary_slug + return self.cached_slug def cavelist(self): rs = [] diff --git a/core/views/caves.py b/core/views/caves.py index 81a1e8e..6771798 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -484,7 +484,7 @@ def ent(request, cave_id, ent_letter): ) def cave_debug(request): - ents = Entrance.objects.all() + ents = Entrance.objects.all().order_by('id') #slugs = self.entranceslug_set.filter() return render( request, diff --git a/parsers/caves.py b/parsers/caves.py index feb8fbb..3f88c45 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -48,13 +48,13 @@ def dummy_entrance(k, slug, msg="DUMMY"): if ent: ent.save() # must save to have id before foreign keys work. try: # Now create a entrance slug ID - EntranceSlug(entrance=ent, slug=slug, primary=False) + EntranceSlug(entrance=ent, slug=slug) except: message = f" ! {k:11s} {msg}-{slug} entrance create failure" DataIssue.objects.create(parser="caves", message=message, url=f"{slug}") print(message) - ent.cached_primary_slug = slug + ent.cached_slug = slug ent.filename = slug + ".html" ent.save() return ent @@ -362,13 +362,12 @@ def readentrance(filename): bearings=bearings[0], url=url[0], filename=filename, - cached_primary_slug=slugs[0], + cached_slug=slugs[0], ) - primary = True for slug in slugs: # print("entrance slug:{} filename:{}".format(slug, filename)) try: - EntranceSlug.objects.update_or_create(entrance=e, slug=slug, primary=primary) + 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}" @@ -383,7 +382,6 @@ def readentrance(filename): 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 - primary = False # else: # more than one item in long list. But this is not an error, and the max and min have been checked by getXML # slug = Path(filename).stem # message = f' ! ABORT loading this entrance. in "{filename}"' diff --git a/templates/cave_debug.html b/templates/cave_debug.html index be0ce20..7de0ce0 100644 --- a/templates/cave_debug.html +++ b/templates/cave_debug.html @@ -8,17 +8,17 @@

Entrances

- + {% for ent in ents %}
entcached_primary_slugcached_slug N slugs slugs
- {{ent}} + #{{ent.id}} {{ent}} - {{ent.cached_primary_slug}} + {{ent.cached_slug}} {{ent.entranceslug_set.all|length }}