Fixed QM report for survex-imported QMs

This commit is contained in:
Philip Sargent
2022-07-05 20:24:51 +03:00
parent 96101252bd
commit 2bd617b543
6 changed files with 65 additions and 21 deletions

View File

@@ -178,12 +178,6 @@ class Cave(TroggleModel):
return str(self.slug())
def get_QMs(self):
'''Does not work because found_by is a string == cave_slug not an object identifier
This chnage was made to remove tricky __get_attribute__ code whihc is hard for
most folks to maintain and is not really necessary. Need to do a proper search for the cave.
Seems pretty broken - all needs re-doing more cleanly.
'''
#return QM.objects.filter(found_by__cave_slug=self.slug)
return QM.objects.filter(cave=self)
@@ -484,7 +478,6 @@ class LogbookEntry(TroggleModel):
class QM(TroggleModel):
"""This is based on qm.csv in trunk/expoweb/1623/204 which has the fields:
"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment"
Note that there is NO LINK TO THE CAVE that the QM is in !
"""
cave = models.ForeignKey(Cave, related_name='QMs',blank=True, null=True,on_delete=models.SET_NULL )
found_by = models.ForeignKey(LogbookEntry, related_name='QMs_found',blank=True, null=True,on_delete=models.SET_NULL )
@@ -511,20 +504,25 @@ class QM(TroggleModel):
def code(self):
if self.found_by:
return "%s-%s-%s" % (str(self.found_by.cave_slug)[6:], self.found_by.date.year, self.number)
return f'{str(self.found_by.cave_slug)[5:]}-{self.found_by.date.year}-{self.number}'
else:
return "%s" % (self.number)
return f'{self.cave.slug()[5:]}-xxxx-{self.number}'
def get_absolute_url(self):
if self.found_by:
qmyear = self.found_by.date.year
else:
qmyear = "1986" # HACK to check if other bits work
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
return urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.cave.slug(),'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}))
return urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.cave.slug(),'year':qmyear,'qm_id':self.number,'grade':self.grade}))
def get_next_by_id(self):
return QM.objects.get(id=self.id+1)
def get_previous_by_id(self):
return QM.objects.get(id=self.id-1)
# def wiki_link(self):
# return "%s%s%s" % ('[[QM:',self.code(),']]')

View File

@@ -467,7 +467,7 @@ def get_entrances(request, caveslug):
return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
def caveQMs(request, slug):
'''Lists the QMs on a particular cave
'''Lists all the QMs on a particular cave
relies on the template to find all the QMs for the cave specified in the slug, e.g. '1623-161'
Now working in July 2022
'''
@@ -482,7 +482,9 @@ def caveQMs(request, slug):
return render(request,'cave_qms.html', {'cave': cave})
def qm(request,cave_id,qm_id,year,grade=None):
'''Not checked, tested or revised in 2022
'''Reports on one specific QM
Fixed and working July 2022, for both CSV imported QMs and for survex-imported QMs,
need refactoring though.
'''
year=int(year)
try:
@@ -493,6 +495,8 @@ def qm(request,cave_id,qm_id,year,grade=None):
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves })
except QM.DoesNotExist:
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=}'})
# Ouch, this does not look like what we want to do. We need to replace this with something better.
url=urllib.parse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id)
if grade:
@@ -500,10 +504,11 @@ def qm(request,cave_id,qm_id,year,grade=None):
return HttpResponseRedirect(url)
def get_qms(request, caveslug):
'''Not checked, tested or revised in 2022
'''Does not crash, but just returns a text list of the entrances for a cave.
Used internally by the JSON export code? Archeology required..
'''
try:
cave = Cave.objects.get(caveslug__slug = caveslug)
except:
return render(request,'errors/badslug.html', {'badslug': caveslug})
return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
return render(request,'options.html', {"items": [(q.slug(), q.slug()) for q in cave.QMs()]})