summaryrefslogtreecommitdiffstats
path: root/flatpages
diff options
context:
space:
mode:
authorMartin Green <martin.speleo@gmail.com>2011-08-08 12:18:47 +0100
committerMartin Green <martin.speleo@gmail.com>2011-08-08 12:18:47 +0100
commit36b1888f468d5837d117e52920ece4d364a569b8 (patch)
treee86fca2c502b65c30a9c74f644f240d2dde95e95 /flatpages
parentc09a668620e654d81f9e80b8a3c82d30b82aa26b (diff)
downloadtroggle-36b1888f468d5837d117e52920ece4d364a569b8.tar.gz
troggle-36b1888f468d5837d117e52920ece4d364a569b8.tar.bz2
troggle-36b1888f468d5837d117e52920ece4d364a569b8.zip
Added 'page not found do you wnat to make this page' page. Minor tweaks
Diffstat (limited to 'flatpages')
-rw-r--r--flatpages/views.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/flatpages/views.py b/flatpages/views.py
index 6279f4d..3357e64 100644
--- a/flatpages/views.py
+++ b/flatpages/views.py
@@ -47,12 +47,12 @@ def flatpage(request, path):
o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb")
path = path + "index.htm"
except IOError:
- raise Http404
+ return render_with_context(request, 'pagenotfound.html', {'path': path})
else:
try:
o = open(os.path.normpath(settings.EXPOWEB + path), "rb")
except IOError:
- raise Http404
+ return render_with_context(request, 'pagenotfound.html', {'path': path})
if path.endswith(".htm") or path.endswith(".html"):
html = o.read()
@@ -105,19 +105,22 @@ def editflatpage(request, path):
try:
filepath = os.path.normpath(settings.EXPOWEB + path)
o = open(filepath, "r")
+ html = o.read()
+ m = re.search(r"<head>(.*)</head>.*<body[^>]*>(.*)</body>", html, re.DOTALL)
+ if m:
+ filefound = True
+ head, body = m.groups()
+ if re.search(r"iso-8859-1", html):
+ linksmatch = re.match('(.*)<ul id="links">', body, re.DOTALL)
+ if linksmatch:
+ body, = linksmatch.groups()
+ body = unicode(body, "iso-8859-1")
+ else:
+ return HttpResponse("Page could not be split into header and body")
except IOError:
- raise Http404
- html = o.read()
- 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):
- linksmatch = re.match('(.*)<ul id="links">', body, re.DOTALL)
- if linksmatch:
- body, = linksmatch.groups()
- body = unicode(body, "iso-8859-1")
- else:
- return HttpResponse("Page could not be split into header and body")
+ filefound = False
+
+
if request.method == 'POST': # If the form has been submitted...
flatpageForm = FlatPageForm(request.POST) # A form bound to the POST data
if flatpageForm.is_valid():# Form valid therefore write file
@@ -128,15 +131,18 @@ def editflatpage(request, path):
f.close()
return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST
else:
- m = re.search(r"<title>(.*)</title>", head, re.DOTALL)
- if m:
- title, = m.groups()
+ if filefound:
+ m = re.search(r"<title>(.*)</title>", head, re.DOTALL)
+ if m:
+ title, = m.groups()
+ else:
+ title = ""
+ flatpageForm = FlatPageForm({"html": body, "title": title})
else:
- title = ""
- flatpageForm = FlatPageForm({"html": body, "title": title})
+ flatpageForm = FlatPageForm()
return render_with_context(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, })
class FlatPageForm(forms.Form):
title = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
- html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
+ html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 20}))