debug ent report

This commit is contained in:
Philip Sargent 2023-03-28 15:37:25 +01:00
parent 2091eb8e8b
commit 6ca5d5bfa8
6 changed files with 91 additions and 40 deletions

View File

@ -74,30 +74,32 @@ class CaveAndEntrance(models.Model):
def __str__(self): def __str__(self):
return str(self.cave) + str(self.entrance_letter) return str(self.cave) + str(self.entrance_letter)
# class CaveSlug(models.Model):
# moved to models/logbooks.py to avoid cyclic import problem
class Cave(TroggleModel): class Cave(TroggleModel):
# too much here perhaps, # too much here perhaps,
official_name = models.CharField(max_length=160)
area = models.ManyToManyField(Area, blank=True) area = models.ManyToManyField(Area, blank=True)
depth = models.CharField(max_length=100, blank=True, null=True)
description_file = models.CharField(max_length=200, blank=True, null=True)
entrances = models.ManyToManyField("Entrance", through="CaveAndEntrance")
equipment = models.TextField(blank=True, null=True)
explorers = models.TextField(blank=True, null=True)
extent = models.CharField(max_length=100, blank=True, null=True)
filename = models.CharField(max_length=200)
kataster_code = models.CharField(max_length=20, blank=True, null=True) kataster_code = models.CharField(max_length=20, blank=True, null=True)
kataster_number = models.CharField(max_length=10, blank=True, null=True) kataster_number = models.CharField(max_length=10, blank=True, null=True)
unofficial_number = models.CharField(max_length=60, blank=True, null=True)
entrances = models.ManyToManyField("Entrance", through="CaveAndEntrance")
explorers = models.TextField(blank=True, null=True)
underground_description = models.TextField(blank=True, null=True)
equipment = models.TextField(blank=True, null=True)
references = models.TextField(blank=True, null=True)
survey = models.TextField(blank=True, null=True)
kataster_status = models.TextField(blank=True, null=True) kataster_status = models.TextField(blank=True, null=True)
underground_centre_line = models.TextField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)
length = models.CharField(max_length=100, blank=True, null=True) length = models.CharField(max_length=100, blank=True, null=True)
depth = models.CharField(max_length=100, blank=True, null=True) notes = models.TextField(blank=True, null=True)
extent = models.CharField(max_length=100, blank=True, null=True) official_name = models.CharField(max_length=160)
references = models.TextField(blank=True, null=True)
survex_file = models.CharField(max_length=100, blank=True, null=True) # should be a foreign key survex_file = models.CharField(max_length=100, blank=True, null=True) # should be a foreign key
description_file = models.CharField(max_length=200, blank=True, null=True) survey = models.TextField(blank=True, null=True)
underground_centre_line = models.TextField(blank=True, null=True)
underground_description = models.TextField(blank=True, null=True)
unofficial_number = models.CharField(max_length=60, blank=True, null=True)
url = models.CharField(max_length=200, blank=True, null=True) url = models.CharField(max_length=200, blank=True, null=True)
filename = models.CharField(max_length=200)
# class Meta: # class Meta:
# unique_together = (("area", "kataster_number"), ("area", "unofficial_number")) # unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
@ -267,15 +269,6 @@ class EntranceSlug(models.Model):
class Entrance(TroggleModel): class Entrance(TroggleModel):
name = models.CharField(max_length=100, blank=True, null=True)
entrance_description = models.TextField(blank=True, null=True)
explorers = models.TextField(blank=True, null=True)
map_description = models.TextField(blank=True, null=True)
location_description = models.TextField(blank=True, null=True)
lastvisit = models.TextField(blank=True, null=True)
approach = models.TextField(blank=True, null=True)
underground_description = models.TextField(blank=True, null=True)
photo = models.TextField(blank=True, null=True)
MARKING_CHOICES = ( MARKING_CHOICES = (
("P", "Paint"), ("P", "Paint"),
("P?", "Paint (?)"), ("P?", "Paint (?)"),
@ -286,25 +279,34 @@ class Entrance(TroggleModel):
("S?", "Spit (?)"), ("S?", "Spit (?)"),
("U", "Unmarked"), ("U", "Unmarked"),
("?", "Unknown"), ("?", "Unknown"),
) )
marking = models.CharField(max_length=2, choices=MARKING_CHOICES)
marking_comment = models.TextField(blank=True, null=True)
FINDABLE_CHOICES = (("?", "To be confirmed ..."), ("S", "Coordinates"), ("L", "Lost"), ("R", "Refindable")) FINDABLE_CHOICES = (("?", "To be confirmed ..."), ("S", "Coordinates"), ("L", "Lost"), ("R", "Refindable"))
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)
easting = models.TextField(blank=True, null=True)
entrance_description = models.TextField(blank=True, null=True)
exact_station = models.TextField(blank=True, null=True)
explorers = models.TextField(blank=True, null=True)
filename = models.CharField(max_length=200)
findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True) findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True)
findability_description = models.TextField(blank=True, null=True) findability_description = models.TextField(blank=True, null=True)
alt = models.TextField(blank=True, null=True) lastvisit = models.TextField(blank=True, null=True)
northing = models.TextField(blank=True, null=True)
easting = models.TextField(blank=True, null=True)
lat_wgs84 = models.TextField(blank=True, null=True) lat_wgs84 = models.TextField(blank=True, null=True)
location_description = models.TextField(blank=True, null=True)
long_wgs84 = models.TextField(blank=True, null=True) long_wgs84 = models.TextField(blank=True, null=True)
tag_station = models.TextField(blank=True, null=True) map_description = models.TextField(blank=True, null=True)
exact_station = models.TextField(blank=True, null=True) marking = models.CharField(max_length=2, choices=MARKING_CHOICES)
other_station = models.TextField(blank=True, null=True) marking_comment = models.TextField(blank=True, null=True)
name = models.CharField(max_length=100, blank=True, null=True)
northing = models.TextField(blank=True, null=True)
other_description = models.TextField(blank=True, null=True) other_description = models.TextField(blank=True, null=True)
bearings = models.TextField(blank=True, null=True) other_station = models.TextField(blank=True, null=True)
photo = models.TextField(blank=True, null=True)
tag_station = models.TextField(blank=True, null=True)
underground_description = models.TextField(blank=True, null=True)
url = models.CharField(max_length=200, blank=True, null=True) url = models.CharField(max_length=200, blank=True, null=True)
filename = models.CharField(max_length=200)
cached_primary_slug = models.CharField(max_length=200, blank=True, null=True)
class Meta: class Meta:
ordering = ["caveandentrance__entrance_letter"] ordering = ["caveandentrance__entrance_letter"]
@ -393,6 +395,9 @@ class Entrance(TroggleModel):
return res return res
def slug(self): 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_primary_slug: if not self.cached_primary_slug:
primarySlugs = self.entranceslug_set.filter(primary=True) primarySlugs = self.entranceslug_set.filter(primary=True)
if primarySlugs: if primarySlugs:

View File

@ -483,7 +483,15 @@ def ent(request, cave_id, ent_letter):
}, },
) )
def cave_debug(request):
ents = Entrance.objects.all()
#slugs = self.entranceslug_set.filter()
return render(
request,
"cave_debug.html",
{"ents": ents},
)
# def entranceSlug(request, slug): # def entranceSlug(request, slug):
# '''This seems to be a fossil, but I am not sure... # '''This seems to be a fossil, but I am not sure...
# ''' # '''

View File

@ -373,7 +373,8 @@ def readentrance(filename):
# need to cope with duplicates # need to cope with duplicates
message = f" ! FAILED to get precisely one ENTRANCE when updating using: cave_entrance/{filename}" message = f" ! FAILED to get precisely one ENTRANCE when updating using: cave_entrance/{filename}"
DataIssue.objects.create(parser="caves", message=message, url=f"/cave/{slug}/edit/") DataIssue.objects.create(parser="caves", 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, primary=primary)
kents = EntranceSlug.objects.all().filter(entrance=e, slug=slug)
for k in kents: for k in kents:
message = " ! - DUPLICATE in db. entrance:" + str(k.entrance) + ", slug:" + str(k.slug()) message = " ! - DUPLICATE in db. entrance:" + str(k.entrance) + ", slug:" + str(k.slug())
DataIssue.objects.create(parser="caves", message=message, url=f"/cave/{slug}/edit/") DataIssue.objects.create(parser="caves", message=message, url=f"/cave/{slug}/edit/")
@ -509,7 +510,7 @@ def readcave(filename):
newArea.save() newArea.save()
areas_xslug[area_slug] = newArea areas_xslug[area_slug] = newArea
c.area.add(newArea) c.area.add(newArea)
primary = True primary = True # this sets the first thing we find to be primary=True and all the others =False
for slug in slugs: for slug in slugs:
if slug in caves_xslug: if slug in caves_xslug:
cs = caves_xslug[slug] cs = caves_xslug[slug]

36
templates/cave_debug.html Normal file
View File

@ -0,0 +1,36 @@
{% extends "base.html" %}
{% block title %}DEBUG page
<!-- cave_debug.html - this text visible because this template has been included -->
{% endblock %}
{% block content %}
<h2 id="cmult">Entrances</h2>
<table>
<tr><th>ent</th>
<th>cached_primary_slug</th>
<th>N slugs</th>
<th>slugs</th>
</tr>
{% for ent in ents %}
<tr>
<td>
{{ent}}
</td>
<td>
{{ent.cached_primary_slug}}
</td>
<td>
{{ent.entranceslug_set.all|length }}
</td>
<td>
{% for s in ent.entranceslug_set.all %}
{{s.slug}},
{% endfor %}
</td>
{% endfor %}
</table>
{% endblock %}

View File

@ -8,7 +8,7 @@
{% include 'html_editor_pop_ups.html' %} {% include 'html_editor_pop_ups.html' %}
<h2>{{message}}</h2> <h2>{{message}}</h2>
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
<table>{{ form }}<!--1-->{{caveAndEntranceFormSet}}<!--2--></table> <table>{{ form }}<!-- begin caveAndEntranceFormSet-->{{caveAndEntranceFormSet}}<!--end caveAndEntranceFormSet--></table>
<p><input type="submit" value="Submit" /></p> <p><input type="submit" value="Submit" /></p>
</form> </form>

View File

@ -5,7 +5,7 @@ from django.urls import include, path, re_path
from troggle.core.views import statistics, survex from troggle.core.views import statistics, survex
from troggle.core.views.auth import expologin, expologout from troggle.core.views.auth import expologin, expologout
from troggle.core.views.caves import (cave3d, caveEntrance, caveindex, from troggle.core.views.caves import (cave3d, caveEntrance, caveindex,
cavepage, caveQMs, edit_cave, cavepage, caveQMs, edit_cave, cave_debug,
edit_entrance, get_entrances, qm) edit_entrance, get_entrances, qm)
from troggle.core.views.drawings import dwgallfiles, dwgfilesingle from troggle.core.views.drawings import dwgallfiles, dwgfilesingle
from troggle.core.views.editor_helpers import image_selector, new_image_form from troggle.core.views.editor_helpers import image_selector, new_image_form
@ -133,6 +133,7 @@ trogglepatterns = [
re_path(r'^getEntrances/(?P<caveslug>.*)', get_entrances, name = "get_entrances"), # used internally ? re_path(r'^getEntrances/(?P<caveslug>.*)', get_entrances, name = "get_entrances"), # used internally ?
# Cave description pages # Cave description pages
path('cave_debug', cave_debug, name="cave_debug"),
re_path(r'^newcave/$', edit_cave, name="newcave"), re_path(r'^newcave/$', edit_cave, name="newcave"),
re_path(r'^cave/3d/(?P<cave_id>[^/]+)$', cave3d, name="cave3d"), re_path(r'^cave/3d/(?P<cave_id>[^/]+)$', cave3d, name="cave3d"),