diff --git a/core/models/logbooks.py b/core/models/logbooks.py index 9903db5..521eb49 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -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: diff --git a/core/models/troggle.py b/core/models/troggle.py index 5ef95c8..4651955 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -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"] diff --git a/core/views/logbooks.py b/core/views/logbooks.py index a0a2efe..2cfc183 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -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 /_list.html. diff --git a/templates/expedition.html b/templates/expedition.html index dd4e7ab..0188107 100644 --- a/templates/expedition.html +++ b/templates/expedition.html @@ -35,9 +35,9 @@ an "S" for a survey trip. The colours are the same for people on the sam -{% for expeditionday in expedition.expeditionday_set.all %} +{% for d in dates %} {% endfor %}
Caver - {{expeditionday.date.day}} + {{d.day}}