mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-21 23:01:52 +00:00
Fixing dates on expedition table
This commit is contained in:
parent
89d0e1723e
commit
7d98980121
@ -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:
|
||||
|
@ -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"]
|
||||
|
@ -58,7 +58,6 @@ def notablepersons(request):
|
||||
def expedition(request, expeditionname):
|
||||
'''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 request.user.is_authenticated:
|
||||
if "reload" in request.GET:
|
||||
@ -76,7 +75,7 @@ def expedition(request, expeditionname):
|
||||
logged_in = False
|
||||
|
||||
|
||||
ts = TROG['pagecache']['expedition']
|
||||
ts = TROG['pagecache']['expedition'] # not much use unless single user!
|
||||
if settings.CACHEDPAGES:
|
||||
nexpos = len( TROG['pagecache']['expedition'])
|
||||
#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,
|
||||
'personexpeditiondays':personexpeditiondays, 'settings':settings,
|
||||
'dateditems': dateditems}
|
||||
'dateditems': dateditems, 'dates':dates}
|
||||
TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname]
|
||||
nexpos = len( TROG['pagecache']['expedition'])
|
||||
#print(f'! - expo {expeditionname} pre-render N expos:{nexpos}')
|
||||
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):
|
||||
"""This uses the Django built-in shortcut mechanism
|
||||
It defaults to use a template with name <app-label>/<model-name>_list.html.
|
||||
|
@ -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">
|
||||
<tr>
|
||||
<th>Caver</th>
|
||||
{% for expeditionday in expedition.expeditionday_set.all %}
|
||||
{% for d in dates %}
|
||||
<th>
|
||||
{{expeditionday.date.day}}
|
||||
{{d.day}}
|
||||
</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user