summaryrefslogtreecommitdiffstats
path: root/flatpages
diff options
context:
space:
mode:
authorMartin Green <martin.speleo@gmail.com>2011-08-08 09:51:47 +0100
committerMartin Green <martin.speleo@gmail.com>2011-08-08 09:51:47 +0100
commitd75bad22de7e41a7049f6873762f0c38a62cff30 (patch)
tree6a022f170ab9dc98d09f9d80a22b68a7e38726cb /flatpages
parentc039183137802dc1a00af876f77ad8f47d4cc8f4 (diff)
downloadtroggle-d75bad22de7e41a7049f6873762f0c38a62cff30.tar.gz
troggle-d75bad22de7e41a7049f6873762f0c38a62cff30.tar.bz2
troggle-d75bad22de7e41a7049f6873762f0c38a62cff30.zip
Allow for editing flatpage titles, and made a common uneditable list of links.
Diffstat (limited to 'flatpages')
-rw-r--r--flatpages/views.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/flatpages/views.py b/flatpages/views.py
index f411bfa..1a445ea 100644
--- a/flatpages/views.py
+++ b/flatpages/views.py
@@ -35,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 == "":
@@ -56,17 +57,22 @@ def flatpage(request, path):
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)
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)
+ if m:
+ title, = m.groups()
+ else:
+ title = ""
+ linksmatch = re.match('(.*)<ul id="links">', body, re.DOTALL)
+ 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, 'head': head, 'body': body, 'homepage': (path == "index.htm")})
else:
return HttpResponse(o.read(), mimetype=getmimetype(path))
@@ -106,6 +112,9 @@ def editflatpage(request, path):
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")
@@ -114,13 +123,20 @@ def editflatpage(request, path):
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})
+ m = re.search(r"<title>(.*)</title>", head, re.DOTALL)
+ if m:
+ title, = m.groups()
+ else:
+ title = ""
+ flatpageForm = FlatPageForm({"html": body, "title": title})
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': 30}))