diff --git a/core/models/caves.py b/core/models/caves.py index d623963..4e963fb 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -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): diff --git a/core/views/caves.py b/core/views/caves.py index 3fbc934..1b47c39 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -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) diff --git a/parsers/survex.py b/parsers/survex.py index 76acda6..6274b1f 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -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 diff --git a/templates/cave_qms.html b/templates/cave_qms.html index 25d5ccf..f108a8f 100644 --- a/templates/cave_qms.html +++ b/templates/cave_qms.html @@ -14,6 +14,7 @@
QMs are also loaded directly from the survex files (possibly buggy, July 2022), e.g. see
For full explanation of the current status of the QM system(s), see scriptsqms page. @@ -25,7 +26,7 @@ {% for QM in cave.get_QMs %} {% if QM.ticked_off_by %} {% else %} -
QMs are also loaded directly from the survex files (possibly buggy, July 2022), e.g. see
+For full explanation of the current status of the QM system(s), see scriptsqms page.
diff --git a/urls.py b/urls.py
index d4dbf9d..462f696 100644
--- a/urls.py
+++ b/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