mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-13 20:17:05 +00:00
Moved classes to models_caves and fixed imports
This commit is contained in:
@@ -12,6 +12,7 @@ from django.template.defaultfilters import slugify
|
||||
from django.utils.timezone import get_current_timezone, make_aware
|
||||
|
||||
import troggle.core.models as models
|
||||
import troggle.core.models_caves as models_caves
|
||||
from parsers.people import GetPersonExpeditionNameLookup
|
||||
from utils import save_carefully
|
||||
|
||||
@@ -49,23 +50,24 @@ def GetTripPersons(trippeople, expedition, logtime_underground):
|
||||
author = res[-1][0]
|
||||
return res, author
|
||||
|
||||
def GetTripCave(place): #need to be fuzzier about matching here. Already a very slow function...
|
||||
# print "Getting cave for " , place
|
||||
def GetTripCave(place):
|
||||
#need to be fuzzier about matching here. Already a very slow function...
|
||||
# print "Getting cave for " , place
|
||||
try:
|
||||
katastNumRes=[]
|
||||
katastNumRes=list(models.Cave.objects.filter(kataster_number=int(place)))
|
||||
katastNumRes=list(models_caves.Cave.objects.filter(kataster_number=int(place)))
|
||||
except ValueError:
|
||||
pass
|
||||
officialNameRes=list(models.Cave.objects.filter(official_name=place))
|
||||
officialNameRes=list(models_caves.Cave.objects.filter(official_name=place))
|
||||
tripCaveRes=officialNameRes+katastNumRes
|
||||
|
||||
if len(tripCaveRes)==1:
|
||||
# print "Place " , place , "entered as" , tripCaveRes[0]
|
||||
# print "Place " , place , "entered as" , tripCaveRes[0]
|
||||
return tripCaveRes[0]
|
||||
|
||||
elif models.OtherCaveName.objects.filter(name=place):
|
||||
tripCaveRes=models.OtherCaveName.objects.filter(name__icontains=place)[0].cave
|
||||
# print "Place " , place , "entered as" , tripCaveRes
|
||||
elif models_caves.OtherCaveName.objects.filter(name=place):
|
||||
tripCaveRes=models_caves.OtherCaveName.objects.filter(name__icontains=place)[0].cave
|
||||
# print "Place " , place , "entered as" , tripCaveRes
|
||||
return tripCaveRes
|
||||
|
||||
elif len(tripCaveRes)>1:
|
||||
@@ -76,6 +78,25 @@ def GetTripCave(place): #need to be fuzzier about matching here. Already a very
|
||||
print(("No cave found for place " , place))
|
||||
return
|
||||
|
||||
# lookup function modelled on GetPersonExpeditionNameLookup
|
||||
Gcavelookup = None
|
||||
def GetCaveLookup():
|
||||
global Gcavelookup
|
||||
if Gcavelookup:
|
||||
return Gcavelookup
|
||||
Gcavelookup = {"NONEPLACEHOLDER":None}
|
||||
for cave in models_caves.Cave.objects.all():
|
||||
Gcavelookup[cave.official_name.lower()] = cave
|
||||
if cave.kataster_number:
|
||||
Gcavelookup[cave.kataster_number] = cave
|
||||
if cave.unofficial_number:
|
||||
Gcavelookup[cave.unofficial_number] = cave
|
||||
|
||||
Gcavelookup["tunnocks"] = Gcavelookup["258"]
|
||||
Gcavelookup["hauchhole"] = Gcavelookup["234"]
|
||||
return Gcavelookup
|
||||
|
||||
|
||||
logentries = [] # the entire logbook is a single object: a list of entries
|
||||
noncaveplaces = [ "Journey", "Loser Plateau" ]
|
||||
|
||||
@@ -195,7 +216,6 @@ def Parseloghtmltxt(year, expedition, txt):
|
||||
if logbook_entry_count == 0:
|
||||
print(" - No trip entries found in logbook, check the syntax matches htmltxt format")
|
||||
|
||||
|
||||
# main parser for 1991 - 2001. simpler because the data has been hacked so much to fit it
|
||||
def Parseloghtml01(year, expedition, txt):
|
||||
tripparas = re.findall(r"<hr[\s/]*>([\s\S]*?)(?=<hr)", txt)
|
||||
@@ -381,6 +401,7 @@ def LoadLogbookForExpedition(expedition):
|
||||
|
||||
#return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(models.PersonTrip.objects.filter(personexpedition__expedition=expedition).count())
|
||||
|
||||
|
||||
def LoadLogbooks():
|
||||
""" This is the master function for parsing all logbooks into the Troggle database. """
|
||||
|
||||
@@ -440,7 +461,7 @@ def parseAutoLogBookEntry(filename):
|
||||
if caveMatch:
|
||||
caveRef, = caveMatch.groups()
|
||||
try:
|
||||
cave = models.getCaveByReference(caveRef)
|
||||
cave = models_caves.getCaveByReference(caveRef)
|
||||
except AssertionError:
|
||||
cave = None
|
||||
errors.append("Cave not found in database")
|
||||
@@ -496,4 +517,4 @@ def parseAutoLogBookEntry(filename):
|
||||
time_underground = TU,
|
||||
logbook_entry = logbookEntry,
|
||||
is_logbook_entry_author = author).save()
|
||||
print(logbookEntry)
|
||||
print(logbookEntry)
|
||||
Reference in New Issue
Block a user