diff options
author | Sam Wenham <sam@wenhams.co.uk> | 2019-02-24 13:03:34 +0000 |
---|---|---|
committer | Sam Wenham <sam@wenhams.co.uk> | 2019-02-24 13:03:34 +0000 |
commit | 4ad5b684333bfb995160cd6bf00308d9f3839d4a (patch) | |
tree | f5683df0d04d8decad0685198e6e76980e376ef0 /core/views_logbooks.py | |
parent | 552730f0a38f474a181f2e1550589a4823667f3c (diff) | |
download | troggle-4ad5b684333bfb995160cd6bf00308d9f3839d4a.tar.gz troggle-4ad5b684333bfb995160cd6bf00308d9f3839d4a.tar.bz2 troggle-4ad5b684333bfb995160cd6bf00308d9f3839d4a.zip |
Make things more compatiable with newer python
Fix the expeditions list
Improvements to make it compatiable with django 1.8
Bump the years to add 2018
Update the .hgignore file to ignore junk
Diffstat (limited to 'core/views_logbooks.py')
-rw-r--r-- | core/views_logbooks.py | 56 |
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: |