forked from expo/troggle
remove 'primary' concept from entrance slugs. tested.
This commit is contained in:
parent
6ca5d5bfa8
commit
bbc13c4eb9
@ -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 = []
|
||||
|
@ -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,
|
||||
|
@ -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}"'
|
||||
|
@ -8,17 +8,17 @@
|
||||
<h2 id="cmult">Entrances</h2>
|
||||
<table>
|
||||
<tr><th>ent</th>
|
||||
<th>cached_primary_slug</th>
|
||||
<th>cached_slug</th>
|
||||
<th>N slugs</th>
|
||||
<th>slugs</th>
|
||||
</tr>
|
||||
{% for ent in ents %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ent}}
|
||||
#{{ent.id}} {{ent}}
|
||||
</td>
|
||||
<td>
|
||||
{{ent.cached_primary_slug}}
|
||||
{{ent.cached_slug}}
|
||||
</td>
|
||||
<td>
|
||||
{{ent.entranceslug_set.all|length }}
|
||||
|
Loading…
Reference in New Issue
Block a user