diff options
author | Wookey <wookey@wookware.org> | 2011-07-11 00:49:18 +0100 |
---|---|---|
committer | Wookey <wookey@wookware.org> | 2011-07-11 00:49:18 +0100 |
commit | 129d93dfa74eaa6f8ec6aeefaff38699bca8d40f (patch) | |
tree | 30de6c64f4fb6d281c9d15879af5d8940eba3cb1 /flatpages/views.py | |
parent | 28924db9f87af72343206383e9065841e3fd1c14 (diff) | |
parent | 65c55f0f21fe85a678d48842da10e0ea5c917ae5 (diff) | |
download | troggle-129d93dfa74eaa6f8ec6aeefaff38699bca8d40f.tar.gz troggle-129d93dfa74eaa6f8ec6aeefaff38699bca8d40f.tar.bz2 troggle-129d93dfa74eaa6f8ec6aeefaff38699bca8d40f.zip |
Merge from Martin's tip
Diffstat (limited to 'flatpages/views.py')
-rw-r--r-- | flatpages/views.py | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/flatpages/views.py b/flatpages/views.py index 9c7483e..5f7b579 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -7,12 +7,33 @@ from django.core.urlresolvers import reverse from django.template import Context, loader import django.forms as forms from tinymce.widgets import TinyMCE +from troggle.flatpages.models import Redirect, EntranceRedirect +from troggle.core.models import Cave +import troggle.core.views_caves import os import re def flatpage(request, path): - print path + try: + r = Redirect.objects.get(originalURL = path) + return HttpResponseRedirect(r.newURL) # Redirect after POST + except Redirect.DoesNotExist: + pass + + try: + r = Cave.objects.get(url = path) + return troggle.core.views_caves.caveSlug(request, r.slug) + except Cave.DoesNotExist: + pass + + try: + r = EntranceRedirect.objects.get(originalURL = path) + return troggle.core.views_caves.enranceSlug(request, r.entrance.slug) + except EntranceRedirect.DoesNotExist: + pass + + if path.startswith("noinfo") and settings.PUBLIC_SITE and not request.user.is_authenticated(): return HttpResponseRedirect(reverse("auth_login") + '?next=%s' % request.path) try: @@ -21,20 +42,32 @@ def flatpage(request, path): raise Http404 if path.endswith(".htm") or path.endswith(".html"): html = o.read() + m = re.search(r"<head>(.*)</head>.*<body>(.*)</body>", html, re.DOTALL) + mwithid = re.search(r'<head>(.*)</head>.*<body id="([^"]*)">(.*)</body>', html, re.DOTALL) if m: head, body = m.groups() + bodyid = None + elif mwithid: + head, bodyid, body = mwithid.groups() else: return HttpResponse(html + "Page could not be split into header and body") if re.search(r"iso-8859-1", html): body = unicode(body, "iso-8859-1") - return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'head': head, 'body': body}) + return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'head': head, 'body': body, "bodyid": bodyid}) else: return HttpResponse(o.read()) @login_required_if_public def editflatpage(request, path): try: + r = CaveRedirect.objects.get(originalURL = path) + return troggle.core.views_caves.editCave(request, r.cave.slug) + except CaveRedirect.DoesNotExist: + pass + + + try: filepath = os.path.normpath(settings.EXPOWEB + path) o = open(filepath, "r") except IOError: @@ -43,6 +76,8 @@ def editflatpage(request, path): m = re.search(r"<head>(.*)</head>.*<body>(.*)</body>", html, re.DOTALL) if m: head, body = m.groups() + if re.search(r"iso-8859-1", html): + body = unicode(body, "iso-8859-1") else: return HttpResponse("Page could not be split into header and body") if request.method == 'POST': # If the form has been submitted... |