From 78f8ea2b5b22f8685441310c277623a36e8cd193 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 13 Apr 2020 17:35:58 +0100 Subject: [PATCH] bug fixed for new logbook --- parsers/logbooks.py | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 9971ed6..01800a1 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -108,15 +108,12 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_ lookupAttribs={'date':date, 'title':title} nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50], 'entry_type':entry_type} lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs) - #logentries.append(models.LogbookEntry) for tripperson, time_underground in trippersons: lookupAttribs={'personexpedition':tripperson, 'logbook_entry':lbo} nonLookupAttribs={'time_underground':time_underground, 'is_logbook_entry_author':(tripperson == author)} save_carefully(models.PersonTrip, lookupAttribs, nonLookupAttribs) - #logentries.append(models.PersonTrip) - def ParseDate(tripdate, year): """ Interprets dates in the expo logbooks and returns a correct datetime.date object """ @@ -350,6 +347,27 @@ def LoadLogbookForExpedition(expedition): parsefunc = year_settings[1] logbook_parseable = True print(" - Parsing logbook: " + year_settings[0] + "\n - Using parser: " + year_settings[1]) + + if logbook_parseable: + parser = globals()[parsefunc] + parser(expedition.year, expedition, txt) + SetDatesFromLogbookEntries(expedition) + # and this has also stored all the objects in logentries[] + print " - Storing " , len(logentries), " log entries" + cache_filename = os.path.join(expowebbase, year_settings[0])+".cache" + with open(cache_filename, "wb") as f: + pickle.dump(logentries, f, 2) + logentries=[] # flush for next year + + if logbook_cached: + i=0 + for entrytuple in range(len(logentries)): + date, place, title, text, trippeople, expedition, logtime_underground, \ + entry_type = logentries[i] + #print " - - obj ", i, date, title + EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground,\ + entry_type) + i +=1 else: try: file_in = open(os.path.join(expowebbase, expedition.year, settings.DEFAULT_LOGBOOK_FILE)) @@ -362,25 +380,6 @@ def LoadLogbookForExpedition(expedition): logbook_parseable = False print("Couldn't open default logbook file and nothing in settings for expo " + expedition.year) - if logbook_parseable: - parser = globals()[parsefunc] - parser(expedition.year, expedition, txt) - SetDatesFromLogbookEntries(expedition) - # and this has also stored all the objects in logentries[] - print " - Storing " , len(logentries), " log entries" - with open(cache_filename, "wb") as f: - pickle.dump(logentries, f, 2) - logentries=[] # flush for next year - - if logbook_cached: - i=0 - for entrytuple in range(len(logentries)): - date, place, title, text, trippeople, expedition, logtime_underground, \ - entry_type = logentries[i] - #print " - - obj ", i, date, title - EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground,\ - entry_type) - i +=1 #return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(models.PersonTrip.objects.filter(personexpedition__expedition=expedition).count())