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"
(.*).*]*>(.*)", html, re.DOTALL)
+ if m:
+ filefound = True
+ head, body = m.groups()
+ if re.search(r"iso-8859-1", html):
+ linksmatch = re.match('(.*)', 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"(.*).*]*>(.*)", html, re.DOTALL)
- if m:
- head, body = m.groups()
- if re.search(r"iso-8859-1", html):
- linksmatch = re.match('(.*)', 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"(.*)", head, re.DOTALL)
- if m:
- title, = m.groups()
+ if filefound:
+ m = re.search(r"(.*)", 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}))
diff --git a/templates/editflatpage.html b/templates/editflatpage.html
index 547b94d..4768078 100644
--- a/templates/editflatpage.html
+++ b/templates/editflatpage.html
@@ -9,6 +9,6 @@
+{% include "menu.html" %}
{% endblock %}
diff --git a/templates/pagenotfound.html b/templates/pagenotfound.html
new file mode 100644
index 0000000..03569de
--- /dev/null
+++ b/templates/pagenotfound.html
@@ -0,0 +1,7 @@
+{% extends "expobase.html" %}
+{% block title %}Page not found {{ path }}{% endblock %}
+{% block body %}
+Page not found {{ path }}
+Create this page.
+{% include "menu.html" %}
+{% endblock %}