2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

Adding QM JSON export

This commit is contained in:
Philip Sargent 2023-03-16 21:06:52 +00:00
parent 98066591da
commit 3011e7b114
6 changed files with 45 additions and 13 deletions

View File

@ -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"),
@ -171,6 +172,7 @@ class QM(TroggleModel):
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)
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)

View File

@ -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,

View File

@ -1311,6 +1311,7 @@ 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?]
@ -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

View File

@ -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 %}

View File

@ -53,6 +53,17 @@
{{qm.block.date}} <a href="/survexfile/{{qm.block.survexfile.path}}.svx">{{qm.block}}.svx</a>
{% endif %}
{% if qm.ticked %}
<h3>Ticked</h3>
This QM is TICKED
{% endif %}
{% if qm.resolution_station_name %}
<h3>resolution_station_name</h3>
{{qm.resolution_station_name}}
{% endif %}
<h3>Location</h3>
{% if qm.block %}
Survex block: {{qm.blockname}}

View File

@ -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<date>.*)/(?P<slug>.*)/?$', logbookentry,name="logbookentry"),