From f44b0be459eee586c37783ea0015f3928bdaf654 Mon Sep 17 00:00:00 2001 From: Martin Green Date: Mon, 11 Jul 2011 00:03:36 +0100 Subject: [PATCH] slug views, start of cave eidt form, cavelist splitting up by kataster area etc. --- core/views_caves.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/core/views_caves.py b/core/views_caves.py index e24e6c2..24a85c7 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -1,6 +1,9 @@ from troggle.core.models import Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription +from troggle.core.forms import CaveForm import troggle.core.models as models import troggle.settings as settings +from troggle.helper import login_required_if_public + from django.forms.models import formset_factory from django.core.urlresolvers import reverse from utils import render_with_context # see views_logbooks for explanation on this. @@ -21,15 +24,31 @@ 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 ] - return render_with_context(request,'caveindex.html', {'caves': caves, 'notablecaves':notablecaves}) + caves1623 = Cave.objects.filter(area__short_name = "1623") + caves1626 = Cave.objects.filter(area__short_name = "1626") + 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) + if cave.non_public and not request.user.is_authenticated(): + return render_with_context(request,'nonpublic.html', {'instance': cave, 'cavepage': True}) + else: + return render_with_context(request,'cave.html', {'cave': cave, 'cavepage': True}) + +def caveSlug(request, slug): + cave = Cave.objects.get(slug = slug) if cave.non_public and not request.user.is_authenticated(): return render_with_context(request,'nonpublic.html', {'instance': cave}) else: return render_with_context(request,'cave.html', {'cave': cave}) - + +@login_required_if_public +def editCave(request, slug=None): + form = CaveForm() + return render_with_context(request, + 'editcave.html', + {'form': form}) + def qm(request,cave_id,qm_id,year,grade=None): year=int(year) try: @@ -43,6 +62,7 @@ def qm(request,cave_id,qm_id,year,grade=None): 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] @@ -50,6 +70,13 @@ def ent(request, cave_id, ent_letter): 'entrance': cave_and_ent.entrance, 'letter': cave_and_ent.entrance_letter,}) +def entranceSlug(request, slug): + entrance = Entrance.objects.get(slug = slug) + 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