[svn] Further attempts to make troggle work on windows using surveys stored on an external server

settings.PHOTOS changed to setting.PHOTO_ROOT
Made databaseReset.py get info from external server if appropriate (hope this did not break linus disk based scripts)
Still needs more work, to get everything working
Auto create photos directory if it does not already exist

Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8262 by julian @ 3/2/2009 1:30 AM
This commit is contained in:
substantialnoninfringinguser 2009-05-13 05:58:18 +01:00
parent 4b34241a16
commit e8da6b9b8b
5 changed files with 26 additions and 10 deletions

View File

@ -17,6 +17,10 @@ user.is_staff = True
user.is_superuser = True user.is_superuser = True
user.save() user.save()
#Make directories that troggle requires
if not os.path.isdir(settings.PHOTOS_ROOT):
os.mkdir(settings.PHOTOS_ROOT)
import parsers.cavetab import parsers.cavetab
parsers.cavetab.LoadCaveTab() parsers.cavetab.LoadCaveTab()
import parsers.people import parsers.people

View File

@ -461,7 +461,7 @@ class QM(TroggleModel):
QMnumber=str(self.found_by.cave)+'-'+str(self.found_by.date.year)+"-"+str(self.number)+self.grade QMnumber=str(self.found_by.cave)+'-'+str(self.found_by.date.year)+"-"+str(self.number)+self.grade
return str(QMnumber) return str(QMnumber)
photoFileStorage = FileSystemStorage(location=settings.EXPOWEB+'photos', base_url=settings.PHOTOS_URL) photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL)
class Photo(TroggleModel): class Photo(TroggleModel):
caption = models.CharField(max_length=1000,blank=True,null=True) caption = models.CharField(max_length=1000,blank=True,null=True)
contains_person_trip = models.ManyToManyField(PersonTrip,blank=True,null=True) contains_person_trip = models.ManyToManyField(PersonTrip,blank=True,null=True)

View File

@ -13,7 +13,11 @@ import csv
import re import re
import datetime import datetime
surveytab = open(os.path.join(settings.SURVEYS, "Surveys.csv")) 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()) dialect=csv.Sniffer().sniff(surveytab.read())
surveytab.seek(0,0) surveytab.seek(0,0)
surveyreader = csv.reader(surveytab,dialect=dialect) surveyreader = csv.reader(surveytab,dialect=dialect)
@ -29,7 +33,7 @@ models.Survey.objects.all().delete()
for survey in surveyreader: 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. 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() # print walletNumberLetter.groups()
surveyobj = models.Survey( surveyobj = models.Survey(
expedition = models.Expedition.objects.filter(year=survey[header['Year']])[0], expedition = models.Expedition.objects.filter(year=survey[header['Year']])[0],
wallet_number = walletNumberLetter.group('number'), wallet_number = walletNumberLetter.group('number'),
@ -43,15 +47,23 @@ for survey in surveyreader:
pass pass
surveyobj.save() surveyobj.save()
print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r", print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r",
def listdir(*directories):
try:
return os.listdir(os.path.join(settings.SURVEYS, *directories))
except:
import urllib
url = settings.SURVEYS + reduce(lambda x, y: x + "/" + y, ["listdir"] + list(directories))
folders = urllib.urlopen(url.replace("#", "%23")).readlines()
return [folder.rstrip(r"/") for folder in folders]
# add survey scans # add survey scans
def parseSurveyScans(year): def parseSurveyScans(year):
yearPath=os.path.join(settings.SURVEYS, year.year) yearFileList = listdir(year.year)
yearFileList=os.listdir(yearPath)
for surveyFolder in yearFileList: for surveyFolder in yearFileList:
try: try:
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups() surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
scanList=os.listdir(os.path.join(yearPath,surveyFolder)) scanList = listdir(year.year, surveyFolder)
except AttributeError: except AttributeError:
print surveyFolder + " ignored", print surveyFolder + " ignored",
continue continue

View File

@ -33,7 +33,7 @@ USE_I18N = True
# trailing slash. # trailing slash.
# Examples: "http://foo.com/media/", "/media/". # Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/troggle/media-admin/' ADMIN_MEDIA_PREFIX = '/troggle/media-admin/'
PHOTOS = os.path.join(EXPOWEB, 'photos') PHOTOS_ROOT = os.path.join(EXPOWEB, 'photos')
MEDIA_URL = URL_ROOT+'/site_media/' MEDIA_URL = URL_ROOT+'/site_media/'
SURVEYS_URL = URL_ROOT+'/survey_scans/' SURVEYS_URL = URL_ROOT+'/survey_scans/'
PHOTOS_URL = URL_ROOT+'/photos/' PHOTOS_URL = URL_ROOT+'/photos/'

View File

@ -19,7 +19,7 @@ urlpatterns = patterns('',
#(r'^person/(?P<person_id>\d*)/?$', views_logbooks.person), #(r'^person/(?P<person_id>\d*)/?$', views_logbooks.person),
url(r'^person/(?P<first_name>[A-Z]*[a-z\-\']*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-z\-]*)/?', views_logbooks.person, name="person"), url(r'^person/(?P<first_name>[A-Z]*[a-z\-\']*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-z\-]*)/?', views_logbooks.person, name="person"),
#url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"), #url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"),
url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"), url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"),
url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-z]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"), url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-z]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"),
url(r'^logbookentry/(.+)$', views_logbooks.logbookentry,name="logbookentry"), url(r'^logbookentry/(.+)$', views_logbooks.logbookentry,name="logbookentry"),
@ -76,5 +76,5 @@ urlpatterns = patterns('',
{'document_root': settings.SURVEYS, 'show_indexes':True}), {'document_root': settings.SURVEYS, 'show_indexes':True}),
(r'^photos/(?P<path>.*)$', 'django.views.static.serve', (r'^photos/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.PHOTOS, 'show_indexes':True}), {'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
) )