summaryrefslogtreecommitdiffstats
path: root/core/models.py
diff options
context:
space:
mode:
authorMartin Green <martin.speleo@gmail.com>2011-05-01 19:32:41 +0100
committerMartin Green <martin.speleo@gmail.com>2011-05-01 19:32:41 +0100
commita26310767ba885bcb403e08f8060f045e4716e08 (patch)
tree935cdf586e354e94757c1f8dc88584e5f3a491a6 /core/models.py
parentd38a767d7ca1b205be82b8cb674746f638f5fb52 (diff)
downloadtroggle-a26310767ba885bcb403e08f8060f045e4716e08.tar.gz
troggle-a26310767ba885bcb403e08f8060f045e4716e08.tar.bz2
troggle-a26310767ba885bcb403e08f8060f045e4716e08.zip
edit logbooks, new logbook format, increased database normalisation
Diffstat (limited to 'core/models.py')
-rw-r--r--core/models.py59
1 files changed, 48 insertions, 11 deletions
diff --git a/core/models.py b/core/models.py
index 432eca4..73063b2 100644
--- a/core/models.py
+++ b/core/models.py
@@ -232,23 +232,27 @@ class PersonExpedition(TroggleModel):
# Single parsed entry from Logbook
#
class LogbookEntry(TroggleModel):
- date = models.DateField()
- expeditionday = models.ForeignKey("ExpeditionDay", null=True)
+ date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.
+ expeditionday = models.ForeignKey("ExpeditionDay", null=True)#MJG wants to KILL THIS (redundant information)
expedition = models.ForeignKey(Expedition,blank=True,null=True) # yes this is double-
- author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip.
+ #author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip.
# Re: the above- so this field should be "typist" or something, not "author". - AC 15 jun 09
- title = models.CharField(max_length=200)
+ #MJG wants to KILL THIS, as it is typically redundant with PersonTrip.is_logbook_entry_author, in the rare it was not redundanty and of actually interest it could be added to the text.
+ title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
cave = models.ForeignKey('Cave',blank=True,null=True)
place = models.CharField(max_length=100,blank=True,null=True,help_text="Only use this if you haven't chosen a cave")
text = models.TextField()
slug = models.SlugField(max_length=50)
+ filename= models.CharField(max_length=200,null=True)
class Meta:
- verbose_name_plural = "Logbook Entries"
+ verbose_name_plural = "Logbook Entries"
# several PersonTrips point in to this object
- class Meta:
ordering = ('-date',)
+ def isLogbookEntry(self): # Function used in templates
+ return True
+
def get_absolute_url(self):
return urlparse.urljoin(settings.URL_ROOT, reverse('logbookentry',kwargs={'date':self.date,'slug':self.slug}))
@@ -282,22 +286,36 @@ class LogbookEntry(TroggleModel):
class PersonTrip(TroggleModel):
personexpedition = models.ForeignKey("PersonExpedition",null=True)
- expeditionday = models.ForeignKey("ExpeditionDay")
- date = models.DateField()
+ #expeditionday = models.ForeignKey("ExpeditionDay")#MJG wants to KILL THIS (redundant information)
+ #date = models.DateField() #MJG wants to KILL THIS (redundant information)
time_underground = models.FloatField(help_text="In decimal hours")
logbook_entry = models.ForeignKey(LogbookEntry)
is_logbook_entry_author = models.BooleanField()
# sequencing by person (difficult to solve locally)
- persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)
- persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)
+ #persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)#MJG wants to KILL THIS (and use funstion persontrip_next_auto)
+ #persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)#MJG wants to KILL THIS(and use funstion persontrip_prev_auto)
+ def persontrip_next(self):
+ futurePTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__gt = self.logbook_entry.date).order_by('logbook_entry__date').all()
+ if len(futurePTs) > 0:
+ return futurePTs[0]
+ else:
+ return None
+
+ def persontrip_prev(self):
+ pastPTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__lt = self.logbook_entry.date).order_by('-logbook_entry__date').all()
+ if len(pastPTs) > 0:
+ return pastPTs[0]
+ else:
+ return None
+
def place(self):
return self.logbook_entry.cave and self.logbook_entry.cave or self.logbook_entry.place
def __unicode__(self):
- return "%s (%s)" % (self.personexpedition, self.date)
+ return "%s (%s)" % (self.personexpedition, self.logbook_entry.date)
@@ -350,7 +368,18 @@ class Cave(TroggleModel):
survex_file = models.CharField(max_length=100,blank=True,null=True)
description_file = models.CharField(max_length=200,blank=True,null=True)
+ #class Meta:
+ # unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
+ # FIXME Kataster Areas and CUCC defined sub areas need seperating
+
+
#href = models.CharField(max_length=100)
+
+ def reference(self):
+ if self.kataster_number:
+ return "%s-%s" % (self.kat_area(), self.kataster_number)
+ else:
+ return "%s-%s" % (self.kat_area(), self.unofficial_number)
def get_absolute_url(self):
if self.kataster_number:
@@ -421,6 +450,14 @@ class Cave(TroggleModel):
res += "&ndash;" + prevR
return res
+def getCaveByReference(reference):
+ print reference
+ areaname, code = reference.split("-", 1)
+ area = Area.objects.get(short_name = areaname)
+ foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all())
+ assert len(foundCaves) == 1
+ return foundCaves[0]
+
class OtherCaveName(TroggleModel):
name = models.CharField(max_length=160)
cave = models.ForeignKey(Cave)