mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-23 07:41:52 +00:00
Debugging, and make get_name function accessable (should really be renamed)
This commit is contained in:
parent
3f4ba904e2
commit
4a3ccc728b
@ -70,11 +70,6 @@ def getTripForm(expedition):
|
|||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
class PersonTripForm(forms.Form):
|
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 = [get_name(pe) for pe in PersonExpedition.objects.filter(expedition = expedition)]
|
||||||
names.sort()
|
names.sort()
|
||||||
names = ["-----"] + names
|
names = ["-----"] + names
|
||||||
@ -86,3 +81,8 @@ def getTripForm(expedition):
|
|||||||
|
|
||||||
return PersonTripFormSet, TripForm
|
return PersonTripFormSet, TripForm
|
||||||
|
|
||||||
|
def get_name(pe):
|
||||||
|
if pe.nickname:
|
||||||
|
return pe.nickname
|
||||||
|
else:
|
||||||
|
return pe.person.first_name
|
||||||
|
@ -5,7 +5,7 @@ import troggle.settings as settings
|
|||||||
import django.db.models
|
import django.db.models
|
||||||
from troggle.parsers.logbooks import LoadLogbookForExpedition
|
from troggle.parsers.logbooks import LoadLogbookForExpedition
|
||||||
from troggle.parsers.people import GetPersonExpeditionNameLookup
|
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.core.urlresolvers import reverse
|
||||||
from django.http import HttpResponseRedirect, HttpResponse
|
from django.http import HttpResponseRedirect, HttpResponse
|
||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
@ -13,6 +13,8 @@ from utils import render_with_context
|
|||||||
import os.path
|
import os.path
|
||||||
import troggle.parsers.logbooks as logbookparsers
|
import troggle.parsers.logbooks as logbookparsers
|
||||||
from django.template.defaultfilters import slugify
|
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.
|
# 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])
|
totalsurvexlength = sum([survexleg.tape for survexleg in survexlegs])
|
||||||
return render_with_context(request, 'experimental.html', { "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength, "legsbyexpo":legsbyexpo })
|
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):
|
def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
|
||||||
expedition = Expedition.objects.get(year=expeditionyear)
|
expedition = Expedition.objects.get(year=expeditionyear)
|
||||||
PersonTripFormSet, TripForm = getTripForm(expedition)
|
PersonTripFormSet, TripForm = getTripForm(expedition)
|
||||||
if pslug and pdate:
|
if pslug and pdate:
|
||||||
previousdate = datetime.date(*[int(x) for x in pdate.split("-")])
|
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
|
assert previouslbe.filename
|
||||||
if request.method == 'POST': # If the form has been submitted...
|
if request.method == 'POST': # If the form has been submitted...
|
||||||
tripForm = TripForm(request.POST) # A form bound to the POST data
|
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)
|
print logbookparsers.parseAutoLogBookEntry(filename)
|
||||||
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
|
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
|
||||||
else:
|
else:
|
||||||
if pslug and date:
|
if pslug and pdate:
|
||||||
if lbe.cave:
|
if previouslbe.cave:
|
||||||
tripForm = TripForm(date = previousdate,
|
tripForm = TripForm(initial={"date": previousdate,
|
||||||
title = previouslbe.title,
|
"title": previouslbe.title,
|
||||||
cave = previouslbe.cave.reference(),
|
"cave": previouslbe.cave.reference(),
|
||||||
location = None,
|
"location": None,
|
||||||
caveOrLocation = "cave",
|
"caveOrLocation": "cave",
|
||||||
html = previouslbe.text)
|
"html": previouslbe.text})
|
||||||
else:
|
else:
|
||||||
tripForm = TripForm(date = previousdate,
|
tripForm = TripForm(initial={"date": previousdate,
|
||||||
title = previouslbe.title,
|
"title": previouslbe.title,
|
||||||
cave = None,
|
"cave": None,
|
||||||
location = previouslbe.location,
|
"location": previouslbe.place,
|
||||||
caveOrLocation = "location",
|
"caveOrLocation": "location",
|
||||||
html = previouslbe.text)
|
"html": previouslbe.text})
|
||||||
personTripFormSet = PersonTripFormSet(initial=[{"name": py.personexpedition.name(),
|
personTripFormSet = PersonTripFormSet(initial=[{"name": get_name(py.personexpedition),
|
||||||
"TU": py.time_underground,
|
"TU": py.time_underground,
|
||||||
"author": py.is_logbook_entry_author}
|
"author": py.is_logbook_entry_author}
|
||||||
for py in previouslbe.persontrip_set.all()])
|
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):
|
def deleteLogbookEntry(request, expeditionyear, date = None, slug = None):
|
||||||
expedition = Expedition.objects.get(year=expeditionyear)
|
expedition = Expedition.objects.get(year=expeditionyear)
|
||||||
previousdate = datetime.date(*[int(x) for x in pdate.split("-")])
|
previousdate = datetime.date(*[int(x) for x in date.split("-")])
|
||||||
previouslbe = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition__year = year)
|
previouslbe = LogbookEntry.objects.get(slug = slug, date = previousdate, expedition = expedition)
|
||||||
delLogbookEntry(previouslbe)
|
delLogbookEntry(previouslbe)
|
||||||
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
|
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
|
||||||
|
|
||||||
@ -236,5 +240,5 @@ def delLogbookEntry(lbe):
|
|||||||
for pt in lbe.persontrip_set.all():
|
for pt in lbe.persontrip_set.all():
|
||||||
pt.delete()
|
pt.delete()
|
||||||
lbe.delete()
|
lbe.delete()
|
||||||
os.delete(lbe.filename)
|
os.remove(lbe.filename)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user