diff options
author | expo <expo@expobox.potato.hut> | 2012-08-06 12:19:48 +0200 |
---|---|---|
committer | expo <expo@expobox.potato.hut> | 2012-08-06 12:19:48 +0200 |
commit | 1ef274ec1dca0c54ea3dbda6887960e8f665e2c9 (patch) | |
tree | 34b38e1cd1016393fe552d8f5e106d6c3ded95fd /flatpages/views.py | |
parent | 0f5627505f9249f520c6f43bba5864643dc8be0e (diff) | |
download | troggle-1ef274ec1dca0c54ea3dbda6887960e8f665e2c9.tar.gz troggle-1ef274ec1dca0c54ea3dbda6887960e8f665e2c9.tar.bz2 troggle-1ef274ec1dca0c54ea3dbda6887960e8f665e2c9.zip |
Editing no longer changes files more than nesecary. Removed TinyMCE editing. /Sumbit/Submit
Diffstat (limited to 'flatpages/views.py')
-rw-r--r-- | flatpages/views.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/flatpages/views.py b/flatpages/views.py index 0999d31..6fb68bb 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -57,9 +57,9 @@ def flatpage(request, path): if path.endswith(".htm") or path.endswith(".html"): html = o.read() - m = re.search(r"<head>(.*)</head>.*<body[^>]*>(.*)</body>", html, re.DOTALL + re.IGNORECASE) + m = re.search(r"(.*)<\s*head([^>]*)>(.*)<\s*/head\s*>(.*)<\s*body([^>]*)>(.*)<\s*/body\s*>(.*)", html, re.DOTALL + re.IGNORECASE) if m: - head, body = m.groups() + preheader, headerattrs, head, postheader, bodyattrs, body, postbody = m.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) @@ -107,13 +107,13 @@ def editflatpage(request, path): 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) + 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) + preheader, headerargs, head, postheader, bodyargs, body, postbody = m.groups() + linksmatch = re.match('(.*)(<ul\s+id="links">.*)', body, re.DOTALL + re.IGNORECASE) if linksmatch: - body, = linksmatch.groups() + body, links = linksmatch.groups() if re.search(r"iso-8859-1", html): body = unicode(body, "iso-8859-1") else: @@ -126,9 +126,22 @@ def editflatpage(request, path): 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}) - f.write(template.render(context)) + if filefound: + headmatch = re.match(r"(.*)<title>.*</title>(.*)", head, re.DOTALL + re.IGNORECASE) + if headmatch: + head = headmatch.group(1) + "<title>" + flatpageForm.cleaned_data["title"] + "</title>" + headmatch.group(2) + else: + head = "<title>" + flatpageForm.cleaned_data["title"] + "</title>" + else: + head = "<title>" + flatpageForm.cleaned_data["title"] + "</title>" + preheader = "<html>" + headerargs = "" + postheader = "" + bodyargs = "" + postbody = "</html>" + body = flatpageForm.cleaned_data["html"] + body = body.replace("\r", "") + f.write("%s<head%s>%s</head>%s<body%s>\n%s</body>%s" % (preheader, headerargs, head, postheader, bodyargs, body, postbody)) f.close() return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST else: @@ -146,4 +159,4 @@ def editflatpage(request, path): class FlatPageForm(forms.Form): title = forms.CharField(widget=forms.TextInput(attrs={'size':'60'})) - html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 20})) + html = forms.CharField(widget=forms.Textarea()) |