forked from expo/troggle
Not quite so broken QMs from survex files
This commit is contained in:
parent
2bd617b543
commit
0ea3ed1ef2
@ -498,15 +498,16 @@ class QM(TroggleModel):
|
||||
area = models.CharField(max_length=100,blank=True, null=True)
|
||||
completion_description = models.TextField(blank=True,null=True)
|
||||
comment=models.TextField(blank=True,null=True)
|
||||
blockname=models.TextField(blank=True,null=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.code()}'
|
||||
|
||||
def code(self):
|
||||
if self.found_by:
|
||||
return f'{str(self.found_by.cave_slug)[5:]}-{self.found_by.date.year}-{self.number}'
|
||||
return f'{str(self.found_by.cave_slug)[5:]}-{self.found_by.date.year}-{self.blockname}{self.number}{self.grade}'
|
||||
else:
|
||||
return f'{self.cave.slug()[5:]}-xxxx-{self.number}'
|
||||
return f'{self.cave.slug()[5:]}-xxxx-{self.blockname}{self.number}{self.grade}'
|
||||
|
||||
def get_absolute_url(self):
|
||||
if self.found_by:
|
||||
@ -514,7 +515,7 @@ class QM(TroggleModel):
|
||||
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':qmyear,'qm_id':self.number,'grade':self.grade}))
|
||||
return urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.cave.slug(),'year':qmyear, 'blockname':self.blockname,'qm_id':self.number,'grade':self.grade}))
|
||||
|
||||
|
||||
def get_next_by_id(self):
|
||||
|
@ -481,31 +481,31 @@ def caveQMs(request, slug):
|
||||
else:
|
||||
return render(request,'cave_qms.html', {'cave': cave})
|
||||
|
||||
def qm(request,cave_id,qm_id,year,grade=None):
|
||||
def qm(request,cave_id,qm_id,year,grade=None, blockname=""):
|
||||
'''Reports on one specific QM
|
||||
Fixed and working July 2022, for both CSV imported QMs and for survex-imported QMs,
|
||||
need refactoring though.
|
||||
needs refactoring though.
|
||||
'''
|
||||
year=int(year)
|
||||
|
||||
try:
|
||||
qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year)
|
||||
return render(request,'qm.html',locals())
|
||||
except Cave.MultipleObjectsReturned: # entirely the wrong action, REPLACE with the right display
|
||||
caves = Cave.objects.filter(kataster_number=cave_id)
|
||||
return render(request, 'svxcaveseveral.html', {'settings': settings, "caves":caves })
|
||||
|
||||
c=getCave(cave_id)
|
||||
manyqms=c.get_QMs()
|
||||
qm=manyqms.get(number=qm_id,found_by__date__year=year, found_by__cave_slug=c.slug())
|
||||
return render(request,'qm.html', {'qm': qm})
|
||||
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:
|
||||
url += r'&grade=' + grade
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
||||
except MultipleObjectsReturned:
|
||||
qm = manyqms.filter(blockname = blockname) # we could still get multiple objects..
|
||||
if qm:
|
||||
return render(request,'qm.html', {'qm': qm})
|
||||
else:
|
||||
return render(request,'errors/badslug.html', {'badslug': f'{cave_id=} {year=} {qm_id=} {blockname=}'})
|
||||
|
||||
def get_qms(request, caveslug):
|
||||
'''Does not crash, but just returns a text list of the entrances for a cave.
|
||||
Used internally by the JSON export code? Archeology required..
|
||||
cf get_entrances() above
|
||||
'''
|
||||
try:
|
||||
cave = Cave.objects.get(caveslug__slug = caveslug)
|
||||
|
@ -508,7 +508,8 @@ class LoadingSurvex():
|
||||
|
||||
def LoadSurvexQM(self, survexblock, qmline):
|
||||
insp = self.insp
|
||||
qm_no = qmline.group(1)
|
||||
qm_no = qmline.group(1) # this may not be unique across multiple survex files
|
||||
|
||||
qm_grade = qmline.group(2)
|
||||
if qmline.group(3): # usual closest survey station
|
||||
qm_nearest = qmline.group(3)
|
||||
@ -537,7 +538,8 @@ class LoadingSurvex():
|
||||
# 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]
|
||||
logslug = f'DUM_{int(qmyear)}_{int(qm_no):03d}'
|
||||
blockname = survexblock.name
|
||||
logslug = f'DUM_{int(qmyear)}_{blockname}_{int(qm_no):03d}'
|
||||
if survexblock.survexfile.cave:
|
||||
caveslug = survexblock.survexfile.cave.slug()
|
||||
place = survexblock.survexfile.cave
|
||||
@ -565,6 +567,7 @@ class LoadingSurvex():
|
||||
nearest_station_name=qm_nearest,
|
||||
grade=qm_grade.upper(),
|
||||
location_description=qm_notes,
|
||||
blockname = blockname, # only set for survex-imported QMs
|
||||
found_by = placeholder,
|
||||
cave = survexblock.survexfile.cave)
|
||||
qm.save
|
||||
|
@ -14,6 +14,7 @@
|
||||
<p>QMs are also loaded directly from the survex files (possibly buggy, July 2022), e.g. see
|
||||
<ul>
|
||||
<li><a href="/cave/qms/1623-264">1623-264 QMs</a>
|
||||
<li><a href="/cave/qms/1623-290">1623-290 QMs</a>
|
||||
</ul>
|
||||
|
||||
<p>For full explanation of the current status of the QM system(s), see <a href="/handbook/troggle/scriptsqms.html">scriptsqms page</a>.
|
||||
@ -25,7 +26,7 @@
|
||||
{% for QM in cave.get_QMs %}
|
||||
{% if QM.ticked_off_by %}
|
||||
{% else %}
|
||||
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a> {{QM.nearest_station_name}} :: {{QM.nearest_station_description}} {{QM.location_description}} <b>{{QM.grade}}</b></li>
|
||||
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a> :: {{QM.nearest_station_description}} {{QM.location_description}} <b>{{QM.grade}}</b></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
@ -33,7 +34,7 @@
|
||||
<ul>
|
||||
{% for QM in cave.get_QMs %}
|
||||
{% if QM.ticked_off_by %}
|
||||
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a> {{QM.nearest_station_name}} :: {{QM.nearest_station_description}} {{QM.location_description}} <b>{{QM.grade}}</b></li>
|
||||
<li><a href="{{QM.get_absolute_url}}">{{QM}}</a> :: {{QM.nearest_station_description}} {{QM.location_description}} <b>{{QM.grade}}</b></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
@ -11,7 +11,8 @@
|
||||
<p>QMs are also loaded directly from the survex files (possibly buggy, July 2022), e.g. see
|
||||
<ul>
|
||||
<li><a href="/cave/qms/1623-264">1623-264 QMs</a>
|
||||
</ul>
|
||||
<li><a href="/cave/qms/1623-290">1623-290 QMs</a>
|
||||
</ul>
|
||||
|
||||
<p>For full explanation of the current status of the QM system(s), see <a href="/handbook/troggle/scriptsqms.html">scriptsqms page</a>.
|
||||
|
||||
|
2
urls.py
2
urls.py
@ -177,7 +177,7 @@ trogglepatterns = [
|
||||
|
||||
# QMs pages - must precede other /caves pages?
|
||||
re_path(r'^cave/qms/([^/]+)/?$', caveQMs, name="caveQMs"), # Fixed. July 2022
|
||||
re_path(r'^cave/qms/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d*)(?P<grade>[ABCDXV\?]?)?$', qm, name="qm"), # Fixed. July 2022
|
||||
re_path(r'^cave/qms/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<blockname>[^0-9]*)?(?P<qm_id>\d*)(?P<grade>[ABCDXV\?]?)?$', qm, name="qm"), # Fixed. July 2022
|
||||
|
||||
# Prospecting Guide document
|
||||
re_path(r'^prospecting_guide/$', prospecting), # disabled. Bad links, incompatible image package use and very, very out of date.
|
||||
|
Loading…
Reference in New Issue
Block a user