[svn] Add beginnings of virtual survey binder: new Survey and ScannedImage models, survey parser. Still has lots of problems, but I need some help with the file upload aspect so am committing now. Biggest problem is trying to call save() on the images from the API. It needs arguments that I don't understand. Also, the # in our survey paths was causing trouble. I worked around this with a correctURL method which urlencodes the actual URL, but admin still tries to use a URL with a # in it.

Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8152 by aaron @ 1/15/2009 6:22 AM
This commit is contained in:
substantialnoninfringinguser 2009-05-13 05:27:43 +01:00
parent 95a08ffbd9
commit c6cce8d2fe
7 changed files with 188 additions and 3 deletions

View File

@ -8,6 +8,13 @@ class RoleInline(admin.TabularInline):
class SurvexBlockAdmin(admin.ModelAdmin): class SurvexBlockAdmin(admin.ModelAdmin):
inlines = (RoleInline,) inlines = (RoleInline,)
class SurveyInline(admin.TabularInline):
model = ScannedImage
extra = 4
class SurveyAdmin(admin.ModelAdmin):
inlines = (SurveyInline,)
admin.site.register(Photo) admin.site.register(Photo)
admin.site.register(Cave) admin.site.register(Cave)
admin.site.register(Area) admin.site.register(Area)
@ -24,4 +31,6 @@ admin.site.register(Role)
admin.site.register(LogbookEntry) admin.site.register(LogbookEntry)
admin.site.register(PersonTrip) admin.site.register(PersonTrip)
admin.site.register(QM) admin.site.register(QM)
admin.site.register(Survey, SurveyAdmin)
admin.site.register(ScannedImage)

View File

@ -1,6 +1,10 @@
import urllib
from django.forms import ModelForm from django.forms import ModelForm
from django.db import models from django.db import models
from django.contrib import admin from django.contrib import admin
from django.core.files.storage import FileSystemStorage
import os
import troggle.settings as settings
from models_survex import * from models_survex import *
class Expedition(models.Model): class Expedition(models.Model):
@ -108,7 +112,7 @@ class Cave(models.Model):
length = models.CharField(max_length=100,blank=True,null=True) length = models.CharField(max_length=100,blank=True,null=True)
depth = models.CharField(max_length=100,blank=True,null=True) depth = models.CharField(max_length=100,blank=True,null=True)
extent = models.CharField(max_length=100,blank=True,null=True) extent = models.CharField(max_length=100,blank=True,null=True)
survex_file = models.CharField(max_length=100,blank=True,null=True) survex_file = models.CharField(max_length=100,blank=True,null=True) #should be filefield, need to fix parser first
def __unicode__(self): def __unicode__(self):
if self.kataster_number: if self.kataster_number:
if self.kat_area(): if self.kat_area():
@ -296,3 +300,53 @@ class Photo(models.Model):
def __str__(self): def __str__(self):
return self.caption return self.caption
scansFileStorage = FileSystemStorage(location=settings.SURVEYS, base_url=settings.SURVEYS_URL)
def get_scan_path(instance, filename):
year=instance.survey.expedition_year.year
number="%02d" % instance.survey.wallet_number + instance.survey.wallet_letter #using %02d string formatting because convention was 2009#01
return os.path.join('./',year,year+r'#'+number,instance.contents+str(instance.number_in_wallet)+r'.jpg')
class ScannedImage(models.Model):
file = models.ImageField(storage=scansFileStorage, upload_to=get_scan_path)
scannedBy = models.ForeignKey(Person,blank=True, null=True)
scannedOn = models.DateField(null=True)
survey = models.ForeignKey('Survey')
contents = models.CharField(max_length=20,choices=(('notes','notes'),('plan','plan_sketch'),('elevation','elevation_sketch')))
number_in_wallet = models.IntegerField(null=True)
lon_utm = models.FloatField(blank=True,null=True)
lat_utm = models.FloatField(blank=True,null=True)
#content_type = models.ForeignKey(ContentType)
#object_id = models.PositiveIntegerField()
#location = generic.GenericForeignKey('content_type', 'object_id')
def correctURL(self):
return urllib.quote(self.file.url)
def __str__(self):
return get_scan_path(self,'')
class admin():
pass
class Survey(models.Model):
expedition_year = models.ForeignKey('Expedition')
wallet_number = models.IntegerField(blank=True,null=True)
wallet_letter = models.CharField(max_length=1,blank=True,null=True)
comments = models.TextField(blank=True,null=True)
location = models.CharField(max_length=400,blank=True,null=True)
#notes_scan = models.ForeignKey('ScannedImage',related_name='notes_scan',blank=True, null=True) #Replaced by contents field of ScannedImage model
survex_block = models.ForeignKey('SurvexBlock',blank=True, null=True)
centreline_printed_on = models.DateField(blank=True, null=True)
centreline_printed_by = models.ForeignKey('Person',related_name='centreline_printed_by',blank=True,null=True)
#sketch_scan = models.ForeignKey(ScannedImage,blank=True, null=True) #Replaced by contents field of ScannedImage model
tunnel_file = models.FileField(upload_to='surveyXMLfiles',blank=True, null=True)
tunnel_main_sketch = models.ForeignKey('Survey',blank=True,null=True)
integrated_into_main_sketch_on = models.DateField(blank=True,null=True)
integrated_into_main_sketch_by = models.ForeignKey('Person' ,related_name='integrated_into_main_sketch_by', blank=True,null=True)
rendered_image = models.ImageField(upload_to='renderedSurveys',blank=True,null=True)
def __str__(self):
return self.expedition_year.year+"#"+"%02d" % self.wallet_number
class admin():
pass

View File

@ -1,5 +1,5 @@
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from troggle.expo.models import Cave, CaveAndEntrance from troggle.expo.models import Cave, CaveAndEntrance, Survey
import troggle.settings as settings import troggle.settings as settings
from troggle.expo.forms import CaveForm from troggle.expo.forms import CaveForm
import search import search
@ -33,5 +33,17 @@ def caveSearch(request):
{ 'query_string': query_string, 'found_entries': found_entries, 'settings': settings}) { 'query_string': query_string, 'found_entries': found_entries, 'settings': settings})
#context_instance=RequestContext(request)) #context_instance=RequestContext(request))
def surveyindex(request):
surveys=Survey.objects.all()
return render_to_response('survey.html',{'settings':settings,'surveys':surveys})
def survey(request,survey_id):
surveys=Survey.objects.all()
current_survey=Survey.objects.get(pk=survey_id)
notes=current_survey.scannedimage_set.filter(contents='notes')
planSketches=current_survey.scannedimage_set.filter(contents='plan')
elevationSketches=current_survey.scannedimage_set.filter(contents='elevation')
dictToPass=locals()
dictToPass.update({'settings':settings})
return render_to_response('survey.html',dictToPass)

View File

@ -5,6 +5,7 @@ import expo.models as models
import csv import csv
import re import re
import datetime import datetime
import os
persontab = open(os.path.join(settings.EXPOWEB, "noinfo", "folk.csv")) persontab = open(os.path.join(settings.EXPOWEB, "noinfo", "folk.csv"))
personreader = csv.reader(persontab) personreader = csv.reader(persontab)

86
parsers/surveys.py Normal file
View File

@ -0,0 +1,86 @@
import sys
import os
import types
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
#import settings
#import expo.models as models
import csv
import re
import datetime
surveytab = open(os.path.join(settings.SURVEYS, "Surveys.csv"))
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()
surveyobj = models.Survey(
expedition_year = models.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
# add survey scans
def parseSurveyScans(year):
yearPath=os.path.join(settings.SURVEYS, year.year)
yearFileList=os.listdir(yearPath)
for surveyFolder in yearFileList:
try:
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
scanList=os.listdir(os.path.join(yearPath,surveyFolder))
except AttributeError:
print surveyFolder + " ignored"
continue
for scan in scanList:
try:
scanChopped=re.match(r'([a-zA-Z]*)(\d*)\.(png|jpg|JPG|PNG)',scan).groups()
scanType,scanNumber,scanFormat=scanChopped
except AttributeError:
print scan + " ignored"
continue
if scanNumber=='':
scanNumber=1
if type(surveyNumber)==types.TupleType:
surveyNumber=surveyNumber[0]
try:
survey=models.Survey.objects.get_or_create(wallet_number=surveyNumber, expedition_year=year)[0]
except models.Survey.MultipleObjectsReturned:
survey=models.Survey.objects.filter(wallet_number=surveyNumber, expedition_year=year)[0]
scanObj = models.ScannedImage(
file=os.path.join(yearPath, surveyFolder, scan),
contents=scanType,
number_in_wallet=scanNumber,
survey=survey
)
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)

View File

@ -8,6 +8,22 @@
<script src="{{ settings.MEDIA_URL }}js/base.js" type="text/javascript"></script> <script src="{{ settings.MEDIA_URL }}js/base.js" type="text/javascript"></script>
</head> </head>
<body> <body>
<body onLoad="fadeText()">
<img src="{{ settings.MEDIA_URL }}loserBanner.jpg" style="width:100%;position:absolute; z-index:-4;width:100%;left:0;right:0;height:100px">
<div id="expoHeader" style="display:inline;">
<h1>CUCC Expeditions to Austria: 1976 - </h1>
<div id="expoFinalDate" style="display:inline;" >
<h1>1976</h1>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<center><iframe src="{{ settings.MEDIA_URL }}intro.html" style="height:600px; width:800px; border:hidden"></iframe></center>
</body>
<div id="editLink" style="right:0px; top:0px; text-align: right; position: absolute; top:0; right:0; z-index:1"> <div id="editLink" style="right:0px; top:0px; text-align: right; position: absolute; top:0; right:0; z-index:1">
{% block editLink %}not editable {% block editLink %}not editable
{% endblock %} {% endblock %}

View File

@ -27,10 +27,17 @@ urlpatterns = patterns('',
(r'^statistics/?$', stats), (r'^statistics/?$', stats),
(r'^survey/?$', surveyindex),
(r'^survey/(?P<survey_id>.*)$', survey),
(r'^admin/doc/?', include('django.contrib.admindocs.urls')), (r'^admin/doc/?', include('django.contrib.admindocs.urls')),
(r'^admin/(.*)', admin.site.root), (r'^admin/(.*)', admin.site.root),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
(r'^survey_scans/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.SURVEYS, 'show_indexes':True}),
) )