import troggle.settings as settings from troggle.helper import login_required_if_public from utils import render_with_context from django.http import HttpResponse, HttpResponseRedirect, Http404 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): 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(): print "flat path noinfo", path return HttpResponseRedirect(reverse("auth_login") + '?next=%s' % request.path) if path.endswith("/") or path == "": try: o = open(os.path.normpath(settings.EXPOWEB + path + "index.html"), "rb") path = path + "index.html" except IOError: try: o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb") path = path + "index.htm" except IOError: raise Http404 else: try: o = open(os.path.normpath(settings.EXPOWEB + path), "rb") except IOError: raise Http404 if path.endswith(".htm") or path.endswith(".html"): html = o.read() m = re.search(r"(.*).*(.*)", html, re.DOTALL) if m: head, body = m.groups() else: return HttpResponse(html + "Page could not be split into header and body") m = re.search(r"(.*)", head, re.DOTALL) if m: title, = m.groups() else: title = "" linksmatch = re.match('(.*)