From 3011e7b11428558360ba2718b8e3d9947607b992 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 16 Mar 2023 21:06:52 +0000 Subject: [PATCH] Adding QM JSON export --- core/models/logbooks.py | 10 ++++++---- core/views/logbooks.py | 5 ++++- parsers/survex.py | 24 +++++++++++++++++------- templates/core/QMs_json_list.html | 5 +++++ templates/qm.html | 11 +++++++++++ urls.py | 3 ++- 6 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 templates/core/QMs_json_list.html diff --git a/core/models/logbooks.py b/core/models/logbooks.py index 5f83059..fbe7e49 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -141,6 +141,9 @@ class QM(TroggleModel): All the stuff handling TICK QMs is INCOMPLETE """ + number = models.IntegerField( + help_text="this is the sequential number in the year, only unique for CSV imports", + ) cave = models.ForeignKey("Cave", related_name="QMs", blank=True, null=True, on_delete=models.SET_NULL) block = models.ForeignKey("SurvexBlock", null=True, on_delete=models.SET_NULL) # only for QMs from survex files blockname = models.TextField(blank=True, null=True) # NB truncated copy of survexblock name with last char added @@ -156,9 +159,7 @@ class QM(TroggleModel): ticked_off_by = models.ForeignKey( LogbookEntry, related_name="QMs_ticked_off", blank=True, null=True, on_delete=models.SET_NULL ) # unused, ever?! - number = models.IntegerField( - help_text="this is the sequential number in the year, only unique for CSV imports", - ) + GRADE_CHOICES = ( ("A", "A: Large obvious lead"), ("B", "B: Average lead"), @@ -170,7 +171,8 @@ class QM(TroggleModel): grade = models.CharField(max_length=1, choices=GRADE_CHOICES) location_description = models.TextField(blank=True) nearest_station_description = models.CharField(max_length=400, blank=True, null=True) - nearest_station_name = models.CharField(max_length=200, blank=True, null=True) + nearest_station_name = models.CharField(max_length=200, blank=True, null=True) + resolution_station_name = models.CharField(max_length=200, blank=True, null=True) nearest_station = models.ForeignKey("SurvexStation", blank=True, null=True, on_delete=models.SET_NULL) area = models.CharField(max_length=100, blank=True, null=True) completion_description = models.TextField(blank=True, null=True) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 626153c..2f89963 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -3,7 +3,7 @@ from django.shortcuts import render from django.views.generic.list import ListView import troggle.settings as settings -from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry +from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry, QM from troggle.core.models.survex import SurvexBlock, SurvexFile from troggle.core.models.troggle import Expedition, Person from troggle.core.models.wallets import Wallet @@ -144,6 +144,9 @@ class Expeditions_jsonListView(ListView): template_name = "core/expeditions_json_list.html" model = Expedition +class QMs_jsonListView(ListView): + template_name = "core/QMs_json_list.html" + model = QM def person( request, diff --git a/parsers/survex.py b/parsers/survex.py index 1849fce..d8eda23 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -1311,7 +1311,8 @@ class LoadingSurvex: # create a short, hopefully-unique name for this block to be used in the QM id blockname = survexblock.name[:6] + survexblock.name[-1:] # logslug = f'D{int(qmyear)}_{blockname}_{int(qm_no):03d}' - + qm_ticked = False # default + qm_no = qmline.group(1) # this is NOT unique across multiple survex files qm_grade = qmline.group(2).strip().upper() # TICK or [a-dA-DvVxX?] if qm_grade == "TICK": @@ -1330,13 +1331,20 @@ class LoadingSurvex: # if qmline.group(4): # qm_nearest = qm_nearest + "." + qmline.group(4) - qm_resolve_station = qmline.group(4) + resolution_station_name = qmline.group(4) + if (resolution_station_name=="-"): + pass + else: + qm_ticked = True + print(f"{survexblock.survexfile.cave} {survexblock}:{qm_no}{qm_grade} {qmline.group(4)}", file=sys.stderr) + if resolution_station_name: + qm_ticked = True # if qmline.group(6) and qmline.group(6) != "-": - # qm_resolve_station = qmline.group(6) + # resolution_station_name = qmline.group(6) # if qmline.group(7): - # qm_resolve_station = qm_resolve_station + "." + qmline.group(7) + # resolution_station_name = resolution_station_name + "." + qmline.group(7) # else: - # qm_resolve_station = "" + # resolution_station_name = "" qm_notes = qmline.group(5) # qm_notes = qmline.group(8) @@ -1364,8 +1372,9 @@ class LoadingSurvex: qm = QM.objects.create( number=qm_no, # nearest_station=a_survex_station_object, # can be null - nearest_station_description=qm_resolve_station, + resolution_station_name=resolution_station_name, nearest_station_name=qm_nearest, + ticked=qm_ticked, grade=qm_grade.upper(), location_description=qm_notes, block=survexblock, # only set for survex-imported QMs @@ -1378,8 +1387,9 @@ class LoadingSurvex: qms = QM.objects.filter( number=qm_no, # nearest_station=a_survex_station_object, # can be null - nearest_station_description=qm_resolve_station, + resolution_station_name=resolution_station_name, nearest_station_name=qm_nearest, + ticked=qm_ticked, grade=qm_grade.upper(), location_description=qm_notes, block=survexblock, # only set for survex-imported QMs diff --git a/templates/core/QMs_json_list.html b/templates/core/QMs_json_list.html new file mode 100644 index 0000000..3c5b1ba --- /dev/null +++ b/templates/core/QMs_json_list.html @@ -0,0 +1,5 @@ +{% extends "baseapi.html" %} +{% block content %}{ +{% for qm in object_list %}{% if not forloop.last %}"{{qm.number}}": + ["{{qm.expoyear}}","{{qm.cave}}","{{qm.blockname}}","QM{{qm.number}}","{{qm.grade}}","{{qm.get_absolute_url}}"],{% endif %}{% if forloop.last %}"{{qm.number}}": ["{{qm.expoyear}}","{{qm.cave}}","{{qm.blockname}}","QM{{qm.number}}","{{qm.grade}}","{{qm.get_absolute_url}}"]{% endif %} +{% endfor %} }{% endblock %} \ No newline at end of file diff --git a/templates/qm.html b/templates/qm.html index 44aa6dc..d701463 100644 --- a/templates/qm.html +++ b/templates/qm.html @@ -53,6 +53,17 @@ {{qm.block.date}} {{qm.block}}.svx {% endif %} +{% if qm.ticked %} +

Ticked

+This QM is TICKED +{% endif %} + +{% if qm.resolution_station_name %} +

resolution_station_name

+{{qm.resolution_station_name}} + +{% endif %} +

Location

{% if qm.block %} Survex block: {{qm.blockname}} diff --git a/urls.py b/urls.py index d0d49a2..e257832 100644 --- a/urls.py +++ b/urls.py @@ -12,7 +12,7 @@ from troggle.core.views.editor_helpers import image_selector, new_image_form from troggle.core.views.expo import (editexpopage, expofiles_redirect, expofilessingle, expopage, map, mapfile, mediapage, spider) -from troggle.core.views.logbooks import (Expeditions_jsonListView, +from troggle.core.views.logbooks import (QMs_jsonListView, Expeditions_jsonListView, Expeditions_tsvListView, expedition, get_logbook_entries, get_people, logbookentry, notablepersons, person, @@ -120,6 +120,7 @@ trogglepatterns = [ re_path(r'^expedition/(\d+)$', expedition, name="expedition"), re_path(r'^api/expeditions_tsv$', Expeditions_tsvListView.as_view()), re_path(r'^api/expeditions_json$', Expeditions_jsonListView.as_view()), + re_path(r'^api/QMs_json$', QMs_jsonListView.as_view()), # Logbook entries re_path(r'^logbookentry/(?P.*)/(?P.*)/?$', logbookentry,name="logbookentry"),