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

Debugging, and make get_name function accessable (should really be renamed)

This commit is contained in:
Martin Green 2011-05-02 02:15:54 +01:00
parent 3f4ba904e2
commit 4a3ccc728b
2 changed files with 29 additions and 25 deletions

View File

@ -70,11 +70,6 @@ def getTripForm(expedition):
return self.cleaned_data
class PersonTripForm(forms.Form):
def get_name(pe):
if pe.nickname:
return pe.nickname
else:
return pe.person.first_name
names = [get_name(pe) for pe in PersonExpedition.objects.filter(expedition = expedition)]
names.sort()
names = ["-----"] + names
@ -86,3 +81,8 @@ def getTripForm(expedition):
return PersonTripFormSet, TripForm
def get_name(pe):
if pe.nickname:
return pe.nickname
else:
return pe.person.first_name

View File

@ -5,7 +5,7 @@ import troggle.settings as settings
import django.db.models
from troggle.parsers.logbooks import LoadLogbookForExpedition
from troggle.parsers.people import GetPersonExpeditionNameLookup
from troggle.core.forms import PersonForm, getTripForm
from troggle.core.forms import PersonForm, getTripForm, get_name
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.template import Context, loader
@ -13,6 +13,8 @@ from utils import render_with_context
import os.path
import troggle.parsers.logbooks as logbookparsers
from django.template.defaultfilters import slugify
from troggle.helper import login_required_if_public
import datetime
# 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.
@ -163,12 +165,13 @@ def experimental(request):
totalsurvexlength = sum([survexleg.tape for survexleg in survexlegs])
return render_with_context(request, 'experimental.html', { "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength, "legsbyexpo":legsbyexpo })
@login_required_if_public
def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
expedition = Expedition.objects.get(year=expeditionyear)
PersonTripFormSet, TripForm = getTripForm(expedition)
if pslug and pdate:
previousdate = datetime.date(*[int(x) for x in pdate.split("-")])
previouslbe = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition__year = year)
previouslbe = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition = expedition)
assert previouslbe.filename
if request.method == 'POST': # If the form has been submitted...
tripForm = TripForm(request.POST) # A form bound to the POST data
@ -196,22 +199,22 @@ def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
print logbookparsers.parseAutoLogBookEntry(filename)
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
else:
if pslug and date:
if lbe.cave:
tripForm = TripForm(date = previousdate,
title = previouslbe.title,
cave = previouslbe.cave.reference(),
location = None,
caveOrLocation = "cave",
html = previouslbe.text)
if pslug and pdate:
if previouslbe.cave:
tripForm = TripForm(initial={"date": previousdate,
"title": previouslbe.title,
"cave": previouslbe.cave.reference(),
"location": None,
"caveOrLocation": "cave",
"html": previouslbe.text})
else:
tripForm = TripForm(date = previousdate,
title = previouslbe.title,
cave = None,
location = previouslbe.location,
caveOrLocation = "location",
html = previouslbe.text)
personTripFormSet = PersonTripFormSet(initial=[{"name": py.personexpedition.name(),
tripForm = TripForm(initial={"date": previousdate,
"title": previouslbe.title,
"cave": None,
"location": previouslbe.place,
"caveOrLocation": "location",
"html": previouslbe.text})
personTripFormSet = PersonTripFormSet(initial=[{"name": get_name(py.personexpedition),
"TU": py.time_underground,
"author": py.is_logbook_entry_author}
for py in previouslbe.persontrip_set.all()])
@ -225,10 +228,11 @@ def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
})
@login_required_if_public
def deleteLogbookEntry(request, expeditionyear, date = None, slug = None):
expedition = Expedition.objects.get(year=expeditionyear)
previousdate = datetime.date(*[int(x) for x in pdate.split("-")])
previouslbe = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition__year = year)
previousdate = datetime.date(*[int(x) for x in date.split("-")])
previouslbe = LogbookEntry.objects.get(slug = slug, date = previousdate, expedition = expedition)
delLogbookEntry(previouslbe)
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
@ -236,5 +240,5 @@ def delLogbookEntry(lbe):
for pt in lbe.persontrip_set.all():
pt.delete()
lbe.delete()
os.delete(lbe.filename)
os.remove(lbe.filename)