forked from expo/troggle
QM reports all working
This commit is contained in:
parent
7dc3cc3b91
commit
d3572e18c3
@ -505,7 +505,7 @@ class QM(TroggleModel):
|
|||||||
return f'{self.code()}'
|
return f'{self.code()}'
|
||||||
|
|
||||||
def code(self):
|
def code(self):
|
||||||
return f'{str(self.found_by.cave_slug)[5:]}-{self.expoyear}-{self.blockname}{self.number}{self.grade}'
|
return f'{str(self.cave.slug())[5:]}-{self.expoyear}-{self.blockname}{self.number}{self.grade}'
|
||||||
|
|
||||||
def newslug(self):
|
def newslug(self):
|
||||||
qmslug = f'{str(self.cave)}-{self.expoyear}-{self.blockname}{self.number}{self.grade}'
|
qmslug = f'{str(self.cave)}-{self.expoyear}-{self.blockname}{self.number}{self.grade}'
|
||||||
|
@ -485,43 +485,46 @@ def qm(request,cave_id,qm_id,year,grade=None, blockname=None):
|
|||||||
'''Reports on one specific QM
|
'''Reports on one specific QM
|
||||||
Fixed and working July 2022, for both CSV imported QMs
|
Fixed and working July 2022, for both CSV imported QMs
|
||||||
needs refactoring though.
|
needs refactoring though.
|
||||||
For survex-imported QMs we are not getting unique objects returned, so the query needs fixing.
|
|
||||||
|
290 has several QMS with the same number, grade, year (2108) and first 8 chars of the survexblock. This crashes things.
|
||||||
'''
|
'''
|
||||||
year=int(year)
|
year=int(year)
|
||||||
|
|
||||||
if blockname == 'None':
|
if blockname == '':
|
||||||
# CSV import QMs, use old technique
|
# CSV import QMs, use old technique
|
||||||
try:
|
try:
|
||||||
c=getCave(cave_id)
|
c=getCave(cave_id)
|
||||||
manyqms=c.get_QMs()
|
manyqms=c.get_QMs()
|
||||||
qm=manyqms.get(number=qm_id,found_by__date__year=year, found_by__cave_slug=c.slug())
|
qm=manyqms.get(number=qm_id,expoyear=year)
|
||||||
return render(request,'qm.html', {'qm': qm})
|
return render(request,'qm.html', {'qm': qm})
|
||||||
except QM.DoesNotExist:
|
except QM.DoesNotExist:
|
||||||
|
raise
|
||||||
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# survex import QMs, need to disambiguate with blockname
|
|
||||||
# slug = f'{str(self.cave)}-{self.found_by.date.year}-{self.blockname}{self.number}{self.grade}'
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qmslug = f'{cave_id}-{year}-{blockname=}{qm_id}{grade}'
|
qmslug = f'{cave_id}-{year}-{blockname=}{qm_id}{grade}'
|
||||||
c=getCave(cave_id)
|
c=getCave(cave_id)
|
||||||
manyqms=c.get_QMs()
|
manyqms=c.get_QMs()
|
||||||
qm=manyqms.get(found_by__date__year=year, blockname=blockname, number=qm_id, grade=grade)
|
qmqs=manyqms.filter(expoyear=year, blockname=blockname, number=qm_id, grade=grade)
|
||||||
if qm:
|
if len(qmqs) > 1:
|
||||||
print(qm, f'{qmslug=}:{cave_id=} {year=} {qm_id=} {blockname=} {qm.expoyear=}')
|
for q in qmqs:
|
||||||
return render(request,'qm.html', {'qm': qm})
|
print(qmqs)
|
||||||
|
message = f'Multiple QMs with the same cave, year, number, grade AND first 8 chars of the survexblock name. Fix this in the survex file(s). {cave_id=} {year=} {qm_id=} {blockname=}'
|
||||||
|
return render(request,'errors/generic.html', {'message': message})
|
||||||
else:
|
else:
|
||||||
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
qm=qmqs.get(expoyear=year, blockname=blockname, number=qm_id, grade=grade)
|
||||||
|
if qm:
|
||||||
|
print(qm, f'{qmslug=}:{cave_id=} {year=} {qm_id=} {blockname=} {qm.expoyear=}')
|
||||||
|
return render(request,'qm.html', {'qm': qm})
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
||||||
except MultipleObjectsReturned:
|
except MultipleObjectsReturned:
|
||||||
if len(qm) > 1:
|
raise
|
||||||
for q in qm:
|
|
||||||
print(qm)
|
|
||||||
return render(request,'qm.html', {'qm': qm[0]})
|
|
||||||
else:
|
|
||||||
return render(request,'qm.html', {'qm': qm})
|
|
||||||
except QM.DoesNotExist:
|
except QM.DoesNotExist:
|
||||||
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
raise
|
||||||
|
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
||||||
|
|
||||||
|
|
||||||
def get_qms(request, caveslug):
|
def get_qms(request, caveslug):
|
||||||
|
@ -27,7 +27,11 @@ def parseCaveQMs(cave,inputFile):
|
|||||||
have the passage name, e.g. in 204/qm.csv
|
have the passage name, e.g. in 204/qm.csv
|
||||||
C2000-204-39 B Tree Pitch in Cave Tree treeumphant.28 Gosser Streamway
|
C2000-204-39 B Tree Pitch in Cave Tree treeumphant.28 Gosser Streamway
|
||||||
The CSV file does not have the exact date for the QM, only the year, so links to
|
The CSV file does not have the exact date for the QM, only the year, so links to
|
||||||
survex files might be ambiguous. But potentially useful?"""
|
survex files might be ambiguous. But potentially useful?
|
||||||
|
|
||||||
|
Much of this code assumes that QMs are edited using troggle. This is not done so this code can be deleted.
|
||||||
|
All QMs are created afresh and this is all only run once on import on a fresh database.
|
||||||
|
"""
|
||||||
|
|
||||||
if cave=='204-steinBH':
|
if cave=='204-steinBH':
|
||||||
try:
|
try:
|
||||||
@ -59,7 +63,7 @@ def parseCaveQMs(cave,inputFile):
|
|||||||
return nqms
|
return nqms
|
||||||
|
|
||||||
#qmPath = settings.EXPOWEB+inputFile
|
#qmPath = settings.EXPOWEB+inputFile
|
||||||
qmPath = os.path.join(settings.EXPOWEB, inputFile)
|
qmPath = os.path.join(settings.EXPOWEB, inputFile) # why not use the pathlib stuff ?
|
||||||
|
|
||||||
qmCSVContents = open(qmPath,'rU')
|
qmCSVContents = open(qmPath,'rU')
|
||||||
dialect=csv.Sniffer().sniff(qmCSVContents.read())
|
dialect=csv.Sniffer().sniff(qmCSVContents.read())
|
||||||
@ -73,20 +77,22 @@ def parseCaveQMs(cave,inputFile):
|
|||||||
n += 1
|
n += 1
|
||||||
year=int(line[0][1:5])
|
year=int(line[0][1:5])
|
||||||
logslug = f'PH_{int(year)}_{int(n):02d}'
|
logslug = f'PH_{int(year)}_{int(n):02d}'
|
||||||
|
# logbook placeholder code was previously here. No longer needed.
|
||||||
#check if placeholder exists for given year, create it if not
|
#check if placeholder exists for given year, create it if not
|
||||||
message = " ! - "+ str(year) + " logbook: placeholder entry for '" + cave + "' created. DUMMY EXPEDITION ID. Should be re-attached to the actual trip."
|
# message = " ! - "+ str(year) + " logbook: placeholder entry for '" + cave + "' created. DUMMY EXPEDITION ID. Should be re-attached to the actual trip."
|
||||||
if cave=='204-steinBH':
|
# if cave=='204-steinBH':
|
||||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="204", title="placeholder for QMs in 204", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date(year, 1, 1),"cave_slug":str(steinBr), "slug": logslug})
|
# placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="204", title="placeholder for QMs in 204", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date(year, 1, 1),"cave_slug":str(steinBr), "slug": logslug})
|
||||||
elif cave=='234-Hauch':
|
# elif cave=='234-Hauch':
|
||||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="234", title="placeholder for QMs in 234", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date(year, 1, 1),"cave_slug":str(hauchHl)})
|
# placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="234", title="placeholder for QMs in 234", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date(year, 1, 1),"cave_slug":str(hauchHl)})
|
||||||
# if hadToCreate:
|
# # if hadToCreate:
|
||||||
# print(message)
|
# # print(message)
|
||||||
# DataIssue.objects.create(parser='QMs', message=message)
|
# # DataIssue.objects.create(parser='QMs', message=message)
|
||||||
QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb")
|
QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb")
|
||||||
newQM = QM()
|
newQM = QM()
|
||||||
newQM.found_by=placeholder
|
# newQM.found_by=placeholder
|
||||||
newQM.number=QMnum
|
newQM.number=QMnum
|
||||||
newQM.cave = caveid
|
newQM.cave = caveid
|
||||||
|
newQM.blockname = ""
|
||||||
if line[1]=="Dig":
|
if line[1]=="Dig":
|
||||||
newQM.grade="D"
|
newQM.grade="D"
|
||||||
else:
|
else:
|
||||||
@ -94,12 +100,12 @@ def parseCaveQMs(cave,inputFile):
|
|||||||
newQM.area=line[2]
|
newQM.area=line[2]
|
||||||
newQM.location_description=line[3]
|
newQM.location_description=line[3]
|
||||||
|
|
||||||
# Troggle checks if QMs are completed by checking if they have a ticked_off_by trip.
|
# Troggle will in future (?! - written in 2006) check if QMs are completed by checking if they have a ticked_off_by trip.
|
||||||
# In the table, completion is indicated by the presence of a completion discription.
|
# In the table, completion is indicated by the presence of a completion discription.
|
||||||
newQM.completion_description=line[4]
|
newQM.completion_description=line[4]
|
||||||
newQM.nearest_station_description=line[5]
|
newQM.nearest_station_description=line[5]
|
||||||
if newQM.completion_description:
|
# if newQM.completion_description:
|
||||||
newQM.ticked_off_by=placeholder
|
# newQM.ticked_off_by=placeholder
|
||||||
|
|
||||||
newQM.comment=line[6]
|
newQM.comment=line[6]
|
||||||
try:
|
try:
|
||||||
@ -139,15 +145,16 @@ def parse_KH_QMs(kh, inputFile):
|
|||||||
if res:
|
if res:
|
||||||
res=res.groupdict()
|
res=res.groupdict()
|
||||||
year=int(res['year'])
|
year=int(res['year'])
|
||||||
|
# logbook placeholder code was previously here. No longer needed.
|
||||||
#check if placeholder exists for given year, create it if not
|
#check if placeholder exists for given year, create it if not
|
||||||
message = " ! - "+ str(year) + " logbook: placeholder entry for '161 KH' created. DUMMY EXPEDITION ID. Should be re-attached to the actual trip."
|
# message = " ! - "+ str(year) + " logbook: placeholder entry for '161 KH' created. DUMMY EXPEDITION ID. Should be re-attached to the actual trip."
|
||||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="161", title="placeholder for QMs in 161", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)})
|
# placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="161", title="placeholder for QMs in 161", text=message, entry_type="DUMMY", expedition_id=1, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)})
|
||||||
# if hadToCreate:
|
# # if hadToCreate:
|
||||||
# print(message)
|
# print(message)
|
||||||
# DataIssue.objects.create(parser='QMs', message=message)
|
# DataIssue.objects.create(parser='QMs', message=message)
|
||||||
lookupArgs={
|
lookupArgs={
|
||||||
# inadequate now that the sequence numbers are not unique for survex-parsed QMs
|
#'found_by':placeholder,
|
||||||
'found_by':placeholder,
|
'blockname': "",
|
||||||
'expoyear':year,
|
'expoyear':year,
|
||||||
'number':res['number'],
|
'number':res['number'],
|
||||||
'cave': kh,
|
'cave': kh,
|
||||||
@ -158,10 +165,10 @@ def parse_KH_QMs(kh, inputFile):
|
|||||||
'location_description':res['description']
|
'location_description':res['description']
|
||||||
}
|
}
|
||||||
instance, created = save_carefully(QM,lookupArgs,nonLookupArgs)
|
instance, created = save_carefully(QM,lookupArgs,nonLookupArgs)
|
||||||
if created:
|
# if created:
|
||||||
message = " ! - "+ instance.code() + " QM entry for '161 KH' created. "
|
# message = " ! - "+ instance.code() + " QM entry for '161 KH' created. "
|
||||||
print(message)
|
# print(message)
|
||||||
DataIssue.objects.create(parser='QMs', message=message)
|
# DataIssue.objects.create(parser='QMs', message=message)
|
||||||
nqms += 1
|
nqms += 1
|
||||||
return nqms
|
return nqms
|
||||||
|
|
||||||
|
@ -532,11 +532,7 @@ class LoadingSurvex():
|
|||||||
# we would have to create one. But that is not obligatory and no QMs loaded from CSVs have one
|
# we would have to create one. But that is not obligatory and no QMs loaded from CSVs have one
|
||||||
|
|
||||||
# Older troggle/CSV assumes a logbook entry 'found_by' for each QM, with a date.
|
# Older troggle/CSV assumes a logbook entry 'found_by' for each QM, with a date.
|
||||||
# We have a date from the survexfile. This is needed for the absolute_url resolution..
|
# We don't need this anymore so we don't need to create a placeholder logbook entry.
|
||||||
|
|
||||||
# We don't know if the survexfile has an associated logbook entry as there is no direct link
|
|
||||||
# so we create a dummy one anyway. We should make logbook entry links optional in QMs in future and
|
|
||||||
# remove this hack.
|
|
||||||
qmyear = str(survexblock.date)[:4]
|
qmyear = str(survexblock.date)[:4]
|
||||||
blockname = survexblock.name[:7]
|
blockname = survexblock.name[:7]
|
||||||
logslug = f'D{int(qmyear)}_{blockname}_{int(qm_no):03d}'
|
logslug = f'D{int(qmyear)}_{blockname}_{int(qm_no):03d}'
|
||||||
@ -548,27 +544,27 @@ class LoadingSurvex():
|
|||||||
place = "oops"
|
place = "oops"
|
||||||
|
|
||||||
|
|
||||||
message = f' ! - logbook dummy "{logslug}" {str(survexblock.date)[:11]} for cave "{caveslug}" created.'
|
# message = f' ! - logbook dummy "{logslug}" {str(survexblock.date)[:11]} for cave "{caveslug}" created.'
|
||||||
|
|
||||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=qmyear,
|
# placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=qmyear,
|
||||||
place=place,
|
# place=place,
|
||||||
title="placeholder for survex QM",
|
# title="placeholder for survex QM",
|
||||||
text=message,
|
# text=message,
|
||||||
entry_type="DUMMY",
|
# entry_type="DUMMY",
|
||||||
expedition_id=1,
|
# expedition_id=1,
|
||||||
defaults={"date": survexblock.date,"cave_slug":caveslug, "slug": logslug})
|
# defaults={"date": survexblock.date,"cave_slug":caveslug, "slug": logslug})
|
||||||
# print(insp+message)
|
# print(insp+message)
|
||||||
# DataIssue.objects.create(parser='survex', message=message)
|
# DataIssue.objects.create(parser='survex', message=message)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qm = QM.objects.create(number=qm_no,
|
qm = QM.objects.create(number=qm_no,
|
||||||
# nearest_station=a_survex_station_object, # can be null
|
# nearest_station=a_survex_station_object, # can be null
|
||||||
nearest_station_description=qm_resolve_station,
|
nearest_station_description=qm_resolve_station,
|
||||||
nearest_station_name=qm_nearest,
|
nearest_station_name=qm_nearest,
|
||||||
grade=qm_grade.upper(),
|
grade=qm_grade.upper(),
|
||||||
location_description=qm_notes,
|
location_description=qm_notes,
|
||||||
blockname = blockname, # only set for survex-imported QMs
|
blockname = blockname, # only set for survex-imported QMs
|
||||||
found_by = placeholder,
|
# found_by = placeholder,
|
||||||
expoyear = str(survexblock.date.year),
|
expoyear = str(survexblock.date.year),
|
||||||
cave = survexblock.survexfile.cave)
|
cave = survexblock.survexfile.cave)
|
||||||
qm.save
|
qm.save
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
{% if qm.cave %}
|
{% if qm.cave %}
|
||||||
<a href="{% url 'caveQMs' qm.cave|safe %}">{{ qm.cave|safe }} QMs</a> <br>
|
<a href="{% url 'caveQMs' qm.cave|safe %}">{{ qm.cave|safe }} QMs</a> <br>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if qm.found_by.cave %}
|
{% if qm.cave %}
|
||||||
<a href="{% url 'caveQMs' qm.found_by.cave|safe %}">{{ qm.found_by.cave|safe }} QMs</a> <br>
|
<a href="{% url 'caveQMs' qm.cave|safe %}">{{ qm.cave|safe }} QMs</a> <br>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="/{{ qm.cave.url }}">{{ qm.cave|safe }} cave description</a>
|
<a href="/{{ qm.cave.url }}">{{ qm.cave|safe }} cave description</a>
|
||||||
@ -49,8 +49,10 @@
|
|||||||
<h3>Grade</h3>
|
<h3>Grade</h3>
|
||||||
{{qm.grade}}
|
{{qm.grade}}
|
||||||
|
|
||||||
|
{% if qm.found_by %}
|
||||||
<h3>Creation</h3>
|
<h3>Creation</h3>
|
||||||
Found by <a href="{{qm.found_by.get_absolute_url}}">{{qm.found_by}}</a> on {{qm.found_by.date}}.
|
Found by <a href="{{qm.found_by.get_absolute_url}}">{{qm.found_by}}</a> on {{qm.found_by.date}}.
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<h3>Completion</h3>
|
<h3>Completion</h3>
|
||||||
{% if ticked_off_by %}
|
{% if ticked_off_by %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user