From eb431eb5c949bb30c51cd53dbbd802816e7f15ec Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:40:56 +0100 Subject: [PATCH] [svn] Fixed up calendar with estimated dates from logbook. Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8202 by aaron @ 1/19/2009 8:28 AM --- expo/admin.py | 4 ++-- expo/models.py | 34 ++++++++++++++++++++++++++-------- templates/calendar.html | 19 ++++++++++--------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/expo/admin.py b/expo/admin.py index 7c170d9..52138af 100644 --- a/expo/admin.py +++ b/expo/admin.py @@ -16,13 +16,13 @@ class SurveyAdmin(admin.ModelAdmin): inlines = (ScannedImageInline,) class LogbookEntryAdmin(admin.ModelAdmin): - search_fields = ('title',) + search_fields = ('title','expedition__year') class PersonAdmin(admin.ModelAdmin): search_fields = ('first_name','last_name') class PersonExpeditionAdmin(admin.ModelAdmin): - search_fields = ('person__first_name',) + search_fields = ('person__first_name','expedition__year') admin.site.register(Photo) admin.site.register(Cave) diff --git a/expo/models.py b/expo/models.py index 2e8dc88..ee3179b 100644 --- a/expo/models.py +++ b/expo/models.py @@ -19,11 +19,29 @@ class Expedition(models.Model): def __unicode__(self): return self.year + def GuessDateFrom(self): + try: + return self.logbookentry_set.order_by('date')[0].date + except IndexError: + pass + + def GuessDateTo(self): # returns the date of the last logbook entry in the expedition + try: + return self.logbookentry_set.order_by('date')[-1].date + except IndexError: + pass + def ListDays(self): - if self.start_date and self.end_date: + if self.date_from and self.date_to: res=[] - date=self.start_date - while date <= self.end_date: + date=self.date_from + while date <= self.date_to: + res.append(date) + date+=datetime.timedelta(days=1) + return res + elif self.GuessDateFrom() and self.GuessDateTo(): # if we don't have the real dates, try it with the dates taken from the earliest and latest logbook entries + date=self.GuessDateFrom() + while date <= self.GuessDateTo(): res.append(date) date+=datetime.timedelta(days=1) return res @@ -78,18 +96,18 @@ class PersonExpedition(models.Model): if self.nickname: res.append(self.nickname) return res - + def ListDays(self): - if self.from_date and self.to_date: + if self.date_from and self.date_to: res=[] - date=self.from_date - while date <= self.to_date: + date=self.date_from + while date <= self.date_to: res.append(date) date+=datetime.timedelta(days=1) return res def ListDaysTF(self): - if self.from_date and self.to_date: + if self.date_from and self.date_to: res=[] for date in self.expedition.ListDays(): res.append(date in self.ListDays()) diff --git a/templates/calendar.html b/templates/calendar.html index a39556c..70d3ecf 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -9,12 +9,13 @@ {% endif %} {% endblock %} -{% block javascript %} +{% block head %} @@ -26,20 +27,20 @@ td.name { background: #7f96e8; width: 80pt; text-align:right; {% for date in expedition.ListDays %} {% ifchanged date.month %} - {{ date|date:"F" }} + {{ date|date:"F" }} {% else %} - + {% endifchanged %} {% endfor %} {% for date in expedition.ListDays %} - {{ date|date:"D" }} + {{ date|date:"D" }} {% endfor %} {% for date in expedition.ListDays %} - {{ date|date:"d" }} + {{ date|date:"d" }} {% endfor %} @@ -51,7 +52,7 @@ td.name { background: #7f96e8; width: 80pt; text-align:right; {% for dateTF in personexpedition.ListDaysTF %} {% empty %} - No data yet. +
No data.
{% endfor %}