2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-26 01:01:53 +00:00

Fixing dates on expedition table

This commit is contained in:
Philip Sargent 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 from django.urls import reverse
import settings import settings
#from troggle.core.models.qm import CaveSlug
from troggle.core.models.survex import SurvexStation from troggle.core.models.survex import SurvexStation
from troggle.core.models.troggle import (DataIssue, Expedition, Person, from troggle.core.models.troggle import (DataIssue, Expedition, Person,
PersonExpedition, TroggleModel) PersonExpedition, TroggleModel)
@ -33,6 +32,11 @@ todo='''
- Rename PersonTrip as PersonLogEntry or similar - 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): class LogbookEntry(TroggleModel):
"""Single parsed entry from Logbook """Single parsed entry from Logbook
""" """
@ -113,11 +117,6 @@ class PersonTrip(TroggleModel):
def __str__(self): def __str__(self):
return f'{self.personexpedition} ({self.logbook_entry.date})' 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): class QM(TroggleModel):
"""This is based on qm.csv in trunk/expoweb/1623/204 which has the fields: """This is based on qm.csv in trunk/expoweb/1623/204 which has the fields:
"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment" "Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment"

View File

@ -82,33 +82,33 @@ class Expedition(TroggleModel):
return urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year])) return urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
# construction function. should be moved out # construction function. should be moved out
def get_expedition_day(self, date): # def get_expedition_day(self, date):
expeditiondays = self.expeditionday_set.filter(date=date) # expeditiondays = self.expeditionday_set.filter(date=date)
if expeditiondays: # if expeditiondays:
if len(expeditiondays) == 1: # if len(expeditiondays) == 1:
return expeditiondays[0] # return expeditiondays[0]
else: # 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.' # 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) # DataIssue.objects.create(parser='expedition', message=message)
return expeditiondays[0] # return expeditiondays[0]
res = ExpeditionDay(expedition=self, date=date) # res = ExpeditionDay(expedition=self, date=date)
res.save() # res.save()
return res # return res
def day_min(self): # def day_min(self):
"""First day of expedition # """First day of expedition
""" # """
res = self.expeditionday_set.all() # res = self.expeditionday_set.all()
return res and res[0] or None # return res and res[0] or None
def day_max(self): # def day_max(self):
"""last day of expedition # """last day of expedition
""" # """
res = self.expeditionday_set.all() # res = self.expeditionday_set.all()
return res and res[len(res) - 1] or None # return res and res[len(res) - 1] or None
class ExpeditionDay(TroggleModel): 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) expedition = models.ForeignKey("Expedition",on_delete=models.CASCADE)
date = models.DateField() date = models.DateField()
@ -209,10 +209,10 @@ class PersonExpedition(TroggleModel):
return sum([survexblock.legslength for survexblock in set(survexblocks)]) 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 # would prefer to return actual person trips so we could link to first and last ones
def day_min(self): # def day_min(self):
res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date")) # res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
return res["day_min"] # return res["day_min"]
def day_max(self): # def day_max(self):
res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date")) # res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date"))
return res["day_max"] # return res["day_max"]

View File

@ -58,7 +58,6 @@ def notablepersons(request):
def expedition(request, expeditionname): def expedition(request, expeditionname):
'''Returns a rendered page for one expedition, specified by the year e.g. '2019'. '''Returns a rendered page for one expedition, specified by the year e.g. '2019'.
If page caching is enabled, it caches the dictionaries used to render the template page. If page caching is enabled, it caches the dictionaries used to render the template page.
''' '''
if request.user.is_authenticated: if request.user.is_authenticated:
if "reload" in request.GET: if "reload" in request.GET:
@ -76,7 +75,7 @@ def expedition(request, expeditionname):
logged_in = False logged_in = False
ts = TROG['pagecache']['expedition'] ts = TROG['pagecache']['expedition'] # not much use unless single user!
if settings.CACHEDPAGES: if settings.CACHEDPAGES:
nexpos = len( TROG['pagecache']['expedition']) nexpos = len( TROG['pagecache']['expedition'])
#print(f'! - expo {expeditionname} CACHEDPAGES {nexpos} expo pages in cache.') #print(f'! - expo {expeditionname} CACHEDPAGES {nexpos} expo pages in cache.')
@ -107,17 +106,12 @@ def expedition(request, expeditionname):
ts[expeditionname] = {'expedition': this_expedition, 'expeditions':expeditions, ts[expeditionname] = {'expedition': this_expedition, 'expeditions':expeditions,
'personexpeditiondays':personexpeditiondays, 'settings':settings, 'personexpeditiondays':personexpeditiondays, 'settings':settings,
'dateditems': dateditems} 'dateditems': dateditems, 'dates':dates}
TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname] TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname]
nexpos = len( TROG['pagecache']['expedition']) nexpos = len( TROG['pagecache']['expedition'])
#print(f'! - expo {expeditionname} pre-render N expos:{nexpos}') #print(f'! - expo {expeditionname} pre-render N expos:{nexpos}')
return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in } ) return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in } )
# def get_absolute_url(self): # seems to have come seriously adrift. This should be in a class?!
# return ('expedition', (expedition.year))
class Expeditions_tsvListView(ListView): class Expeditions_tsvListView(ListView):
"""This uses the Django built-in shortcut mechanism """This uses the Django built-in shortcut mechanism
It defaults to use a template with name <app-label>/<model-name>_list.html. It defaults to use a template with name <app-label>/<model-name>_list.html.

View File

@ -35,9 +35,9 @@ an "<b>S</b>" for a survey trip. The colours are the same for people on the sam
<table class="expeditionpersonlist"> <table class="expeditionpersonlist">
<tr> <tr>
<th>Caver</th> <th>Caver</th>
{% for expeditionday in expedition.expeditionday_set.all %} {% for d in dates %}
<th> <th>
{{expeditionday.date.day}} {{d.day}}
</th> </th>
{% endfor %} {% endfor %}
</tr> </tr>