summaryrefslogtreecommitdiffstats
path: root/core/views_logbooks.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/views_logbooks.py')
-rw-r--r--core/views_logbooks.py56
1 files changed, 37 insertions, 19 deletions
diff --git a/core/views_logbooks.py b/core/views_logbooks.py
index 0aee9c6..c6f9086 100644
--- a/core/views_logbooks.py
+++ b/core/views_logbooks.py
@@ -16,9 +16,18 @@ from django.template.defaultfilters import slugify
from troggle.helper import login_required_if_public
import datetime
+from django.views.generic.list import ListView
+from django.utils import timezone
-# Django uses Context, not RequestContext when you call render_to_response. We always want to use RequestContext, so that django adds the context from settings.TEMPLATE_CONTEXT_PROCESSORS. This way we automatically get necessary settings variables passed to each template. So we use a custom method, render_response instead of render_to_response. Hopefully future Django releases will make this unnecessary.
-#from troggle.alwaysUseRequestContext import render_response
+
+# Django uses Context, not RequestContext when you call render
+# to_response. We always want to use RequestContext, so that
+# django adds the context from settings.TEMPLATE_CONTEXT_PROCESSORS.
+# This way we automatically get necessary settings variables passed
+# to each template. So we use a custom method, render_response
+# instead of render_to_response. Hopefully future Django releases
+# will make this unnecessary.
+# from troggle.alwaysUseRequestContext import render_response
import re
@@ -50,13 +59,13 @@ def personindex(request):
def expedition(request, expeditionname):
- expedition = Expedition.objects.get(year=int(expeditionname))
+ this_expedition = Expedition.objects.get(year=int(expeditionname))
expeditions = Expedition.objects.all()
personexpeditiondays = [ ]
- dateditems = list(expedition.logbookentry_set.all()) + list(expedition.survexblock_set.all())
+ dateditems = list(this_expedition.logbookentry_set.all()) + list(this_expedition.survexblock_set.all())
dates = list(set([item.date for item in dateditems]))
dates.sort()
- for personexpedition in expedition.personexpedition_set.all():
+ for personexpedition in this_expedition.personexpedition_set.all():
prow = [ ]
for date in dates:
pcell = { "persontrips": PersonTrip.objects.filter(personexpedition=personexpedition,
@@ -71,21 +80,30 @@ def expedition(request, expeditionname):
message = LoadLogbookForExpedition(expedition)
return render_with_context(request,'expedition.html', {'expedition': expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'message':message, 'settings':settings, 'dateditems': dateditems })
- def get_absolute_url(self):
+class ExpeditionListView(ListView):
+
+ model = Expedition
+
+ def get_context_data(self, **kwargs):
+ context = super(ExpeditionListView, self).get_context_data(**kwargs)
+ context['now'] = timezone.now()
+ return context
+
+def get_absolute_url(self):
return ('expedition', (expedition.year))
def person(request, first_name='', last_name='', ):
- person = Person.objects.get(first_name = first_name, last_name = last_name)
+ this_person = Person.objects.get(first_name = first_name, last_name = last_name)
- #This is for removing the reference to the user's profile, in case they set it to the wrong person
+ # This is for removing the reference to the user's profile, in case they set it to the wrong person
if request.method == 'GET':
if request.GET.get('clear_profile')=='True':
- person.user=None
- person.save()
+ this_person.user=None
+ this_person.save()
return HttpResponseRedirect(reverse('profiles_select_profile'))
- return render_with_context(request,'person.html', {'person': person, })
+ return render_with_context(request,'person.html', {'person': this_person, })
def GetPersonChronology(personexpedition):
@@ -115,20 +133,20 @@ def GetPersonChronology(personexpedition):
def personexpedition(request, first_name='', last_name='', year=''):
person = Person.objects.get(first_name = first_name, last_name = last_name)
- expedition = Expedition.objects.get(year=year)
- personexpedition = person.personexpedition_set.get(expedition=expedition)
+ this_expedition = Expedition.objects.get(year=year)
+ personexpedition = person.personexpedition_set.get(expedition=this_expedition)
personchronology = GetPersonChronology(personexpedition)
return render_with_context(request,'personexpedition.html', {'personexpedition': personexpedition, 'personchronology':personchronology})
def logbookentry(request, date, slug):
- logbookentry = LogbookEntry.objects.filter(date=date, slug=slug)
+ this_logbookentry = LogbookEntry.objects.filter(date=date, slug=slug)
- if len(logbookentry)>1:
- return render_with_context(request, 'object_list.html',{'object_list':logbookentry})
+ if len(this_logbookentry)>1:
+ return render_with_context(request, 'object_list.html',{'object_list':this_logbookentry})
else:
- logbookentry=logbookentry[0]
- return render_with_context(request, 'logbookentry.html', {'logbookentry': logbookentry})
+ this_logbookentry=this_logbookentry[0]
+ return render_with_context(request, 'logbookentry.html', {'logbookentry': this_logbookentry})
def logbookSearch(request, extra):
@@ -196,7 +214,7 @@ def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
'expeditionyear': expeditionyear})
f.write(template.render(context))
f.close()
- print logbookparsers.parseAutoLogBookEntry(filename)
+ print(logbookparsers.parseAutoLogBookEntry(filename))
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
else:
if pslug and pdate: