forked from expo/troggle
153 lines
6.2 KiB
Python
153 lines
6.2 KiB
Python
|
from django.db import models
|
||
|
|
||
|
class Area(models.Model):
|
||
|
short_name = models.CharField(max_length=100)
|
||
|
name = models.CharField(max_length=200, blank=True, null=True)
|
||
|
description = models.TextField(blank=True,null=True)
|
||
|
parent = models.ForeignKey('Area', blank=True, null=True)
|
||
|
def __unicode__(self):
|
||
|
if self.parent:
|
||
|
return unicode(self.parent) + u" - " + unicode(self.short_name)
|
||
|
else:
|
||
|
return unicode(self.short_name)
|
||
|
def kat_area(self):
|
||
|
if self.short_name in ["1623", "1626"]:
|
||
|
return self.short_name
|
||
|
elif self.parent:
|
||
|
return self.parent.kat_area()
|
||
|
|
||
|
class CaveAndEntrance(models.Model):
|
||
|
cave = models.ForeignKey('Cave')
|
||
|
entrance = models.ForeignKey('Entrance')
|
||
|
entrance_letter = models.CharField(max_length=20,blank=True,null=True)
|
||
|
def __unicode__(self):
|
||
|
return unicode(self.cave) + unicode(self.entrance_letter)
|
||
|
|
||
|
class Cave(models.Model):
|
||
|
official_name = models.CharField(max_length=160)
|
||
|
area = models.ManyToManyField(Area, blank=True, null=True)
|
||
|
kataster_code = models.CharField(max_length=20,blank=True,null=True)
|
||
|
kataster_number = models.CharField(max_length=10,blank=True, null=True)
|
||
|
unofficial_number = models.CharField(max_length=30,blank=True, null=True)
|
||
|
entrances = models.ManyToManyField('Entrance', through='CaveAndEntrance')
|
||
|
explorers = models.TextField(blank=True,null=True)
|
||
|
underground_description = models.TextField(blank=True,null=True)
|
||
|
equipment = models.TextField(blank=True,null=True)
|
||
|
references = models.TextField(blank=True,null=True)
|
||
|
survey = models.TextField(blank=True,null=True)
|
||
|
kataster_status = models.TextField(blank=True,null=True)
|
||
|
underground_centre_line = models.TextField(blank=True,null=True)
|
||
|
notes = models.TextField(blank=True,null=True)
|
||
|
length = models.CharField(max_length=40,blank=True,null=True)
|
||
|
depth = models.CharField(max_length=40,blank=True,null=True)
|
||
|
extent = models.CharField(max_length=40,blank=True,null=True)
|
||
|
survex_file = models.CharField(max_length=100,blank=True,null=True)
|
||
|
def __unicode__(self):
|
||
|
if self.kataster_number:
|
||
|
if self.kat_area():
|
||
|
return self.kat_area() + u": " + self.kataster_number
|
||
|
else:
|
||
|
return unicode(l) + u": " + self.kataster_number
|
||
|
else:
|
||
|
if self.kat_area():
|
||
|
return self.kat_area() + u": " + self.unofficial_number
|
||
|
else:
|
||
|
return self.unofficial_number
|
||
|
def kat_area(self):
|
||
|
for a in self.area.all():
|
||
|
if a.kat_area():
|
||
|
return a.kat_area()
|
||
|
def entrances(self):
|
||
|
return CaveAndEntrance.objects.filter(cave=self)
|
||
|
def entrancelist(self):
|
||
|
rs = []
|
||
|
res = ""
|
||
|
for e in CaveAndEntrance.objects.filter(cave=self):
|
||
|
rs.append(e.entrance_letter)
|
||
|
rs.sort()
|
||
|
prevR = None
|
||
|
n = 0
|
||
|
for r in rs:
|
||
|
if prevR:
|
||
|
if chr(ord(prevR) + 1 ) == r:
|
||
|
prevR = r
|
||
|
n += 1
|
||
|
else:
|
||
|
if n == 0:
|
||
|
res += ", " + prevR
|
||
|
else:
|
||
|
res += "–" + prevR
|
||
|
else:
|
||
|
prevR = r
|
||
|
n = 0
|
||
|
res += r
|
||
|
if n == 0:
|
||
|
res += ", " + prevR
|
||
|
else:
|
||
|
res += "–" + prevR
|
||
|
return res
|
||
|
|
||
|
|
||
|
class OtherCaveName(models.Model):
|
||
|
name = models.CharField(max_length=160)
|
||
|
cave = models.ForeignKey(Cave)
|
||
|
def __unicode__(self):
|
||
|
return unicode(self.name)
|
||
|
|
||
|
class SurveyStation(models.Model):
|
||
|
name = models.CharField(max_length=200)
|
||
|
def __unicode__(self):
|
||
|
return unicode(self.name)
|
||
|
|
||
|
class Entrance(models.Model):
|
||
|
name = models.CharField(max_length=60, blank=True,null=True)
|
||
|
entrance_description = models.TextField(blank=True,null=True)
|
||
|
explorers = models.TextField(blank=True,null=True)
|
||
|
map_description = models.TextField(blank=True,null=True)
|
||
|
location_description = models.TextField(blank=True,null=True)
|
||
|
approach = models.TextField(blank=True,null=True)
|
||
|
underground_description = models.TextField(blank=True,null=True)
|
||
|
photo = models.TextField(blank=True,null=True)
|
||
|
MARKING_CHOICES = (
|
||
|
('P', 'Paint'),
|
||
|
('P?', 'Paint (?)'),
|
||
|
('T', 'Tag'),
|
||
|
('T?', 'Tag (?)'),
|
||
|
('R', 'Retagged'),
|
||
|
('S', 'Spit'),
|
||
|
('S?', 'Spit (?)'),
|
||
|
('U', 'Unmarked'),
|
||
|
('?', 'Unknown'))
|
||
|
marking = models.CharField(max_length=2, choices=MARKING_CHOICES)
|
||
|
marking_comment = models.TextField(blank=True,null=True)
|
||
|
FINDABLE_CHOICES = (
|
||
|
('?', 'To be confirmed ...'),
|
||
|
('S', 'Surveyed'),
|
||
|
('L', 'Lost'),
|
||
|
('R', 'Refindable'))
|
||
|
findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True)
|
||
|
findability_description = models.TextField(blank=True,null=True)
|
||
|
alt = models.TextField(blank=True, null=True)
|
||
|
northing = models.TextField(blank=True, null=True)
|
||
|
easting = models.TextField(blank=True, null=True)
|
||
|
tag_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="tag_station")
|
||
|
exact_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="exact_station")
|
||
|
other_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="other_station")
|
||
|
other_description = models.TextField(blank=True,null=True)
|
||
|
bearings = models.TextField(blank=True,null=True)
|
||
|
def __unicode__(self):
|
||
|
a = CaveAndEntrance.objects.filter(entrance = self)
|
||
|
name = u''
|
||
|
if self.name:
|
||
|
name = unicode(self.name) + u' '
|
||
|
if len(a) == 1:
|
||
|
return name + unicode(a[0])
|
||
|
return name + unicode(a)
|
||
|
def marking_val(self):
|
||
|
for m in self.MARKING_CHOICES:
|
||
|
if m[0] == self.marking:
|
||
|
return m[1]
|
||
|
def findability_val(self):
|
||
|
for f in self.FINDABLE_CHOICES:
|
||
|
if f[0] == self.findability:
|
||
|
return f[1]
|