summaryrefslogtreecommitdiffstats
path: root/parsers/cavetab.py
diff options
context:
space:
mode:
authorMartin Green <martin.speleo@gmail.com>2011-07-11 00:15:59 +0100
committerMartin Green <martin.speleo@gmail.com>2011-07-11 00:15:59 +0100
commit861daee66feb985ccfb9271c211dc1a27263fbf4 (patch)
tree43143d7e05d59ca83ef9d9f696071bf594f1d589 /parsers/cavetab.py
parentdb2d954b1d8d3a7454d51a7f6eebd88aa102e64c (diff)
downloadtroggle-861daee66feb985ccfb9271c211dc1a27263fbf4.tar.gz
troggle-861daee66feb985ccfb9271c211dc1a27263fbf4.tar.bz2
troggle-861daee66feb985ccfb9271c211dc1a27263fbf4.zip
Removed conversion to wiki, replaced Surveystation models with text, added area 1623 to all relevant caves.
Diffstat (limited to 'parsers/cavetab.py')
-rw-r--r--parsers/cavetab.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/parsers/cavetab.py b/parsers/cavetab.py
index bf61d7f..68ea4b3 100644
--- a/parsers/cavetab.py
+++ b/parsers/cavetab.py
@@ -3,7 +3,8 @@ import troggle.core.models as models
from django.conf import settings
import csv, time, re, os, logging
from utils import save_carefully
-from utils import html_to_wiki
+from django.core.urlresolvers import reverse
+import flatpages.models
##format of CAVETAB2.CSV is
KatasterNumber = 0
@@ -54,6 +55,7 @@ Findability = 44
FindabilityComment = 45
def LoadCaveTab():
+
cavetab = open(os.path.join(settings.EXPOWEB, "noinfo", "CAVETAB2.CSV"),'rU')
caveReader = csv.reader(cavetab)
caveReader.next() # Strip out column headers
@@ -76,14 +78,14 @@ def LoadCaveTab():
if line[MultipleEntrances] == 'yes' or line[MultipleEntrances]=='': #When true, this line contains an actual cave, otherwise it is an extra entrance.
args = {}
defaultArgs = {}
-
+
def addToArgs(CSVname, modelName):
if line[CSVname]:
- args[modelName] = html_to_wiki(line[CSVname])
+ args[modelName] = line[CSVname]
def addToDefaultArgs(CSVname, modelName): #This has to do with the non-destructive import. These arguments will be passed as the "default" dictionary in a get_or_create
if line[CSVname]:
- defaultArgs[modelName] = html_to_wiki(line[CSVname])
+ defaultArgs[modelName] = line[CSVname]
# The attributes added using "addToArgs" will be used to look up an existing cave. Those added using "addToDefaultArgs" will not.
addToArgs(KatasterNumber, "kataster_number")
@@ -103,6 +105,7 @@ def LoadCaveTab():
addToDefaultArgs(Extent, "extent")
addToDefaultArgs(SurvexFile, "survex_file")
addToDefaultArgs(Notes, "notes")
+ addToDefaultArgs(AutogenFile, "url")
if line[Area] == "1626":
if line[KatasterNumber] != "":
args["slug"] = line[Area] + "-" + line[KatasterNumber]
@@ -140,6 +143,7 @@ def LoadCaveTab():
newArea = models.Area(short_name = line[Area], parent = area1623)
newArea.save()
newCave.area.add(newArea)
+ newCave.area.add(area1623)
elif created:
newCave.area.add(area1623)
@@ -152,6 +156,7 @@ def LoadCaveTab():
newUnofficialName.save()
logging.info("Added unofficial name "+str(newUnofficialName)+" to cave "+str(newCave)+"\n")
+
if created and line[MultipleEntrances] == '' or \
line[MultipleEntrances] == 'entrance' or \
@@ -165,10 +170,10 @@ def LoadCaveTab():
def addToArgs(CSVname, modelName):
if line[CSVname]:
- args[modelName] = html_to_wiki(line[CSVname])
+ args[modelName] = line[CSVname]
def addToArgsViaDict(CSVname, modelName, dictionary):
if line[CSVname]:
- args[modelName] = dictionary[html_to_wiki(line[CSVname])]
+ args[modelName] = dictionary[line[CSVname]]
addToArgs(EntranceName, 'name')
addToArgs(Explorers, 'explorers')
addToArgs(Map, 'map_description')
@@ -188,6 +193,7 @@ def LoadCaveTab():
"Unmarked": "U",
"": "?",
})
+
addToArgs(MarkingComment, 'marking_comment')
addToArgsViaDict(Findability, 'findability', {"Surveyed": "S",
"Lost": "L",
@@ -200,20 +206,15 @@ def LoadCaveTab():
addToArgs(Northing, 'northing')
addToArgs(Altitude, 'alt')
addToArgs(DescriptionOfOtherPoint, 'other_description')
- def addToArgsSurveyStation(CSVname, modelName):
- if line[CSVname]:
- surveyPoint = models.SurveyStation(name = line[CSVname])
- surveyPoint.save()
- args[modelName] = surveyPoint
- addToArgsSurveyStation(TagPoint, 'tag_station')
- addToArgsSurveyStation(ExactEntrance, 'exact_station')
- addToArgsSurveyStation(OtherPoint, 'other_station')
+ addToArgs(TagPoint, 'tag_station')
+ addToArgs(ExactEntrance, 'exact_station')
+ addToArgs(OtherPoint, 'other_station')
addToArgs(OtherPoint, 'other_description')
if line[GPSpreSA]:
- addToArgsSurveyStation(GPSpreSA, 'other_station')
+ addToArgs(GPSpreSA, 'other_station')
args['other_description'] = 'pre selective availability GPS'
if line[GPSpostSA]:
- addToArgsSurveyStation(GPSpostSA, 'other_station')
+ addToArgs(GPSpostSA, 'other_station')
args['other_description'] = 'post selective availability GPS'
addToArgs(Bearings, 'bearings')
args['slug'] = newCave.slug + entrance_letter
@@ -227,6 +228,8 @@ def LoadCaveTab():
newCaveAndEntrance.save()
logging.info("Added CaveAndEntrance "+str(newCaveAndEntrance)+"\n")
+ f = flatpages.models.EntranceRedirect(originalURL = line[AutogenFile], entrance = newEntrance)
+ f.save()
# lookup function modelled on GetPersonExpeditionNameLookup