QM report pages now not crashing, working..

This commit is contained in:
Philip Sargent 2022-07-05 15:38:23 +03:00
parent 33eb91346c
commit 779afc2f2a
6 changed files with 41 additions and 8 deletions

View File

@ -183,7 +183,9 @@ class Cave(TroggleModel):
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(found_by__cave_slug=self.slug)
return QM.objects.filter(cave=self)
def new_QM_number(self, year=datetime.date.today().year):
"""Given a cave and the current year, returns the next QM number."""
@ -482,7 +484,9 @@ 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 )
ticked_off_by = models.ForeignKey(LogbookEntry, related_name='QMs_ticked_off',blank=True, null=True,on_delete=models.SET_NULL)
number = models.IntegerField(help_text="this is the sequential number in the year", )
@ -503,7 +507,7 @@ class QM(TroggleModel):
comment=models.TextField(blank=True,null=True)
def __str__(self):
return f'{self.nearest_station_name}, {self.code()}-{self.grade}'
return f'{self.code()}'
def code(self):
if self.found_by:
@ -513,7 +517,7 @@ class QM(TroggleModel):
def get_absolute_url(self):
#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.found_by.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':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}))
def get_next_by_id(self):
return QM.objects.get(id=self.id+1)

View File

@ -467,6 +467,10 @@ 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
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
'''
try:
cave = Cave.objects.get(caveslug__slug = slug)
except:
@ -478,6 +482,8 @@ 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
'''
year=int(year)
try:
qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year)
@ -487,12 +493,15 @@ def qm(request,cave_id,qm_id,year,grade=None):
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves })
except QM.DoesNotExist:
# 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:
url += r'&grade=' + grade
return HttpResponseRedirect(url)
def get_qms(request, caveslug):
'''Not checked, tested or revised in 2022
'''
try:
cave = Cave.objects.get(caveslug__slug = caveslug)
except:

View File

@ -32,6 +32,7 @@ def parseCaveQMs(cave,inputFile):
if cave=='204-steinBH':
try:
steinBr=Cave.objects.get(official_name="Steinbrückenhöhle")
caveid = steinBr
except Cave.DoesNotExist:
message = f' ! - {qmPath} Steinbruckenhoehle is not in the database. Please run cave parser'
print(message)
@ -40,6 +41,7 @@ def parseCaveQMs(cave,inputFile):
elif cave=='234-Hauch':
try:
hauchHl=Cave.objects.get(official_name="Hauchhöhle")
caveid = hauchHl
except Cave.DoesNotExist:
message = f' ! - {qmPath} Hauchhoehle is not in the database. Please run cave parser'
print(message)
@ -48,6 +50,7 @@ def parseCaveQMs(cave,inputFile):
elif cave =='161-KH':
try:
kh=Cave.objects.get(official_name="Kaninchenhöhle")
caveid = kh
except Cave.DoesNotExist:
message = f' ! - {qmPath} KH is not in the database. Please run cave parser'
print(message)
@ -82,6 +85,7 @@ def parseCaveQMs(cave,inputFile):
newQM = QM()
newQM.found_by=placeholder
newQM.number=QMnum
newQM.cave = caveid
if line[1]=="Dig":
newQM.grade="D"
else:
@ -120,7 +124,7 @@ def parseCaveQMs(cave,inputFile):
continue
def parse_KH_QMs(kh, inputFile):
"""import QMs from the 1623-161 (Kaninchenh<EFBFBD>hle) html pages
"""import QMs from the 1623-161 (Kaninchenhohle) html pages, different format
"""
khQMs=open(os.path.join(settings.EXPOWEB, inputFile),'r')
khQMs=khQMs.readlines()
@ -140,6 +144,7 @@ def parse_KH_QMs(kh, inputFile):
'number':res['number']
}
nonLookupArgs={
'cave': kh,
'grade':res['grade'],
'nearest_station_name':res['nearest_station'],
'location_description':res['description']

View File

@ -1,11 +1,19 @@
<h2>Question marks for {{cave.kataster_number}} - {{cave.official_name|safe}} - {{cave.unofficial_number}}</h2>
<p>Note that QMs are only loaded for 1623-161, 1623-204 and 1623-234 as these are the only CSV files loaded by the import parser.
No QMs are loaded directly from the survex files (yet, as of July 2022).
<ul>
<li><a href="/cave/qms/1623-161">1623-161 QMs</a>
<li><a href="/cave/qms/1623-204">1623-204 QMs</a>
<li><a href="/cave/qms/1623-234">1623-234 QMs</a>
</ul>
<h3>Extant</h3>
<p>{% if cave.get_QMs %}
<ul id="cavelist">
{% for QM in cave.get_QMs %}
{% if QM.ticked_off_by %}
{% else %}
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a></li>
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a> {{QM.nearest_station_name}} :: {{QM.nearest_station_description}} <b>{{QM.cave}}</b></li>
{% endif %}
{% endfor %}
</ul>
@ -13,7 +21,7 @@
<ul>
{% for QM in cave.get_QMs %}
{% if QM.ticked_off_by %}
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a></li>
<li><a href="{{QM}}">{{QM}}</a> {{QM.nearest_station_name}} :: {{QM.nearest_station_description}} <b>{{QM.cave}}</b></li>
{% endif %}
{% endfor %}
</ul>

View File

@ -2,6 +2,13 @@
{% load link %}
{% block title %} QM: {{qm|safe}} {% endblock %}
{% block contentheader %}
<h3>QMs only available for these caves</h3>
<ul>
<li><a href="/cave/qms/1623-161">1623-161 QMs</a>
<li><a href="/cave/qms/1623-204">1623-204 QMs</a>
<li><a href="/cave/qms/1623-234">1623-234 QMs</a>
</ul>
<table id="cavepage">
<tr>
<th id="kat_no"><a href="{{qm.get_previous_by_id.get_absolute_url}}">Previous</a></th>

View File

@ -176,8 +176,8 @@ trogglepatterns = [
path('dwgdataraw/<path:path>', dwgfilesingle, name="dwgfilesingle"),
# QMs pages - must precede other /caves pages?
re_path(r'^cave/qms/([^/]+)/?$', caveQMs), # Broken- QMs have no proper link to cave id
re_path(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d*)(?P<grade>[ABCDX]?)?$', qm, name="qm"),
re_path(r'^cave/qms/([^/]+)/?$', caveQMs), # Being fixed, currently returns all QMs for all caves
re_path(r'^cave/qms/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d*)(?P<grade>[ABCDXV]?)?$', qm, name="qm"), # broken..
# Prospecting Guide document
re_path(r'^prospecting_guide/$', prospecting), # disabled. Bad links, incompatible image package use and very, very out of date.