diff --git a/core/models/caves.py b/core/models/caves.py index 7deaca1..4e221e7 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -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) diff --git a/core/views/caves.py b/core/views/caves.py index 8df801b..0349836 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -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: diff --git a/parsers/QMs.py b/parsers/QMs.py index 367b4a5..94088cf 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -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�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'] diff --git a/templates/cave_qms.html b/templates/cave_qms.html index 15aabc7..c7966e1 100644 --- a/templates/cave_qms.html +++ b/templates/cave_qms.html @@ -1,11 +1,19 @@

Question marks for {{cave.kataster_number}} - {{cave.official_name|safe}} - {{cave.unofficial_number}}

+ +

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). +

Extant

{% if cave.get_QMs %}

@@ -13,7 +21,7 @@ diff --git a/templates/qm.html b/templates/qm.html index f2d0cf5..807b3ea 100644 --- a/templates/qm.html +++ b/templates/qm.html @@ -2,6 +2,13 @@ {% load link %} {% block title %} QM: {{qm|safe}} {% endblock %} {% block contentheader %} +

QMs only available for these caves

+ + diff --git a/urls.py b/urls.py index 5f5a711..977fcba 100644 --- a/urls.py +++ b/urls.py @@ -176,8 +176,8 @@ trogglepatterns = [ path('dwgdataraw/', 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[^/]+)/(?P\d\d\d\d)-(?P\d*)(?P[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[^/]+)/(?P\d\d\d\d)-(?P\d*)(?P[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.
Previous