diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:27:43 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 05:27:43 +0100 |
commit | c6cce8d2fe470b42740258e737877d94d1b3fdb2 (patch) | |
tree | 4b148e1ad42906e0eca59873264da1b96adc6df9 /expo/models.py | |
parent | 95a08ffbd9459d200d20863d1a59ffe475868600 (diff) | |
download | troggle-c6cce8d2fe470b42740258e737877d94d1b3fdb2.tar.gz troggle-c6cce8d2fe470b42740258e737877d94d1b3fdb2.tar.bz2 troggle-c6cce8d2fe470b42740258e737877d94d1b3fdb2.zip |
[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
Diffstat (limited to 'expo/models.py')
-rw-r--r-- | expo/models.py | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/expo/models.py b/expo/models.py index 1723f4a..a75e8ed 100644 --- a/expo/models.py +++ b/expo/models.py @@ -1,6 +1,10 @@ +import urllib
from django.forms import ModelForm
from django.db import models
from django.contrib import admin
+from django.core.files.storage import FileSystemStorage
+import os
+import troggle.settings as settings
from models_survex import *
class Expedition(models.Model):
@@ -108,7 +112,7 @@ class Cave(models.Model): length = 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)
- 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):
if self.kataster_number:
if self.kat_area():
@@ -296,3 +300,53 @@ class Photo(models.Model): def __str__(self):
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
+
\ No newline at end of file |