2012-08-10 18:02:13 +01:00
|
|
|
from troggle.core.models import Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, Entrance, Area
|
2012-06-10 14:59:21 +01:00
|
|
|
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm
|
2011-07-11 02:10:22 +01:00
|
|
|
import troggle.core.models as models
|
|
|
|
import troggle.settings as settings
|
|
|
|
from troggle.helper import login_required_if_public
|
|
|
|
|
2012-06-10 14:59:21 +01:00
|
|
|
from django.forms.models import modelformset_factory
|
2012-01-07 19:05:25 +00:00
|
|
|
from django import forms
|
2011-07-11 02:10:22 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from utils import render_with_context # see views_logbooks for explanation on this.
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.conf import settings
|
|
|
|
import re, urlparse
|
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-08-05 18:26:24 +01:00
|
|
|
def pad5(x):
|
|
|
|
return "0" * (5 -len(x.group(0))) + x.group(0)
|
|
|
|
def padnumber(x):
|
|
|
|
return re.sub("\d+", pad5, x)
|
|
|
|
def numericalcmp(x, y):
|
|
|
|
return cmp(padnumber(x), padnumber(y))
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-05 18:28:34 +01:00
|
|
|
def caveCmp(x, y):
|
2012-06-10 14:59:21 +01:00
|
|
|
if x.kataster_number:
|
|
|
|
if y.kataster_number:
|
2012-08-05 18:28:34 +01:00
|
|
|
return numericalcmp(x.kataster_number, y.kataster_number) # Note that cave kataster numbers are not generally integers.
|
2012-06-10 14:59:21 +01:00
|
|
|
else:
|
|
|
|
return -1
|
|
|
|
else:
|
2012-08-05 18:26:24 +01:00
|
|
|
if y.kataster_number:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return numericalcmp(x.unofficial_number, y.unofficial_number)
|
2012-06-10 14:59:21 +01:00
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def caveindex(request):
|
|
|
|
caves = Cave.objects.all()
|
|
|
|
notablecavehrefs = [ "161", "204", "258", "76" ] # could detect notability by trips and notability of people who have been down them
|
|
|
|
notablecaves = [Cave.objects.get(kataster_number=kataster_number) for kataster_number in notablecavehrefs ]
|
2012-06-10 14:59:21 +01:00
|
|
|
caves1623 = list(Cave.objects.filter(area__short_name = "1623"))
|
|
|
|
caves1626 = list(Cave.objects.filter(area__short_name = "1626"))
|
|
|
|
caves1623.sort(caveCmp)
|
|
|
|
caves1626.sort(caveCmp)
|
2011-07-11 02:10:22 +01:00
|
|
|
return render_with_context(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':notablecaves, 'cavepage': True})
|
|
|
|
|
|
|
|
def cave(request, cave_id='', offical_name=''):
|
|
|
|
cave=getCave(cave_id)
|
2011-08-08 08:51:12 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
2011-07-11 02:10:22 +01:00
|
|
|
return render_with_context(request,'nonpublic.html', {'instance': cave, 'cavepage': True})
|
|
|
|
else:
|
|
|
|
return render_with_context(request,'cave.html', {'cave': cave, 'cavepage': True})
|
|
|
|
|
|
|
|
def caveEntrance(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2011-08-08 08:51:12 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
2011-07-11 02:10:22 +01:00
|
|
|
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
|
|
|
else:
|
|
|
|
return render_with_context(request,'cave_entrances.html', {'cave': cave})
|
2012-05-23 09:23:40 +01:00
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
def caveDescription(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2011-08-08 08:51:12 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
2011-07-11 02:10:22 +01:00
|
|
|
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
|
|
|
else:
|
|
|
|
return render_with_context(request,'cave_uground_description.html', {'cave': cave})
|
|
|
|
def caveQMs(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2011-08-08 08:51:12 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
2011-07-11 02:10:22 +01:00
|
|
|
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
|
|
|
else:
|
|
|
|
return render_with_context(request,'cave_qms.html', {'cave': cave})
|
|
|
|
def caveLogbook(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2011-08-08 08:51:12 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
2011-07-11 02:10:22 +01:00
|
|
|
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
|
|
|
else:
|
|
|
|
return render_with_context(request,'cave_logbook.html', {'cave': cave})
|
|
|
|
|
|
|
|
def caveSlug(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2011-08-08 08:51:12 +01:00
|
|
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
2012-01-07 19:05:25 +00:00
|
|
|
return render_with_context(request,'nonpublic.html', {'instance': cave, 'cave_editable': slug})
|
2011-07-11 02:10:22 +01:00
|
|
|
else:
|
2012-01-07 19:05:25 +00:00
|
|
|
return render_with_context(request,'cave.html', {'cave': cave, 'cave_editable': slug})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
@login_required_if_public
|
2012-01-07 19:05:25 +00:00
|
|
|
def edit_cave(request, slug=None):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = slug)
|
2012-05-23 09:23:40 +01:00
|
|
|
if request.POST:
|
|
|
|
form = CaveForm(request.POST, instance=cave)
|
|
|
|
ceFormSet = CaveAndEntranceFormSet(request.POST)
|
2012-06-10 14:59:21 +01:00
|
|
|
versionControlForm = VersionControlCommentForm(request.POST)
|
|
|
|
if form.is_valid() and ceFormSet.is_valid() and versionControlForm.is_valid():
|
|
|
|
cave = form.save()
|
|
|
|
ceinsts = ceFormSet.save(commit=False)
|
|
|
|
for ceinst in ceinsts:
|
|
|
|
ceinst.cave = cave
|
|
|
|
ceinst.save()
|
|
|
|
cave.writeDataFile()
|
|
|
|
return HttpResponseRedirect("/" + cave.url)
|
2012-05-23 09:23:40 +01:00
|
|
|
else:
|
|
|
|
form = CaveForm(instance=cave)
|
2012-06-10 14:59:21 +01:00
|
|
|
ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
|
|
|
|
versionControlForm = VersionControlCommentForm()
|
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
return render_with_context(request,
|
2012-01-07 19:05:25 +00:00
|
|
|
'editcave2.html',
|
|
|
|
{'form': form,
|
2012-06-10 14:59:21 +01:00
|
|
|
'caveAndEntranceFormSet': ceFormSet,
|
|
|
|
'versionControlForm': versionControlForm
|
|
|
|
})
|
|
|
|
|
|
|
|
@login_required_if_public
|
|
|
|
def editEntrance(request, slug=None):
|
|
|
|
entrance = Entrance.objects.get(entranceslug__slug = slug)
|
|
|
|
if request.POST:
|
|
|
|
form = EntranceForm(request.POST, instance = entrance)
|
|
|
|
versionControlForm = VersionControlCommentForm(request.POST)
|
|
|
|
if form.is_valid() and versionControlForm.is_valid():
|
|
|
|
entrance = form.save()
|
|
|
|
entrance.writeDataFile()
|
|
|
|
return HttpResponseRedirect("/" + entrance.url)
|
|
|
|
else:
|
|
|
|
form = EntranceForm(instance = entrance)
|
|
|
|
versionControlForm = VersionControlCommentForm()
|
|
|
|
|
|
|
|
return render_with_context(request,
|
|
|
|
'editentrance.html',
|
|
|
|
{'form': form,
|
|
|
|
'versionControlForm': versionControlForm
|
2012-01-07 19:05:25 +00:00
|
|
|
})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def qm(request,cave_id,qm_id,year,grade=None):
|
|
|
|
year=int(year)
|
|
|
|
try:
|
|
|
|
qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year)
|
|
|
|
return render_with_context(request,'qm.html',locals())
|
|
|
|
|
|
|
|
except QM.DoesNotExist:
|
|
|
|
url=urlparse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id)
|
|
|
|
if grade:
|
|
|
|
url += r'&grade=' + grade
|
|
|
|
return HttpResponseRedirect(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
return render_with_context(request,'entrance.html', {'cave': cave,
|
|
|
|
'entrance': cave_and_ent.entrance,
|
|
|
|
'letter': cave_and_ent.entrance_letter,})
|
|
|
|
|
|
|
|
def entranceSlug(request, slug):
|
2012-06-10 14:59:21 +01:00
|
|
|
entrance = Entrance.objects.get(entranceslug__slug = slug)
|
2011-07-11 02:10:22 +01:00
|
|
|
if entrance.non_public and not request.user.is_authenticated():
|
|
|
|
return render_with_context(request,'nonpublic.html', {'instance': entrance})
|
|
|
|
else:
|
|
|
|
return render_with_context(request,'entranceslug.html', {'entrance': entrance})
|
|
|
|
|
|
|
|
def survexblock(request, survexpath):
|
|
|
|
survexpath = re.sub("/", ".", survexpath)
|
|
|
|
print "jjjjjj", survexpath
|
|
|
|
survexblock = models.SurvexBlock.objects.get(survexpath=survexpath)
|
|
|
|
#ftext = survexblock.filecontents()
|
|
|
|
ftext = survexblock.text
|
|
|
|
return render_with_context(request,'survexblock.html', {'survexblock':survexblock, 'ftext':ftext, })
|
|
|
|
|
|
|
|
def surveyindex(request):
|
|
|
|
surveys=Survey.objects.all()
|
|
|
|
expeditions=Expedition.objects.order_by("-year")
|
|
|
|
return render_with_context(request,'survey.html',locals())
|
|
|
|
|
|
|
|
def survey(request,year,wallet_number):
|
|
|
|
surveys=Survey.objects.all()
|
|
|
|
expeditions=Expedition.objects.order_by("-year")
|
|
|
|
current_expedition=Expedition.objects.filter(year=year)[0]
|
|
|
|
|
|
|
|
if wallet_number!='':
|
|
|
|
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')
|
|
|
|
|
|
|
|
return render_with_context(request,'survey.html', locals())
|
|
|
|
|
|
|
|
def cave_description(request, cavedescription_name):
|
|
|
|
cave_description = get_object_or_404(CaveDescription, short_name = cavedescription_name)
|
|
|
|
return render_with_context(request,'cave_description.html', locals())
|
|
|
|
|
|
|
|
def get_entrances(request, caveslug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = caveslug)
|
|
|
|
return render_with_context(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def get_qms(request, caveslug):
|
2012-06-10 14:59:21 +01:00
|
|
|
cave = Cave.objects.get(caveslug__slug = caveslug)
|
|
|
|
return render_with_context(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
2012-08-10 18:02:13 +01:00
|
|
|
|
|
|
|
areanames = [
|
|
|
|
#('', 'Location unclear'),
|
|
|
|
('1a', '1a – Plateau: around Top Camp'),
|
|
|
|
('1b', '1b – Western plateau near 182'),
|
|
|
|
('1c', '1c – Eastern plateau near 204 walk-in path'),
|
|
|
|
('1d', '1d – Further plateau around 76'),
|
|
|
|
('2a', '2a – Southern Schwarzmooskogel near 201 path and the Nipple'),
|
|
|
|
('2b', '2b – Eishöhle area'),
|
|
|
|
('2c', '2c – Kaninchenhöhle area'),
|
|
|
|
('2d', '2d – Steinbrückenhöhle area'),
|
|
|
|
('3', '3 – Bräuning Alm'),
|
|
|
|
('4', '4 – Kratzer valley'),
|
|
|
|
('5', '5 – Schwarzmoos-Wildensee'),
|
|
|
|
('6', '6 – Far plateau'),
|
|
|
|
('7', '7 – Egglgrube'),
|
|
|
|
('8a', '8a – Loser south face'),
|
|
|
|
('8b', '8b – Loser below Dimmelwand'),
|
|
|
|
('8c', '8c – Augst See'),
|
|
|
|
('8d', '8d – Loser-Hochganger ridge'),
|
|
|
|
('9', '9 – Gschwandt Alm'),
|
|
|
|
('10', '10 – Altaussee'),
|
|
|
|
('11', '11 – Augstbach')
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def prospecting(request):
|
|
|
|
for key, name in areanames:
|
|
|
|
print key, Area.objects.get(short_name = key)
|
|
|
|
areas = [ (name, Area.objects.get(short_name = key)) for key, name in areanames ]
|
|
|
|
return render_with_context(request,'prospecting.html', {"areas": areas})
|
|
|
|
|