diff --git a/core/models_caves.py b/core/models_caves.py index ac6dd34..0027a29 100644 --- a/core/models_caves.py +++ b/core/models_caves.py @@ -125,7 +125,7 @@ class Cave(TroggleModel): return urljoin(settings.URL_ROOT, reverse('cave',kwargs={'cave_id':href,})) def __str__(self, sep = ": "): - return str("slug:"+self.slug()) + return str("slug:"+str(self.slug())) def get_QMs(self): return QM.objects.filter(found_by__cave_slug=self.caveslug_set.all()) diff --git a/core/views_caves.py b/core/views_caves.py index 943e797..8613790 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -72,16 +72,30 @@ def caveKey(x): """ return x.kataster_number +def getnotablecaves(): + notablecaves = [] + for kataster_number in settings.NOTABLECAVESHREFS: + try: + cave = Cave.objects.get(kataster_number=kataster_number) + notablecaves.append(cave) + except: + print(" ! FAILED to get only one cave per kataster_number for: "+kataster_number) + caves = Cave.objects.all().filter(kataster_number=kataster_number) + for c in caves: + print(c.kataster_number, c.slug()) + if c.slug() != None: + notablecaves.append(c) + return notablecaves + + def caveindex(request): caves = Cave.objects.all() - notablecavehrefs = settings.NOTABLECAVESHREFS - notablecaves = [Cave.objects.get(kataster_number=kataster_number) for kataster_number in notablecavehrefs ] caves1623 = list(Cave.objects.filter(area__short_name = "1623")) caves1626 = list(Cave.objects.filter(area__short_name = "1626")) #python2 to python3 issue https://realpython.com/python-sort/ caves1623.sort(key=caveKey) caves1626.sort(key=caveKey) - return render(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':notablecaves, 'cavepage': True}) + return render(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':getnotablecaves(), 'cavepage': True}) def cave3d(request, cave_id=''): cave = getCave(cave_id) diff --git a/flatpages/views.py b/flatpages/views.py index 1905461..eb8720c 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -27,6 +27,14 @@ def flatpage(request, path): return troggle.core.views_caves.caveSlug(request, r.slug()) except Cave.DoesNotExist: pass + except: + print(" ! FAILED to get only one cave per slug for: "+path) + caves = Cave.objects.all().filter(url = path) + for c in caves: + print(path, c.slug()) + if c.slug() != None: + return troggle.core.views_caves.caveSlug(request, c.slug()) + pass try: r = EntranceRedirect.objects.get(originalURL = path)