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 %} + +
ent | +cached_primary_slug | +N slugs | +slugs | +
---|---|---|---|
+ {{ent}} + | ++ {{ent.cached_primary_slug}} + | ++ {{ent.entranceslug_set.all|length }} + | ++ {% for s in ent.entranceslug_set.all %} + {{s.slug}}, + {% endfor %} + | + +{% endfor %} +