mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 08:41:51 +00:00
[svn] Fixes to deal with reorganization of expo surveys repository. Now that survey scans and Surveys.csv are in different directories, we have two settings variables, settings.SURVEYS for the root of the survey repo, and settings.SURVEY_SCANS for the surveyscans directory.
Fixed tab / indent muck in surveys parser. Commented out some "file abstraction" stuff for the time being. Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8335 by cucc @ 5/10/2009 7:26 AM
This commit is contained in:
parent
9489fe56d9
commit
919c7e932a
@ -24,6 +24,7 @@ class ScannedImageInline(admin.TabularInline):
|
||||
|
||||
class SurveyAdmin(TroggleModelAdmin):
|
||||
inlines = (ScannedImageInline,)
|
||||
search_fields = ('expedition__year','wallet_number')
|
||||
|
||||
class QMInline(admin.TabularInline):
|
||||
model=QM
|
||||
|
@ -538,7 +538,7 @@ class Photo(TroggleModel):
|
||||
def __str__(self):
|
||||
return self.caption
|
||||
|
||||
scansFileStorage = FileSystemStorage(location=settings.SURVEYS, base_url=settings.SURVEYS_URL)
|
||||
scansFileStorage = FileSystemStorage(location=settings.SURVEY_SCANS, base_url=settings.SURVEYS_URL)
|
||||
def get_scan_path(instance, filename):
|
||||
year=instance.survey.expedition.year
|
||||
print "WN: ", type(instance.survey.wallet_number), instance.survey.wallet_number
|
||||
|
@ -5,7 +5,7 @@ sys.path.append('C:\\Expo\\expoweb')
|
||||
from troggle import *
|
||||
os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
|
||||
import troggle.settings as settings
|
||||
import troggle.expo.models as models
|
||||
from troggle.expo.models import *
|
||||
|
||||
#import settings
|
||||
#import expo.models as models
|
||||
@ -13,40 +13,41 @@ import csv
|
||||
import re
|
||||
import datetime
|
||||
|
||||
try:
|
||||
surveytab = open(os.path.join(settings.SURVEYS, "Surveys.csv"))
|
||||
except IOError:
|
||||
import cStringIO, urllib
|
||||
surveytab = cStringIO.StringIO(urllib.urlopen(settings.SURVEYS + "download/Surveys.csv").read())
|
||||
dialect=csv.Sniffer().sniff(surveytab.read())
|
||||
surveytab.seek(0,0)
|
||||
surveyreader = csv.reader(surveytab,dialect=dialect)
|
||||
headers = surveyreader.next()
|
||||
header = dict(zip(headers, range(len(headers)))) #set up a dictionary where the indexes are header names and the values are column numbers
|
||||
def readSurveysFromCSV():
|
||||
try:
|
||||
surveytab = open(os.path.join(settings.SURVEYS, "Surveys.csv"))
|
||||
except IOError:
|
||||
import cStringIO, urllib
|
||||
surveytab = cStringIO.StringIO(urllib.urlopen(settings.SURVEYS + "download/Surveys.csv").read())
|
||||
dialect=csv.Sniffer().sniff(surveytab.read())
|
||||
surveytab.seek(0,0)
|
||||
surveyreader = csv.reader(surveytab,dialect=dialect)
|
||||
headers = surveyreader.next()
|
||||
header = dict(zip(headers, range(len(headers)))) #set up a dictionary where the indexes are header names and the values are column numbers
|
||||
|
||||
# test if the expeditions have been added yet
|
||||
if len(models.Expedition.objects.all())==0:
|
||||
print "There are no expeditions in the database. Please run the logbook parser."
|
||||
sys.exit()
|
||||
models.ScannedImage.objects.all().delete()
|
||||
models.Survey.objects.all().delete()
|
||||
for survey in surveyreader:
|
||||
walletNumberLetter = re.match(r'(?P<number>\d*)(?P<letter>[a-zA-Z]*)',survey[header['Survey Number']]) #I hate this, but some surveys have a letter eg 2000#34a. This line deals with that.
|
||||
# print walletNumberLetter.groups()
|
||||
# test if the expeditions have been added yet
|
||||
if Expedition.objects.count()==0:
|
||||
print "There are no expeditions in the database. Please run the logbook parser."
|
||||
sys.exit()
|
||||
ScannedImage.objects.all().delete()
|
||||
Survey.objects.all().delete()
|
||||
for survey in surveyreader:
|
||||
walletNumberLetter = re.match(r'(?P<number>\d*)(?P<letter>[a-zA-Z]*)',survey[header['Survey Number']]) #I hate this, but some surveys have a letter eg 2000#34a. This line deals with that.
|
||||
# print walletNumberLetter.groups()
|
||||
|
||||
surveyobj = models.Survey(
|
||||
expedition = models.Expedition.objects.filter(year=survey[header['Year']])[0],
|
||||
wallet_number = walletNumberLetter.group('number'),
|
||||
surveyobj = Survey(
|
||||
expedition = Expedition.objects.filter(year=survey[header['Year']])[0],
|
||||
wallet_number = walletNumberLetter.group('number'),
|
||||
|
||||
comments = survey[header['Comments']],
|
||||
location = survey[header['Location']]
|
||||
)
|
||||
surveyobj.wallet_letter = walletNumberLetter.group('letter')
|
||||
if survey[header['Finished']]=='Yes':
|
||||
#try and find the sketch_scan
|
||||
pass
|
||||
surveyobj.save()
|
||||
print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r",
|
||||
comments = survey[header['Comments']],
|
||||
location = survey[header['Location']]
|
||||
)
|
||||
surveyobj.wallet_letter = walletNumberLetter.group('letter')
|
||||
if survey[header['Finished']]=='Yes':
|
||||
#try and find the sketch_scan
|
||||
pass
|
||||
surveyobj.save()
|
||||
print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r",
|
||||
|
||||
def listdir(*directories):
|
||||
try:
|
||||
@ -59,11 +60,15 @@ def listdir(*directories):
|
||||
|
||||
# add survey scans
|
||||
def parseSurveyScans(year):
|
||||
yearFileList = listdir(year.year)
|
||||
# yearFileList = listdir(year.year)
|
||||
yearPath=os.path.join(settings.SURVEY_SCANS, year.year)
|
||||
yearFileList=os.listdir(yearPath)
|
||||
print yearFileList
|
||||
for surveyFolder in yearFileList:
|
||||
try:
|
||||
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
|
||||
scanList = listdir(year.year, surveyFolder)
|
||||
# scanList = listdir(year.year, surveyFolder)
|
||||
scanList=os.listdir(os.path.join(yearPath,surveyFolder))
|
||||
except AttributeError:
|
||||
print surveyFolder + " ignored",
|
||||
continue
|
||||
@ -73,10 +78,10 @@ def parseSurveyScans(year):
|
||||
scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups()
|
||||
scanType,scanNumber,scanFormat=scanChopped
|
||||
except AttributeError:
|
||||
print "Adding scans: " + scan + " ignored \r",
|
||||
print scan + " ignored \r",
|
||||
continue
|
||||
if scanType == 'elev' or scanType == 'extend':
|
||||
scanType = 'elevation'
|
||||
if scanType == 'elev' or scanType == 'extend':
|
||||
scanType = 'elevation'
|
||||
|
||||
if scanNumber=='':
|
||||
scanNumber=1
|
||||
@ -84,11 +89,11 @@ def parseSurveyScans(year):
|
||||
if type(surveyNumber)==types.TupleType:
|
||||
surveyNumber=surveyNumber[0]
|
||||
try:
|
||||
survey=models.Survey.objects.get_or_create(wallet_number=surveyNumber, expedition=year)[0]
|
||||
except models.Survey.MultipleObjectsReturned:
|
||||
survey=models.Survey.objects.filter(wallet_number=surveyNumber, expedition=year)[0]
|
||||
survey=Survey.objects.get_or_create(wallet_number=surveyNumber, expedition=year)[0]
|
||||
except Survey.MultipleObjectsReturned:
|
||||
survey=Survey.objects.filter(wallet_number=surveyNumber, expedition=year)[0]
|
||||
|
||||
scanObj = models.ScannedImage(
|
||||
scanObj = ScannedImage(
|
||||
file=os.path.join(year.year, surveyFolder, scan),
|
||||
contents=scanType,
|
||||
number_in_wallet=scanNumber,
|
||||
@ -96,6 +101,8 @@ def parseSurveyScans(year):
|
||||
)
|
||||
#print "Added scanned image at " + str(scanObj)
|
||||
scanObj.save()
|
||||
|
||||
for year in models.Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then
|
||||
parseSurveyScans(year)
|
||||
|
||||
def parseSurveys():
|
||||
readSurveysFromCSV()
|
||||
for year in Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then
|
||||
parseSurveyScans(year)
|
||||
|
2
urls.py
2
urls.py
@ -76,7 +76,7 @@ urlpatterns = patterns('',
|
||||
#(r'^survey_files/upload/(?P<path>.*)$', view_surveys.upload),
|
||||
|
||||
(r'^survey_scans/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': settings.SURVEYS, 'show_indexes':True}),
|
||||
{'document_root': settings.SURVEY_SCANS, 'show_indexes':True}),
|
||||
|
||||
(r'^photos/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
|
||||
|
Loading…
Reference in New Issue
Block a user