mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 16:51:54 +00:00
Added 'page not found do you wnat to make this page' page. Minor tweaks
This commit is contained in:
parent
a0df539ca1
commit
3205e1752c
@ -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}))
|
||||
|
@ -9,6 +9,6 @@
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{{form.as_p}}
|
||||
<p><input type="submit" value="Submit" /></p>
|
||||
{% include "menu.html" %}
|
||||
</form>
|
||||
{% include "menu.html" %}
|
||||
{% endblock %}
|
||||
|
7
templates/pagenotfound.html
Normal file
7
templates/pagenotfound.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends "expobase.html" %}
|
||||
{% block title %}Page not found {{ path }}{% endblock %}
|
||||
{% block body %}
|
||||
<h1>Page not found {{ path }}</h1>
|
||||
<a href="{%url editflatpage path %}">Create this page.</a>
|
||||
{% include "menu.html" %}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user