2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-26 09:11:54 +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,) inlines = (ScannedImageInline,)
class LogbookEntryAdmin(admin.ModelAdmin): class LogbookEntryAdmin(admin.ModelAdmin):
search_fields = ('title',) search_fields = ('title','expedition__year')
class PersonAdmin(admin.ModelAdmin): class PersonAdmin(admin.ModelAdmin):
search_fields = ('first_name','last_name') search_fields = ('first_name','last_name')
class PersonExpeditionAdmin(admin.ModelAdmin): class PersonExpeditionAdmin(admin.ModelAdmin):
search_fields = ('person__first_name',) search_fields = ('person__first_name','expedition__year')
admin.site.register(Photo) admin.site.register(Photo)
admin.site.register(Cave) admin.site.register(Cave)

View File

@ -19,11 +19,29 @@ class Expedition(models.Model):
def __unicode__(self): def __unicode__(self):
return self.year 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): def ListDays(self):
if self.start_date and self.end_date: if self.date_from and self.date_to:
res=[] res=[]
date=self.start_date date=self.date_from
while date <= self.end_date: 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) res.append(date)
date+=datetime.timedelta(days=1) date+=datetime.timedelta(days=1)
return res return res
@ -80,16 +98,16 @@ class PersonExpedition(models.Model):
return res return res
def ListDays(self): def ListDays(self):
if self.from_date and self.to_date: if self.date_from and self.date_to:
res=[] res=[]
date=self.from_date date=self.date_from
while date <= self.to_date: while date <= self.date_to:
res.append(date) res.append(date)
date+=datetime.timedelta(days=1) date+=datetime.timedelta(days=1)
return res return res
def ListDaysTF(self): def ListDaysTF(self):
if self.from_date and self.to_date: if self.date_from and self.date_to:
res=[] res=[]
for date in self.expedition.ListDays(): for date in self.expedition.ListDays():
res.append(date in self.ListDays()) res.append(date in self.ListDays())

View File

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