From 6ca5d5bfa83ef59a6ecc93a6ef9b12abf137be38 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 28 Mar 2023 15:37:25 +0100 Subject: [PATCH] debug ent report --- core/models/caves.py | 75 +++++++++++++++++++++------------------ core/views/caves.py | 10 +++++- parsers/caves.py | 5 +-- templates/cave_debug.html | 36 +++++++++++++++++++ templates/editcave.html | 2 +- urls.py | 3 +- 6 files changed, 91 insertions(+), 40 deletions(-) create mode 100644 templates/cave_debug.html diff --git a/core/models/caves.py b/core/models/caves.py index 0001814..bae8eb5 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -74,30 +74,32 @@ class CaveAndEntrance(models.Model): def __str__(self): 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): # too much here perhaps, - official_name = models.CharField(max_length=160) 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_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) - 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) - depth = models.CharField(max_length=100, blank=True, null=True) - extent = models.CharField(max_length=100, blank=True, null=True) + notes = models.TextField(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 - 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) - filename = models.CharField(max_length=200) # class Meta: # unique_together = (("area", "kataster_number"), ("area", "unofficial_number")) @@ -267,15 +269,6 @@ class EntranceSlug(models.Model): 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 = ( ("P", "Paint"), ("P?", "Paint (?)"), @@ -286,25 +279,34 @@ class Entrance(TroggleModel): ("S?", "Spit (?)"), ("U", "Unmarked"), ("?", "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")) + 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_description = models.TextField(blank=True, null=True) - alt = models.TextField(blank=True, null=True) - northing = models.TextField(blank=True, null=True) - easting = models.TextField(blank=True, null=True) + lastvisit = 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) - tag_station = models.TextField(blank=True, null=True) - exact_station = models.TextField(blank=True, null=True) - other_station = models.TextField(blank=True, null=True) + map_description = models.TextField(blank=True, null=True) + marking = models.CharField(max_length=2, choices=MARKING_CHOICES) + 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) - 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) - filename = models.CharField(max_length=200) - cached_primary_slug = models.CharField(max_length=200, blank=True, null=True) class Meta: ordering = ["caveandentrance__entrance_letter"] @@ -393,6 +395,9 @@ class Entrance(TroggleModel): return res 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: primarySlugs = self.entranceslug_set.filter(primary=True) if primarySlugs: diff --git a/core/views/caves.py b/core/views/caves.py index af59bc9..81a1e8e 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -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): # '''This seems to be a fossil, but I am not sure... # ''' diff --git a/parsers/caves.py b/parsers/caves.py index f12cd84..feb8fbb 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -373,7 +373,8 @@ def readentrance(filename): # need to cope with duplicates 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/") - 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: message = " ! - DUPLICATE in db. entrance:" + str(k.entrance) + ", slug:" + str(k.slug()) DataIssue.objects.create(parser="caves", message=message, url=f"/cave/{slug}/edit/") @@ -509,7 +510,7 @@ def readcave(filename): newArea.save() areas_xslug[area_slug] = 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: if slug in caves_xslug: cs = caves_xslug[slug] diff --git a/templates/cave_debug.html b/templates/cave_debug.html new file mode 100644 index 0000000..be0ce20 --- /dev/null +++ b/templates/cave_debug.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} +{% block title %}DEBUG page + +{% endblock %} + +{% block content %} + +

Entrances

+ + + + + + +{% for ent in ents %} + + + + + + +{% endfor %} +
entcached_primary_slugN slugsslugs
+ {{ent}} + + {{ent.cached_primary_slug}} + + {{ent.entranceslug_set.all|length }} + + {% for s in ent.entranceslug_set.all %} + {{s.slug}}, + {% endfor %} +
+ + +{% endblock %} diff --git a/templates/editcave.html b/templates/editcave.html index 75033b3..640412a 100644 --- a/templates/editcave.html +++ b/templates/editcave.html @@ -8,7 +8,7 @@ {% include 'html_editor_pop_ups.html' %}

{{message}}

{% csrf_token %} - {{ form }}{{caveAndEntranceFormSet}}
+ {{ form }}{{caveAndEntranceFormSet}}

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