2009-05-13 05:13:38 +01:00
|
|
|
from django.db import models
|
2009-05-13 05:52:59 +01:00
|
|
|
from django.conf import settings
|
2009-05-13 05:38:18 +01:00
|
|
|
import os
|
2009-05-13 05:21:39 +01:00
|
|
|
|
2009-07-27 13:43:43 +01:00
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# These will allow browsing and editing of the survex data
|
|
|
|
###########################################################
|
|
|
|
# Needs to add:
|
|
|
|
# Equates
|
|
|
|
# reloading
|
|
|
|
|
2009-08-01 07:31:27 +01:00
|
|
|
class SurvexDirectory(models.Model):
|
|
|
|
path = models.CharField(max_length=200)
|
|
|
|
cave = models.ForeignKey('Cave', blank=True, null=True)
|
|
|
|
primarysurvexfile = models.ForeignKey('SurvexFile', related_name='primarysurvexfile', blank=True, null=True)
|
|
|
|
# could also include files in directory but not referenced
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('id',)
|
|
|
|
|
|
|
|
class SurvexFile(models.Model):
|
|
|
|
path = models.CharField(max_length=200)
|
|
|
|
survexdirectory = models.ForeignKey("SurvexDirectory", blank=True, null=True)
|
|
|
|
cave = models.ForeignKey('Cave', blank=True, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('id',)
|
|
|
|
|
|
|
|
def exists(self):
|
|
|
|
fname = os.path.join(settings.SURVEX_DATA, self.path + ".svx")
|
|
|
|
return os.path.isfile(fname)
|
|
|
|
|
|
|
|
def OpenFile(self):
|
|
|
|
fname = os.path.join(settings.SURVEX_DATA, self.path + ".svx")
|
|
|
|
return open(fname)
|
|
|
|
|
|
|
|
def SetDirectory(self):
|
|
|
|
dirpath = os.path.split(self.path)[0]
|
|
|
|
survexdirectorylist = SurvexDirectory.objects.filter(cave=self.cave, path=dirpath)
|
|
|
|
if survexdirectorylist:
|
|
|
|
self.survexdirectory = survexdirectorylist[0]
|
|
|
|
else:
|
|
|
|
survexdirectory = SurvexDirectory(path=dirpath, cave=self.cave, primarysurvexfile=self)
|
|
|
|
survexdirectory.save()
|
|
|
|
self.survexdirectory = survexdirectory
|
|
|
|
self.save()
|
|
|
|
|
2009-08-05 11:58:36 +01:00
|
|
|
class SurvexEquate(models.Model):
|
|
|
|
cave = models.ForeignKey('Cave', blank=True, null=True)
|
|
|
|
|
|
|
|
class SurvexStation(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
block = models.ForeignKey('SurvexBlock')
|
|
|
|
equate = models.ForeignKey('SurvexEquate', blank=True, null=True)
|
|
|
|
|
|
|
|
class SurvexLeg(models.Model):
|
|
|
|
block = models.ForeignKey('SurvexBlock')
|
|
|
|
#title = models.ForeignKey('SurvexTitle')
|
|
|
|
stationfrom = models.ForeignKey('SurvexStation', related_name='stationfrom')
|
|
|
|
stationto = models.ForeignKey('SurvexStation', related_name='stationto')
|
|
|
|
tape = models.FloatField()
|
|
|
|
compass = models.FloatField()
|
|
|
|
clino = models.FloatField()
|
2009-07-27 13:43:43 +01:00
|
|
|
#
|
|
|
|
# Single SurvexBlock
|
|
|
|
#
|
2009-05-13 05:13:38 +01:00
|
|
|
class SurvexBlock(models.Model):
|
2009-08-01 07:31:27 +01:00
|
|
|
name = models.CharField(max_length=100)
|
2009-05-13 05:13:51 +01:00
|
|
|
parent = models.ForeignKey('SurvexBlock', blank=True, null=True)
|
2009-05-13 05:13:38 +01:00
|
|
|
text = models.TextField()
|
2009-08-01 07:31:27 +01:00
|
|
|
cave = models.ForeignKey('Cave', blank=True, null=True)
|
2009-05-13 05:38:18 +01:00
|
|
|
|
2009-05-13 05:39:52 +01:00
|
|
|
date = models.DateField(blank=True, null=True)
|
2009-08-01 07:31:27 +01:00
|
|
|
expedition = models.ForeignKey('Expedition', blank=True, null=True)
|
|
|
|
|
|
|
|
survexfile = models.ForeignKey("SurvexFile", blank=True, null=True)
|
|
|
|
begin_char = models.IntegerField() # code for where in the survex data files this block sits
|
|
|
|
survexpath = models.CharField(max_length=200) # the path for the survex stations
|
|
|
|
refscandir = models.CharField(max_length=100)
|
2009-08-05 11:58:36 +01:00
|
|
|
totalleglength = models.FloatField()
|
2009-05-13 05:38:18 +01:00
|
|
|
|
2009-05-13 05:43:20 +01:00
|
|
|
class Meta:
|
2009-08-01 07:31:27 +01:00
|
|
|
ordering = ('id',)
|
2009-05-13 05:43:20 +01:00
|
|
|
|
2009-05-13 05:13:38 +01:00
|
|
|
def __unicode__(self):
|
2009-07-27 13:43:43 +01:00
|
|
|
return self.name and unicode(self.name) or 'no name'
|
|
|
|
|
2009-05-13 05:43:20 +01:00
|
|
|
def GetPersonroles(self):
|
|
|
|
res = [ ]
|
|
|
|
for personrole in self.personrole_set.order_by('personexpedition'):
|
|
|
|
if res and res[-1]['person'] == personrole.personexpedition.person:
|
|
|
|
res[-1]['roles'] += ", " + str(personrole.role)
|
|
|
|
else:
|
|
|
|
res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year, 'roles':str(personrole.role)})
|
|
|
|
return res
|
2009-05-13 05:38:18 +01:00
|
|
|
|
2009-08-05 11:58:36 +01:00
|
|
|
def MakeSurvexStation(self, name):
|
|
|
|
ssl = self.survexstation_set.filter(name=name)
|
|
|
|
if ssl:
|
|
|
|
assert len(ssl) == 1
|
|
|
|
return ssl[0]
|
|
|
|
ss = SurvexStation(name=name, block=self)
|
|
|
|
ss.save()
|
|
|
|
return ss
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-01 07:31:27 +01:00
|
|
|
class SurvexTitle(models.Model):
|
|
|
|
survexblock = models.ForeignKey('SurvexBlock')
|
|
|
|
title = models.CharField(max_length=200)
|
|
|
|
cave = models.ForeignKey('Cave', blank=True, null=True)
|
2009-07-27 13:43:43 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# member of a SurvexBlock
|
|
|
|
#
|
|
|
|
class PersonRole(models.Model):
|
2009-08-05 11:58:36 +01:00
|
|
|
survexblock = models.ForeignKey('SurvexBlock')
|
2009-07-27 13:43:43 +01:00
|
|
|
|
|
|
|
ROLE_CHOICES = (
|
|
|
|
('insts','Instruments'),
|
|
|
|
('dog','Other'),
|
|
|
|
('notes','Notes'),
|
|
|
|
('pics','Pictures'),
|
|
|
|
('tape','Tape measure'),
|
2009-08-01 07:31:27 +01:00
|
|
|
('useless','Useless'),
|
|
|
|
('helper','Helper'),
|
|
|
|
('disto','Disto'),
|
|
|
|
('consultant','Consultant'),
|
2009-07-27 13:43:43 +01:00
|
|
|
)
|
|
|
|
nrole = models.CharField(choices=ROLE_CHOICES, max_length=200, blank=True, null=True)
|
|
|
|
|
|
|
|
# increasing levels of precision
|
2009-08-01 07:31:27 +01:00
|
|
|
personname = models.CharField(max_length=100)
|
|
|
|
person = models.ForeignKey('Person', blank=True, null=True)
|
|
|
|
personexpedition = models.ForeignKey('PersonExpedition', blank=True, null=True)
|
2009-07-27 13:43:43 +01:00
|
|
|
persontrip = models.ForeignKey('PersonTrip', blank=True, null=True)
|
2009-08-01 07:31:27 +01:00
|
|
|
|
2009-07-27 13:43:43 +01:00
|
|
|
def __unicode__(self):
|
2009-08-05 11:58:36 +01:00
|
|
|
return unicode(self.person) + " - " + unicode(self.survexblock) + " - " + unicode(self.nrole)
|
2009-07-27 13:43:43 +01:00
|
|
|
|
2009-05-13 05:39:52 +01:00
|
|
|
|