From 6f62771552a7f55ebefc626b718838a8db7608d1 Mon Sep 17 00:00:00 2001 From: aaron Date: Mon, 16 Mar 2009 19:09:26 +0100 Subject: [PATCH] [svn r8307] Up to late programming last night and forgot that not all logbookentries will have caves attached. The function I wrote for making the "add a qm link" was breaking stuff. Fixed now. --- troggle/expo/views_logbooks.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/troggle/expo/views_logbooks.py b/troggle/expo/views_logbooks.py index cfc5d2f00..13468dc25 100644 --- a/troggle/expo/views_logbooks.py +++ b/troggle/expo/views_logbooks.py @@ -69,20 +69,28 @@ def personexpedition(request, first_name='', last_name='', year=''): personexpedition = person.personexpedition_set.get(expedition=expedition) return render_response(request,'personexpedition.html', {'personexpedition': personexpedition, }) -def logbookentry(request, logbookentry_pk): - logbookentry = LogbookEntry.objects.get(pk = logbookentry_pk) - logsforcave=logbookentry.cave.logbookentry_set.all() +def newQMlink(logbookentry): biggestQMnumber=0 - for log in logsforcave: - try: + if logbookentry.cave: + for log in logbookentry.cave.logbookentry_set.all(): + try: biggestQMnumberInLog = logbookentry.QMs_found.order_by('-number')[0].number except IndexError: biggestQMnumberInLog = 0 if biggestQMnumberInLog > biggestQMnumber: biggestQMnumber = biggestQMnumberInLog + else: + return None + + + nextQMnumber=biggestQMnumber+1 - newQMlink=settings.URL_ROOT + r'/admin/expo/qm/add/?' + r'found_by=' + str(logbookentry.pk) +'&number=' + str(nextQMnumber) - return render_response(request, 'logbookentry.html', {'logbookentry': logbookentry, 'newQMlink':newQMlink}) + return settings.URL_ROOT + r'/admin/expo/qm/add/?' + r'found_by=' + str(logbookentry.pk) +'&number=' + str(nextQMnumber) + +def logbookentry(request, logbookentry_pk): + logbookentry = LogbookEntry.objects.get(pk = logbookentry_pk) + + return render_response(request, 'logbookentry.html', {'logbookentry': logbookentry, 'newQMlink':newQMlink(logbookentry)}) def logbookSearch(request, extra): query_string = ''