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-05-13 05:13:38 +01:00
|
|
|
class SurvexBlock(models.Model):
|
2009-05-13 05:13:51 +01:00
|
|
|
name = models.CharField(max_length=100, blank=True, null=True)
|
|
|
|
parent = models.ForeignKey('SurvexBlock', blank=True, null=True)
|
2009-05-13 05:13:38 +01:00
|
|
|
text = models.TextField()
|
2009-05-13 05:39:52 +01:00
|
|
|
|
|
|
|
# non-useful representation of incomplete data
|
2009-05-13 05:21:39 +01:00
|
|
|
start_year = models.IntegerField(blank=True, null=True)
|
|
|
|
start_month = models.IntegerField(blank=True, null=True)
|
|
|
|
start_day = models.IntegerField(blank=True, null=True)
|
|
|
|
end_year = models.IntegerField(blank=True, null=True)
|
|
|
|
end_month = models.IntegerField(blank=True, null=True)
|
|
|
|
end_day = models.IntegerField(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)
|
|
|
|
survexpath = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
# superfluous
|
|
|
|
person = models.ManyToManyField('Person', through='PersonRole', blank=True, null=True)
|
2009-05-13 05:38:18 +01:00
|
|
|
|
2009-05-13 05:39:52 +01:00
|
|
|
# code for where in the survex data files this block sits
|
2009-05-13 05:13:38 +01:00
|
|
|
begin_file = models.CharField(max_length=200)
|
|
|
|
begin_char = models.IntegerField()
|
2009-05-13 05:13:51 +01:00
|
|
|
end_file = models.CharField(max_length=200, blank=True, null=True)
|
|
|
|
end_char = models.IntegerField(blank=True, null=True)
|
2009-05-13 05:38:18 +01:00
|
|
|
|
2009-05-13 05:43:20 +01:00
|
|
|
class Meta:
|
|
|
|
ordering = ('date', 'survexpath')
|
|
|
|
|
2009-05-13 05:13:38 +01:00
|
|
|
def __unicode__(self):
|
2009-05-13 05:13:51 +01:00
|
|
|
return unicode(self.name)
|
2009-05-13 05:38:18 +01:00
|
|
|
|
|
|
|
def filecontents(self):
|
|
|
|
f = os.path.join(settings.SURVEX_DATA, self.begin_file)
|
2009-05-13 05:39:52 +01:00
|
|
|
fin = open(f, "rb")
|
|
|
|
res = fin.read().decode("latin1")
|
2009-05-13 05:38:18 +01:00
|
|
|
fin.close()
|
|
|
|
return res
|
|
|
|
|
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)})
|
|
|
|
print res
|
|
|
|
return res
|
2009-05-13 05:38:18 +01:00
|
|
|
|
2009-05-13 05:21:39 +01:00
|
|
|
|
|
|
|
class PersonRole(models.Model):
|
2009-05-13 05:38:18 +01:00
|
|
|
personexpedition = models.ForeignKey('PersonExpedition')
|
2009-05-13 05:21:39 +01:00
|
|
|
person = models.ForeignKey('Person')
|
|
|
|
survex_block = models.ForeignKey('SurvexBlock')
|
|
|
|
role = models.ForeignKey('Role')
|
|
|
|
def __unicode__(self):
|
|
|
|
return unicode(self.person) + " - " + unicode(self.survex_block) + " - " + unicode(self.role)
|
|
|
|
|
|
|
|
class Role(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
def __unicode__(self):
|
2009-05-13 05:39:52 +01:00
|
|
|
return unicode(self.name)
|
|
|
|
|