Fixing dates on expedition table

This commit is contained in:
2023-01-29 22:11:00 +00:00
parent 89d0e1723e
commit 7d98980121
4 changed files with 38 additions and 45 deletions

View File

@@ -21,7 +21,6 @@ from django.template import Context, loader
from django.urls import reverse
import settings
#from troggle.core.models.qm import CaveSlug
from troggle.core.models.survex import SurvexStation
from troggle.core.models.troggle import (DataIssue, Expedition, Person,
PersonExpedition, TroggleModel)
@@ -33,6 +32,11 @@ todo='''
- Rename PersonTrip as PersonLogEntry or similar
'''
class CaveSlug(models.Model):
cave = models.ForeignKey('Cave',on_delete=models.CASCADE)
slug = models.SlugField(max_length=50, unique = True)
primary = models.BooleanField(default=False)
class LogbookEntry(TroggleModel):
"""Single parsed entry from Logbook
"""
@@ -112,11 +116,6 @@ class PersonTrip(TroggleModel):
def __str__(self):
return f'{self.personexpedition} ({self.logbook_entry.date})'
class CaveSlug(models.Model):
cave = models.ForeignKey('Cave',on_delete=models.CASCADE)
slug = models.SlugField(max_length=50, unique = True)
primary = models.BooleanField(default=False)
class QM(TroggleModel):
"""This is based on qm.csv in trunk/expoweb/1623/204 which has the fields:

View File

@@ -82,33 +82,33 @@ class Expedition(TroggleModel):
return urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
# construction function. should be moved out
def get_expedition_day(self, date):
expeditiondays = self.expeditionday_set.filter(date=date)
if expeditiondays:
if len(expeditiondays) == 1:
return expeditiondays[0]
else:
message =f'! - More than one expeditionday for the same date: {date} .\n - This should never happen. \n - Restart mysql and run reset to clean database.'
DataIssue.objects.create(parser='expedition', message=message)
return expeditiondays[0]
res = ExpeditionDay(expedition=self, date=date)
res.save()
return res
# def get_expedition_day(self, date):
# expeditiondays = self.expeditionday_set.filter(date=date)
# if expeditiondays:
# if len(expeditiondays) == 1:
# return expeditiondays[0]
# else:
# message =f'! - More than one expeditionday for the same date: {date} .\n - This should never happen. \n - Restart mysql and run reset to clean database.'
# DataIssue.objects.create(parser='expedition', message=message)
# return expeditiondays[0]
# res = ExpeditionDay(expedition=self, date=date)
# res.save()
# return res
def day_min(self):
"""First day of expedition
"""
res = self.expeditionday_set.all()
return res and res[0] or None
# def day_min(self):
# """First day of expedition
# """
# res = self.expeditionday_set.all()
# return res and res[0] or None
def day_max(self):
"""last day of expedition
"""
res = self.expeditionday_set.all()
return res and res[len(res) - 1] or None
# def day_max(self):
# """last day of expedition
# """
# res = self.expeditionday_set.all()
# return res and res[len(res) - 1] or None
class ExpeditionDay(TroggleModel):
"""Exists only so that we can get all logbook trips on this day
"""Exists only on Expedition now. Removed from logbookentry, persontrip, survex stuff etc.
"""
expedition = models.ForeignKey("Expedition",on_delete=models.CASCADE)
date = models.DateField()
@@ -209,10 +209,10 @@ class PersonExpedition(TroggleModel):
return sum([survexblock.legslength for survexblock in set(survexblocks)])
# would prefer to return actual person trips so we could link to first and last ones
def day_min(self):
res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
return res["day_min"]
# def day_min(self):
# res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
# return res["day_min"]
def day_max(self):
res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date"))
return res["day_max"]
# def day_max(self):
# res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date"))
# return res["day_max"]