forked from expo/troggle
Fully working dj 1.11.29
This commit is contained in:
@@ -5,6 +5,7 @@ from datetime import *
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from troggle.core.models import DataIssue
|
||||
from troggle.core.models_caves import QM, Cave, LogbookEntry
|
||||
from utils import save_carefully
|
||||
|
||||
@@ -15,19 +16,19 @@ def deleteQMs():
|
||||
def parseCaveQMs(cave,inputFile):
|
||||
"""Runs through the CSV file at inputFile (which is a relative path from expoweb) and saves each QM as a QM instance."""
|
||||
|
||||
if cave=='stein':
|
||||
if cave=='204-steinBH':
|
||||
try:
|
||||
steinBr=Cave.objects.get(official_name="Steinbrückenhöhle")
|
||||
except Cave.DoesNotExist:
|
||||
print("Steinbruckenhoehle is not in the database. Please run parsers.")
|
||||
return
|
||||
elif cave=='hauch':
|
||||
elif cave=='234-Hauch':
|
||||
try:
|
||||
hauchHl=Cave.objects.get(official_name="Hauchhöhle")
|
||||
except Cave.DoesNotExist:
|
||||
print("Hauchhoele is not in the database. Please run parsers.")
|
||||
print("Hauchhoehle is not in the database. Please run parsers.")
|
||||
return
|
||||
elif cave =='kh':
|
||||
elif cave =='161-KH':
|
||||
try:
|
||||
kh=Cave.objects.get(official_name="Kaninchenhöhle")
|
||||
except Cave.DoesNotExist:
|
||||
@@ -45,12 +46,14 @@ def parseCaveQMs(cave,inputFile):
|
||||
try:
|
||||
year=int(line[0][1:5])
|
||||
#check if placeholder exists for given year, create it if not
|
||||
if cave=='stein':
|
||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, title="placeholder for QMs in 204", text="QMs temporarily attached to this should be re-attached to their actual trips", defaults={"date": date(year, 1, 1),"cave":steinBr})
|
||||
elif cave=='hauch':
|
||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, title="placeholder for QMs in 234", text="QMs temporarily attached to this should be re-attached to their actual trips", defaults={"date": date(year, 1, 1),"cave":hauchHl})
|
||||
message = " ! - "+ str(year) + " logbook: placeholder entry for '" + cave + "' created. Should be re-attached to the actual trip."
|
||||
if cave=='204-steinBH':
|
||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="204", title="placeholder for QMs in 204", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(steinBr)})
|
||||
elif cave=='234-Hauch':
|
||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="234", title="placeholder for QMs in 234", text=message, defaults={"date": date(year, 1, 1),"cave_slug":str(hauchHl)})
|
||||
if hadToCreate:
|
||||
print((" - placeholder logbook entry for " + cave + " " + str(year) + " added to database"))
|
||||
print(message)
|
||||
DataIssue.objects.create(parser='QMs', message=message)
|
||||
QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb")
|
||||
newQM = QM()
|
||||
newQM.found_by=placeholder
|
||||
@@ -97,8 +100,12 @@ def parse_KH_QMs(kh, inputFile):
|
||||
if res:
|
||||
res=res.groupdict()
|
||||
year=int(res['year'])
|
||||
#check if placeholder exists for given year, create it if not
|
||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, title="placeholder for QMs in 161", text="QMs temporarily attached to this should be re-attached to their actual trips", defaults={"date": date((year), 1, 1),"cave":kh})
|
||||
#check if placeholder exists for given year, create it if not
|
||||
message = " ! - "+ str(year) + " logbook: placeholder entry for '161 KH' created. Should be re-attached to the actual trip."
|
||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, place="161", title="placeholder for QMs in 161", text=message, defaults={"date": date((year), 1, 1),"cave_slug":str(kh)})
|
||||
if hadToCreate:
|
||||
print(message)
|
||||
DataIssue.objects.create(parser='QMs', message=message)
|
||||
lookupArgs={
|
||||
'found_by':placeholder,
|
||||
'number':res['number']
|
||||
@@ -112,7 +119,7 @@ def parse_KH_QMs(kh, inputFile):
|
||||
save_carefully(QM,lookupArgs,nonLookupArgs)
|
||||
|
||||
def Load_QMs():
|
||||
parseCaveQMs(cave='stein',inputFile=r"1623/204/qm.csv")
|
||||
parseCaveQMs(cave='hauch',inputFile=r"1623/234/qm.csv")
|
||||
parseCaveQMs(cave='kh', inputFile="1623/161/qmtodo.htm")
|
||||
parseCaveQMs(cave='204-steinBH',inputFile=r"1623/204/qm.csv")
|
||||
parseCaveQMs(cave='234-Hauch',inputFile=r"1623/234/qm.csv")
|
||||
parseCaveQMs(cave='161-KH', inputFile="1623/161/qmtodo.htm")
|
||||
#parseCaveQMs(cave='balkonhoehle',inputFile=r"1623/264/qm.csv")
|
||||
|
||||
@@ -76,9 +76,10 @@ def GetTripCave(place):
|
||||
return tripCaveRes[correctIndex]
|
||||
else:
|
||||
print(("No cave found for place " , place))
|
||||
return
|
||||
return None
|
||||
|
||||
# lookup function modelled on GetPersonExpeditionNameLookup
|
||||
# repeated assignment each call, needs refactoring
|
||||
Gcavelookup = None
|
||||
def GetCaveLookup():
|
||||
global Gcavelookup
|
||||
@@ -91,19 +92,28 @@ def GetCaveLookup():
|
||||
Gcavelookup[cave.kataster_number] = cave
|
||||
if cave.unofficial_number:
|
||||
Gcavelookup[cave.unofficial_number] = cave
|
||||
|
||||
# These are exact matches! edit to check for prefix only!
|
||||
Gcavelookup["tunnocks"] = Gcavelookup["258"]
|
||||
Gcavelookup["hauchhole"] = Gcavelookup["234"]
|
||||
Gcavelookup["KH"] = Gcavelookup["161"]
|
||||
Gcavelookup["Balcony"] = Gcavelookup["264"]
|
||||
Gcavelookup["Balkon"] = Gcavelookup["264"]
|
||||
Gcavelookup["FGH"] = Gcavelookup["290"]
|
||||
Gcavelookup["GSH"] = Gcavelookup["291"]
|
||||
Gcavelookup["Homecoming"] = Gcavelookup["2018-dm-07"]
|
||||
return Gcavelookup
|
||||
|
||||
|
||||
logentries = [] # the entire logbook for one year is a single object: a list of entries
|
||||
noncaveplaces = [ "Journey", "Loser Plateau" ]
|
||||
noncaveplaces = [ "QMplaceholder", "Journey", "Loser Plateau", "UNKNOWN", 'plateau',
|
||||
'base camp', 'basecamp', 'top camp', 'topcamp' ]
|
||||
logdataissues = {}
|
||||
trips ={}
|
||||
|
||||
def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground, entry_type="wiki"):
|
||||
""" saves a logbook entry and related persontrips """
|
||||
""" saves a logbook entry and related persontrips
|
||||
Does NOT save the expeditionday_id - all NULLs. why?
|
||||
"""
|
||||
|
||||
trippersons, author = GetTripPersons(trippeople, expedition, logtime_underground)
|
||||
if not author:
|
||||
@@ -112,16 +122,23 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_
|
||||
DataIssue.objects.create(parser='logbooks', message=message)
|
||||
return
|
||||
|
||||
#tripCave = GetTripCave(place)
|
||||
# This needs attention. The slug field is derived from 'title'
|
||||
# both GetCaveLookup() and GetTripCave() need to work together better. None of this data is *used* though?
|
||||
#tripCave = GetTripCave(place):
|
||||
|
||||
lplace = place.lower()
|
||||
cave=None
|
||||
if lplace not in noncaveplaces:
|
||||
cave=GetCaveLookup().get(lplace)
|
||||
cave = GetCaveLookup().get(lplace)
|
||||
# message = " ! - '" + lplace + "' place not in noncaveplaces."
|
||||
# print(message)
|
||||
# DataIssue.objects.create(parser='logbooks', message=message)
|
||||
|
||||
#Check for an existing copy of the current entry, and save
|
||||
expeditionday = expedition.get_expedition_day(date)
|
||||
lookupAttribs={'date':date, 'title':title}
|
||||
nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50], 'entry_type':entry_type}
|
||||
# 'cave' is converted to a string doing this, which renders as the cave slug.
|
||||
nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave_slug':str(cave), 'slug':slugify(title)[:50], 'entry_type':entry_type}
|
||||
lbo, created=save_carefully(LogbookEntry, lookupAttribs, nonLookupAttribs)
|
||||
|
||||
|
||||
|
||||
@@ -93,8 +93,13 @@ def LoadPersonsExpos():
|
||||
if len(names) == 1:
|
||||
lastname = ""
|
||||
|
||||
if personline[header["VfHO member"]] =='':
|
||||
vfho = False
|
||||
else:
|
||||
vfho = True
|
||||
|
||||
lookupAttribs={'first_name':firstname, 'last_name':(lastname or "")}
|
||||
nonLookupAttribs={'is_vfho':personline[header["VfHO member"]], 'fullname':fullname}
|
||||
nonLookupAttribs={'is_vfho':vfho, 'fullname':fullname}
|
||||
person, created = save_carefully(models.Person, lookupAttribs, nonLookupAttribs)
|
||||
|
||||
parseMugShotAndBlurb(personline=personline, header=header, person=person)
|
||||
|
||||
Reference in New Issue
Block a user