2009-07-02 20:43:18 +01:00
|
|
|
from troggle.core.models import Cave, CaveAndEntrance, Survey, Expedition, QM
|
|
|
|
import troggle.core.models as models
|
2009-05-13 05:13:38 +01:00
|
|
|
import troggle.settings as settings
|
2009-05-13 06:08:04 +01:00
|
|
|
from django.forms.models import formset_factory
|
2009-05-13 05:22:14 +01:00
|
|
|
import search
|
2009-05-13 06:08:04 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
2009-05-13 05:52:15 +01:00
|
|
|
from troggle.alwaysUseRequestContext import render_response # see views_logbooks for explanation on this.
|
2009-05-13 06:08:04 +01:00
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.conf import settings
|
2009-06-10 05:37:53 +01:00
|
|
|
import re, urlparse
|
2009-05-13 05:13:38 +01:00
|
|
|
|
2009-05-13 05:59:40 +01:00
|
|
|
def getCave(cave_id):
|
|
|
|
"""Returns a cave object when given a cave name or number. It is used by views including cavehref, ent, and qm."""
|
|
|
|
try:
|
|
|
|
cave = Cave.objects.get(kataster_number=cave_id)
|
|
|
|
except Cave.DoesNotExist:
|
|
|
|
cave = Cave.objects.get(unofficial_number=cave_id)
|
|
|
|
return cave
|
|
|
|
|
2009-05-13 05:13:38 +01:00
|
|
|
def caveindex(request):
|
|
|
|
caves = Cave.objects.all()
|
2009-05-13 05:48:47 +01:00
|
|
|
notablecavehrefs = [ "161", "204", "258", "76" ] # could detect notability by trips and notability of people who have been down them
|
2009-05-13 05:55:00 +01:00
|
|
|
notablecaves = [Cave.objects.get(kataster_number=kataster_number) for kataster_number in notablecavehrefs ]
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'caveindex.html', {'caves': caves, 'notablecaves':notablecaves})
|
2009-05-13 05:13:38 +01:00
|
|
|
|
2009-05-13 06:13:31 +01:00
|
|
|
def cave(request, cave_id='', offical_name=''):
|
2009-06-10 06:34:50 +01:00
|
|
|
cave=getCave(cave_id)
|
2009-06-12 05:39:30 +01:00
|
|
|
if cave.non_public and not request.user.is_authenticated():
|
2009-06-10 06:34:50 +01:00
|
|
|
return render_response(request,'nonpublic.html', {'instance': cave})
|
|
|
|
else:
|
|
|
|
return render_response(request,'cave.html', {'cave': cave})
|
2009-05-13 06:08:04 +01:00
|
|
|
|
|
|
|
def qm(request,cave_id,qm_id,year,grade=None):
|
2009-05-13 05:59:40 +01:00
|
|
|
year=int(year)
|
2009-05-13 06:08:04 +01:00
|
|
|
try:
|
|
|
|
qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year)
|
2009-06-10 05:37:53 +01:00
|
|
|
return render_response(request,'qm.html',locals())
|
2009-05-13 06:08:04 +01:00
|
|
|
|
|
|
|
except QM.DoesNotExist:
|
2009-06-10 05:37:53 +01:00
|
|
|
url=urlparse.urljoin(settings.URL_ROOT, r'/admin/expo/qm/add/'+'?'+ r'number=' + qm_id)
|
|
|
|
if grade:
|
|
|
|
url += r'&grade=' + grade
|
|
|
|
return HttpResponseRedirect(url)
|
2009-05-13 06:08:04 +01:00
|
|
|
|
2009-05-13 05:46:12 +01:00
|
|
|
|
2009-05-13 05:13:38 +01:00
|
|
|
def ent(request, cave_id, ent_letter):
|
|
|
|
cave = Cave.objects.filter(kataster_number = cave_id)[0]
|
|
|
|
cave_and_ent = CaveAndEntrance.objects.filter(cave = cave).filter(entrance_letter = ent_letter)[0]
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'entrance.html', {'cave': cave,
|
2009-05-13 05:13:38 +01:00
|
|
|
'entrance': cave_and_ent.entrance,
|
2009-05-13 05:52:15 +01:00
|
|
|
'letter': cave_and_ent.entrance_letter,})
|
|
|
|
|
2009-05-13 05:39:52 +01:00
|
|
|
def survexblock(request, survexpath):
|
|
|
|
survexblock = models.SurvexBlock.objects.get(survexpath=survexpath)
|
|
|
|
#ftext = survexblock.filecontents()
|
|
|
|
ftext = survexblock.text
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'survexblock.html', {'survexblock':survexblock, 'ftext':ftext, })
|
2009-05-13 05:22:14 +01:00
|
|
|
|
2009-05-13 06:15:48 +01:00
|
|
|
def subcave(request, cave_id, subcave):
|
|
|
|
print subcave
|
2009-05-13 06:28:36 +01:00
|
|
|
subcaveSeq=re.findall('(?:/)([^/]*)',subcave)
|
2009-05-13 06:15:48 +01:00
|
|
|
print subcaveSeq
|
2009-05-13 06:28:36 +01:00
|
|
|
cave=models.Cave.objects.get(kataster_number = cave_id)
|
2009-05-22 01:50:16 +01:00
|
|
|
subcave=models.Subcave.objects.get(title=subcaveSeq[0], cave=cave)
|
2009-05-13 06:15:48 +01:00
|
|
|
if len(subcaveSeq)>1:
|
2009-05-13 06:28:36 +01:00
|
|
|
for subcaveUrlSegment in subcaveSeq[1:]:
|
|
|
|
if subcaveUrlSegment:
|
2009-05-22 01:50:16 +01:00
|
|
|
subcave=subcave.children.get(title=subcaveUrlSegment)
|
2009-05-13 06:15:48 +01:00
|
|
|
print subcave
|
2009-05-13 06:28:36 +01:00
|
|
|
return render_response(request,'subcave.html', {'subcave': subcave,'cave':cave})
|
2009-05-13 05:45:26 +01:00
|
|
|
|
2009-05-13 05:22:14 +01:00
|
|
|
def caveSearch(request):
|
|
|
|
query_string = ''
|
|
|
|
found_entries = None
|
|
|
|
if ('q' in request.GET) and request.GET['q'].strip():
|
|
|
|
query_string = request.GET['q']
|
2009-05-13 05:52:15 +01:00
|
|
|
entry_query = search.get_query(query_string, ['underground_description','official_name',])
|
|
|
|
found_entries = Cave.objects.filter(entry_query)
|
2009-05-13 05:22:14 +01:00
|
|
|
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'cavesearch.html',
|
|
|
|
{ 'query_string': query_string, 'found_entries': found_entries,})
|
2009-05-13 05:22:14 +01:00
|
|
|
|
2009-05-13 05:27:43 +01:00
|
|
|
def surveyindex(request):
|
|
|
|
surveys=Survey.objects.all()
|
2009-05-13 06:22:07 +01:00
|
|
|
expeditions=Expedition.objects.order_by("-year")
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'survey.html',locals())
|
2009-05-13 05:27:43 +01:00
|
|
|
|
2009-05-13 05:31:21 +01:00
|
|
|
def survey(request,year,wallet_number):
|
2009-05-13 05:27:43 +01:00
|
|
|
surveys=Survey.objects.all()
|
2009-05-13 06:22:07 +01:00
|
|
|
expeditions=Expedition.objects.order_by("-year")
|
2009-05-13 05:31:21 +01:00
|
|
|
current_expedition=Expedition.objects.filter(year=year)[0]
|
|
|
|
|
|
|
|
if wallet_number!='':
|
2009-06-10 05:37:53 +01:00
|
|
|
current_survey=Survey.objects.filter(expedition=current_expedition,wallet_number=wallet_number)[0]
|
|
|
|
notes=current_survey.scannedimage_set.filter(contents='notes')
|
|
|
|
planSketches=current_survey.scannedimage_set.filter(contents='plan')
|
|
|
|
elevationSketches=current_survey.scannedimage_set.filter(contents='elevation')
|
2009-05-13 05:27:43 +01:00
|
|
|
|
2009-05-13 05:52:15 +01:00
|
|
|
return render_response(request,'survey.html', locals())
|