2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

[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
This commit is contained in:
substantialnoninfringinguser 2009-05-13 05:40:56 +01:00
parent aeef470c6d
commit eb431eb5c9
3 changed files with 38 additions and 19 deletions

View File

@ -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)

View File

@ -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())

View File

@ -9,12 +9,13 @@
{% endif %}
{% endblock %}
{% block javascript %}
{% block head %}
<style type="text/css">
<!--
td.yes { background: #7f96e8; width: 80pt; font-size: 10pt }
td.no { background: #ff6666; width: 80pt; font-size: 10pt }
td.name { background: #7f96e8; width: 80pt; text-align:right; font-size: 10pt }
.no { background: #7f96e8; width: 80pt; font-size: 10pt }
.yes { background: #ff6666; width: 80pt; font-size: 10pt }
.name { background: #999; width: 80pt; text-align:right; font-size: 10pt }
.date { background: #999; width: 80pt; text-align:right; font-size: 10pt }
-->
</style>
@ -26,20 +27,20 @@ td.name { background: #7f96e8; width: 80pt; text-align:right;
<tr><td />
{% for date in expedition.ListDays %}
{% ifchanged date.month %}
<td class="h">{{ date|date:"F" }}</td>
<td class="date">{{ date|date:"F" }}</td>
{% else %}
<td class="h"></td>
<td class="date"></td>
{% endifchanged %}
{% endfor %}
</tr>
<tr><td />
{% for date in expedition.ListDays %}
<td class="h">{{ date|date:"D" }}</td>
<td class="date">{{ date|date:"D" }}</td>
{% endfor %}
</tr>
<tr><td />
{% for date in expedition.ListDays %}
<td class="h">{{ date|date:"d" }}</td>
<td class="date">{{ date|date:"d" }}</td>
{% endfor %}
</tr>
@ -51,7 +52,7 @@ td.name { background: #7f96e8; width: 80pt; text-align:right;
{% for dateTF in personexpedition.ListDaysTF %}
<td {{ dateTF|yesno:"class='yes',class='no'"|safe }}></td>
{% empty %}
<td colspan="{{ expedition.ListDays|length }}">No data yet.</td>
<td colspan="{{ expedition.ListDays|length }}"><center>No data.</center></td>
{% endfor %}