forked from expo/troggle
Imposrt mad more specific
This commit is contained in:
parent
d857cc9084
commit
01e098339e
@ -6,7 +6,8 @@ from django.core import serializers
|
|||||||
|
|
||||||
from troggle.core.views_other import downloadLogbook
|
from troggle.core.views_other import downloadLogbook
|
||||||
from troggle.core.models import *
|
from troggle.core.models import *
|
||||||
from troggle.core.models_caves import *
|
from troggle.core.models_caves import Cave, Area, Entrance, CaveAndEntrance, NewSubCave, OtherCaveName, CaveDescription, LogbookEntry, PersonTrip, Survey, ScannedImage, QM
|
||||||
|
from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexStation, SurvexScansFolder, SurvexScanSingle
|
||||||
#from troggle.reversion.admin import VersionAdmin #django-reversion version control
|
#from troggle.reversion.admin import VersionAdmin #django-reversion version control
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ from django.core.urlresolvers import reverse
|
|||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
|
|
||||||
from troggle.core.models import TroggleModel, TroggleImageModel, Person, Expedition
|
from troggle.core.models import TroggleModel, TroggleImageModel, Person, Expedition
|
||||||
from troggle.core.models_survex import *
|
from troggle.core.models_survex import SurvexStation
|
||||||
|
|
||||||
class Area(TroggleModel):
|
class Area(TroggleModel):
|
||||||
short_name = models.CharField(max_length=100)
|
short_name = models.CharField(max_length=100)
|
||||||
@ -444,7 +444,7 @@ class LogbookEntry(TroggleModel):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if "cave" in list(kwargs.keys()):
|
if "cave" in list(kwargs.keys()):
|
||||||
if kwargs["cave"] is not None:
|
if kwargs["cave"] is not None:
|
||||||
kwargs["cave_slug"] = models_caves.CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug
|
kwargs["cave_slug"] = CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug
|
||||||
kwargs.pop("cave")
|
kwargs.pop("cave")
|
||||||
# parse error in python3.8
|
# parse error in python3.8
|
||||||
return TroggleModel.__init__(self, *args, **kwargs) # seems OK in 3.5 & 3.8! failure later elsewhere with 3.8
|
return TroggleModel.__init__(self, *args, **kwargs) # seems OK in 3.5 & 3.8! failure later elsewhere with 3.8
|
||||||
|
@ -11,8 +11,8 @@ from django.conf import settings
|
|||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.utils.timezone import get_current_timezone, make_aware
|
from django.utils.timezone import get_current_timezone, make_aware
|
||||||
|
|
||||||
import troggle.core.models as models
|
from troggle.core.models import DataIssue, Expedition
|
||||||
import troggle.core.models_caves as models_caves
|
from troggle.core.models_caves import Cave, OtherCaveName, getCaveByReference, LogbookEntry, PersonTrip
|
||||||
from parsers.people import GetPersonExpeditionNameLookup
|
from parsers.people import GetPersonExpeditionNameLookup
|
||||||
from utils import save_carefully
|
from utils import save_carefully
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ def GetTripPersons(trippeople, expedition, logtime_underground):
|
|||||||
if not personyear:
|
if not personyear:
|
||||||
print((" - No name match for: '%s'" % tripperson))
|
print((" - No name match for: '%s'" % tripperson))
|
||||||
message = "No name match for: '%s' in year '%s'" % (tripperson, expedition.year)
|
message = "No name match for: '%s' in year '%s'" % (tripperson, expedition.year)
|
||||||
models.DataIssue.objects.create(parser='logbooks', message=message)
|
DataIssue.objects.create(parser='logbooks', message=message)
|
||||||
res.append((personyear, logtime_underground))
|
res.append((personyear, logtime_underground))
|
||||||
if mul:
|
if mul:
|
||||||
author = personyear
|
author = personyear
|
||||||
@ -55,18 +55,18 @@ def GetTripCave(place):
|
|||||||
# print "Getting cave for " , place
|
# print "Getting cave for " , place
|
||||||
try:
|
try:
|
||||||
katastNumRes=[]
|
katastNumRes=[]
|
||||||
katastNumRes=list(models_caves.Cave.objects.filter(kataster_number=int(place)))
|
katastNumRes=list(Cave.objects.filter(kataster_number=int(place)))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
officialNameRes=list(models_caves.Cave.objects.filter(official_name=place))
|
officialNameRes=list(Cave.objects.filter(official_name=place))
|
||||||
tripCaveRes=officialNameRes+katastNumRes
|
tripCaveRes=officialNameRes+katastNumRes
|
||||||
|
|
||||||
if len(tripCaveRes)==1:
|
if len(tripCaveRes)==1:
|
||||||
# print "Place " , place , "entered as" , tripCaveRes[0]
|
# print "Place " , place , "entered as" , tripCaveRes[0]
|
||||||
return tripCaveRes[0]
|
return tripCaveRes[0]
|
||||||
|
|
||||||
elif models_caves.OtherCaveName.objects.filter(name=place):
|
elif OtherCaveName.objects.filter(name=place):
|
||||||
tripCaveRes=models_caves.OtherCaveName.objects.filter(name__icontains=place)[0].cave
|
tripCaveRes=OtherCaveName.objects.filter(name__icontains=place)[0].cave
|
||||||
# print "Place " , place , "entered as" , tripCaveRes
|
# print "Place " , place , "entered as" , tripCaveRes
|
||||||
return tripCaveRes
|
return tripCaveRes
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ def GetCaveLookup():
|
|||||||
if Gcavelookup:
|
if Gcavelookup:
|
||||||
return Gcavelookup
|
return Gcavelookup
|
||||||
Gcavelookup = {"NONEPLACEHOLDER":None}
|
Gcavelookup = {"NONEPLACEHOLDER":None}
|
||||||
for cave in models_caves.Cave.objects.all():
|
for cave in Cave.objects.all():
|
||||||
Gcavelookup[cave.official_name.lower()] = cave
|
Gcavelookup[cave.official_name.lower()] = cave
|
||||||
if cave.kataster_number:
|
if cave.kataster_number:
|
||||||
Gcavelookup[cave.kataster_number] = cave
|
Gcavelookup[cave.kataster_number] = cave
|
||||||
@ -112,7 +112,7 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_
|
|||||||
if not author:
|
if not author:
|
||||||
print((" - Skipping logentry: " + title + " - no author for entry"))
|
print((" - Skipping logentry: " + title + " - no author for entry"))
|
||||||
message = "Skipping logentry: %s - no author for entry in year '%s'" % (title, expedition.year)
|
message = "Skipping logentry: %s - no author for entry in year '%s'" % (title, expedition.year)
|
||||||
models.DataIssue.objects.create(parser='logbooks', message=message)
|
DataIssue.objects.create(parser='logbooks', message=message)
|
||||||
return
|
return
|
||||||
|
|
||||||
#tripCave = GetTripCave(place)
|
#tripCave = GetTripCave(place)
|
||||||
@ -125,13 +125,13 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_
|
|||||||
expeditionday = expedition.get_expedition_day(date)
|
expeditionday = expedition.get_expedition_day(date)
|
||||||
lookupAttribs={'date':date, 'title':title}
|
lookupAttribs={'date':date, 'title':title}
|
||||||
nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50], 'entry_type':entry_type}
|
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)
|
lbo, created=save_carefully(LogbookEntry, lookupAttribs, nonLookupAttribs)
|
||||||
|
|
||||||
|
|
||||||
for tripperson, time_underground in trippersons:
|
for tripperson, time_underground in trippersons:
|
||||||
lookupAttribs={'personexpedition':tripperson, 'logbook_entry':lbo}
|
lookupAttribs={'personexpedition':tripperson, 'logbook_entry':lbo}
|
||||||
nonLookupAttribs={'time_underground':time_underground, 'is_logbook_entry_author':(tripperson == author)}
|
nonLookupAttribs={'time_underground':time_underground, 'is_logbook_entry_author':(tripperson == author)}
|
||||||
save_carefully(models.PersonTrip, lookupAttribs, nonLookupAttribs)
|
save_carefully(PersonTrip, lookupAttribs, nonLookupAttribs)
|
||||||
|
|
||||||
def ParseDate(tripdate, year):
|
def ParseDate(tripdate, year):
|
||||||
""" Interprets dates in the expo logbooks and returns a correct datetime.date object """
|
""" Interprets dates in the expo logbooks and returns a correct datetime.date object """
|
||||||
@ -399,16 +399,16 @@ def LoadLogbookForExpedition(expedition):
|
|||||||
print(("Couldn't open default logbook file and nothing in settings for expo " + expedition.year))
|
print(("Couldn't open default logbook file and nothing in settings for expo " + expedition.year))
|
||||||
|
|
||||||
|
|
||||||
#return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(models.PersonTrip.objects.filter(personexpedition__expedition=expedition).count())
|
#return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(PersonTrip.objects.filter(personexpedition__expedition=expedition).count())
|
||||||
|
|
||||||
|
|
||||||
def LoadLogbooks():
|
def LoadLogbooks():
|
||||||
""" This is the master function for parsing all logbooks into the Troggle database. """
|
""" This is the master function for parsing all logbooks into the Troggle database. """
|
||||||
|
|
||||||
# Clear the logbook data issues as we are reloading
|
# Clear the logbook data issues as we are reloading
|
||||||
models.DataIssue.objects.filter(parser='logbooks').delete()
|
DataIssue.objects.filter(parser='logbooks').delete()
|
||||||
# Fetch all expos
|
# Fetch all expos
|
||||||
expos = models.Expedition.objects.all()
|
expos = Expedition.objects.all()
|
||||||
for expo in expos:
|
for expo in expos:
|
||||||
print(("\nLoading Logbook for: " + expo.year))
|
print(("\nLoading Logbook for: " + expo.year))
|
||||||
|
|
||||||
@ -442,9 +442,9 @@ def parseAutoLogBookEntry(filename):
|
|||||||
expeditionYearMatch = expeditionYearRegex.search(contents)
|
expeditionYearMatch = expeditionYearRegex.search(contents)
|
||||||
if expeditionYearMatch:
|
if expeditionYearMatch:
|
||||||
try:
|
try:
|
||||||
expedition = models.Expedition.objects.get(year = expeditionYearMatch.groups()[0])
|
expedition = Expedition.objects.get(year = expeditionYearMatch.groups()[0])
|
||||||
personExpeditionNameLookup = GetPersonExpeditionNameLookup(expedition)
|
personExpeditionNameLookup = GetPersonExpeditionNameLookup(expedition)
|
||||||
except models.Expedition.DoesNotExist:
|
except Expedition.DoesNotExist:
|
||||||
errors.append("Expedition not in database")
|
errors.append("Expedition not in database")
|
||||||
else:
|
else:
|
||||||
errors.append("Expedition Year could not be parsed")
|
errors.append("Expedition Year could not be parsed")
|
||||||
@ -461,7 +461,7 @@ def parseAutoLogBookEntry(filename):
|
|||||||
if caveMatch:
|
if caveMatch:
|
||||||
caveRef, = caveMatch.groups()
|
caveRef, = caveMatch.groups()
|
||||||
try:
|
try:
|
||||||
cave = models_caves.getCaveByReference(caveRef)
|
cave = getCaveByReference(caveRef)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
cave = None
|
cave = None
|
||||||
errors.append("Cave not found in database")
|
errors.append("Cave not found in database")
|
||||||
@ -506,14 +506,14 @@ def parseAutoLogBookEntry(filename):
|
|||||||
people.append((name, author, TU))
|
people.append((name, author, TU))
|
||||||
if errors:
|
if errors:
|
||||||
return errors # Bail out before commiting to the database
|
return errors # Bail out before commiting to the database
|
||||||
logbookEntry = models.LogbookEntry(date = date,
|
logbookEntry = LogbookEntry(date = date,
|
||||||
expedition = expedition,
|
expedition = expedition,
|
||||||
title = title, cave = cave, place = location,
|
title = title, cave = cave, place = location,
|
||||||
text = report, slug = slugify(title)[:50],
|
text = report, slug = slugify(title)[:50],
|
||||||
filename = filename)
|
filename = filename)
|
||||||
logbookEntry.save()
|
logbookEntry.save()
|
||||||
for name, author, TU in people:
|
for name, author, TU in people:
|
||||||
models.PersonTrip(personexpedition = personExpo,
|
PersonTrip(personexpedition = personExpo,
|
||||||
time_underground = TU,
|
time_underground = TU,
|
||||||
logbook_entry = logbookEntry,
|
logbook_entry = logbookEntry,
|
||||||
is_logbook_entry_author = author).save()
|
is_logbook_entry_author = author).save()
|
||||||
|
Loading…
Reference in New Issue
Block a user