summaryrefslogtreecommitdiffstats
path: root/core/models/logbooks.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/models/logbooks.py')
-rw-r--r--core/models/logbooks.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/core/models/logbooks.py b/core/models/logbooks.py
index 521eb49..680036a 100644
--- a/core/models/logbooks.py
+++ b/core/models/logbooks.py
@@ -33,6 +33,7 @@ todo='''
'''
class CaveSlug(models.Model):
+ """Moved here to avoid nasty cyclic import error"""
cave = models.ForeignKey('Cave',on_delete=models.CASCADE)
slug = models.SlugField(max_length=50, unique = True)
primary = models.BooleanField(default=False)
@@ -41,7 +42,6 @@ class LogbookEntry(TroggleModel):
"""Single parsed entry from Logbook
"""
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.ld()
- # expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.SET_NULL)#MJG wants to KILL THIS (redundant information)
expedition = models.ForeignKey(Expedition,blank=True, null=True,on_delete=models.SET_NULL) # yes this is double-
title = models.CharField(max_length=200)
cave_slug = models.SlugField(max_length=50, blank=True, null=True)
@@ -77,9 +77,16 @@ class LogbookEntry(TroggleModel):
def DayIndex(self):
"""This is used to set different colours for the different trips on
the calendar view of the expedition"""
- index = list(LogbookEntry.objects.filter(date=self.date)).index(self)
- if index not in range(0,10):
- print(f"Unexpected LogbookEntry DayIndex '{index}' {self}")
+ mx = 10
+ todays = list(LogbookEntry.objects.filter(date=self.date))
+ if self in todays:
+ index = todays.index(self)
+ else:
+ print(f"DayIndex: Synchronization error. Restart server. {self}")
+ index = 0
+
+ if index not in range(0, mx):
+ print(f"DayIndex: More than {mx-1} LogbookEntry items on one day '{index}' {self}")
index = 0
return index