diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2021-04-10 01:07:49 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2021-04-10 01:07:49 +0100 |
commit | 6dc54adec817ff959dafbf436ae3f21ae0dadbd6 (patch) | |
tree | 94ed180e8e3705097cf72cf69b723f7ab9793ea5 /core/views/logbooks.py | |
parent | 16a6e05849e0e1bc5ce4c9ee6db04a137f503216 (diff) | |
download | troggle-6dc54adec817ff959dafbf436ae3f21ae0dadbd6.tar.gz troggle-6dc54adec817ff959dafbf436ae3f21ae0dadbd6.tar.bz2 troggle-6dc54adec817ff959dafbf436ae3f21ae0dadbd6.zip |
Cache enabled for 'expedition' pages
Diffstat (limited to 'core/views/logbooks.py')
-rw-r--r-- | core/views/logbooks.py | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 11ea3d6..4abb205 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -12,10 +12,9 @@ from django.template.defaultfilters import slugify from django.utils import timezone from django.views.generic.list import ListView -import troggle.core.models as models -import troggle.parsers.logbooks as logbookparsers +#import troggle.parsers.logbooks as logbookparsers from troggle.core.forms import getTripForm # , get_name, PersonForm -from troggle.core.models import Expedition, Person, PersonExpedition +from troggle.core.models import Expedition, Person, PersonExpedition, TROG from troggle.core.models_caves import LogbookEntry, PersonTrip from troggle.core.models_survex import SurvexBlock from .login import login_required_if_public @@ -24,6 +23,11 @@ from troggle.parsers.people import GetPersonExpeditionNameLookup import troggle.settings as settings +'''These views are for logbook items when they appear in an 'expedition' page +and for persons: their individual pages and their perseonexpedition pages. + +It uses the global object TROG to hold some cached pages. +''' def getNotablePersons(): notablepersons = [] @@ -51,7 +55,27 @@ def personindex(request): def expedition(request, expeditionname): + '''Returns a rendered page for one expedition, specified by the year e.g. '2019'. + If page caching is enabled, it caches the dictionaries used to render the template page. + + The cache is refreshed if '?reload' is present in the requesting URL, which also re-parses the logbook. + By specifying a '0' for the expected number of entries in the logbook cache, this forces the parser to + re-parse the original logbook HTML file. + ''' + if "reload" in request.GET: + this_expedition = Expedition.objects.get(year=int(expeditionname)) + LoadLogbookForExpedition(this_expedition, 0) + + ts = TROG['pagecache']['expedition'] + if settings.CACHEDPAGES: + nexpos = len( TROG['pagecache']['expedition']) + #print(f'! - expo {expeditionname} CACHEDPAGES {nexpos} expo pages in cache.') + if expeditionname in ts: + #print('! - expo {expeditionanme} using cached page') + return render(request,'expedition.html', ts[expeditionname] ) + this_expedition = Expedition.objects.get(year=int(expeditionname)) + expeditions = Expedition.objects.all() personexpeditiondays = [ ] dateditems = list(this_expedition.logbookentry_set.all()) + list(this_expedition.survexblock_set.all()) @@ -66,9 +90,14 @@ def expedition(request, expeditionname): prow.append(pcell) personexpeditiondays.append({"personexpedition":personexpedition, "personrow":prow}) - if "reload" in request.GET: - LoadLogbookForExpedition(this_expedition) - return render(request,'expedition.html', {'expedition': this_expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'settings':settings, 'dateditems': dateditems }) + + ts[expeditionname] = {'expedition': this_expedition, 'expeditions':expeditions, + 'personexpeditiondays':personexpeditiondays, 'settings':settings, + 'dateditems': dateditems } + TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname] + nexpos = len( TROG['pagecache']['expedition']) + #print(f'! - expo {expeditionname} pre-render N expos:{nexpos}') + return render(request,'expedition.html', ts[expeditionname] ) def get_absolute_url(self): |