summaryrefslogtreecommitdiffstats
path: root/flatpages/views.py
diff options
context:
space:
mode:
authorexpo <expo@expobox.potato.hut>2011-09-02 03:39:20 +0200
committerexpo <expo@expobox.potato.hut>2011-09-02 03:39:20 +0200
commit378ddfe96d4a9497be7f00aade1b0ef1cb3d01d3 (patch)
treeed5d2156f5374d7705b2f163508962f8c012aa6b /flatpages/views.py
parent4def1aece2eb713c90ea3cec027c40458f20c8ed (diff)
parent2145d1187ee401ba0b768a8383b06aef866bdbce (diff)
downloadtroggle-378ddfe96d4a9497be7f00aade1b0ef1cb3d01d3.tar.gz
troggle-378ddfe96d4a9497be7f00aade1b0ef1cb3d01d3.tar.bz2
troggle-378ddfe96d4a9497be7f00aade1b0ef1cb3d01d3.zip
branch merge
Diffstat (limited to 'flatpages/views.py')
-rw-r--r--flatpages/views.py65
1 files changed, 43 insertions, 22 deletions
diff --git a/flatpages/views.py b/flatpages/views.py
index e9db223..f46488e 100644
--- a/flatpages/views.py
+++ b/flatpages/views.py
@@ -15,7 +15,6 @@ import os
import re
def flatpage(request, path):
- print "gggggg", path
try:
r = Redirect.objects.get(originalURL = path)
return HttpResponseRedirect(r.newURL) # Redirect after POST
@@ -36,6 +35,7 @@ def flatpage(request, path):
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 == "":
@@ -45,29 +45,34 @@ def flatpage(request, path):
except IOError:
try:
o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb")
- path = path + "index.html"
+ 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()
- m = re.search(r"<head>(.*)</head>.*<body>(.*)</body>", html, re.DOTALL)
- mwithid = re.search(r'<head>(.*)</head>.*<body id="([^"]*)">(.*)</body>', html, re.DOTALL)
+ m = re.search(r"<head>(.*)</head>.*<body[^>]*>(.*)</body>", html, re.DOTALL + re.IGNORECASE)
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")
+ m = re.search(r"<title>(.*)</title>", head, re.DOTALL + re.IGNORECASE)
+ if m:
+ title, = m.groups()
+ else:
+ title = ""
+ linksmatch = re.match('(.*)<ul id="links">', body, re.DOTALL + re.IGNORECASE)
+ if linksmatch:
+ body, = linksmatch.groups()
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, "bodyid": bodyid})
+ body.strip
+ return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm")})
else:
return HttpResponse(o.read(), mimetype=getmimetype(path))
@@ -100,28 +105,44 @@ 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 + re.IGNORECASE)
+ if m:
+ filefound = True
+ head, body = m.groups()
+ linksmatch = re.match('(.*)<ul\s+id="links">', body, re.DOTALL + re.IGNORECASE)
+ if linksmatch:
+ body, = linksmatch.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")
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):
- 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
f = open(filepath, "w")
template = loader.get_template('dataformat/flatfile.html')
- context = Context({'form': flatpageForm.cleaned_data, 'head': head})
+ context = Context({'form': flatpageForm.cleaned_data})
f.write(template.render(context))
f.close()
return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST
else:
- flatpageForm = FlatPageForm({"html": body})
+ if filefound:
+ m = re.search(r"<title>(.*)</title>", head, re.DOTALL + re.IGNORECASE)
+ if m:
+ title, = m.groups()
+ else:
+ title = ""
+ flatpageForm = FlatPageForm({"html": body, "title": title})
+ else:
+ flatpageForm = FlatPageForm()
return render_with_context(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, })
class FlatPageForm(forms.Form):
- html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
+ title = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
+
+ html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 20}))