From b1b91d3f62727efdf694772840e399f5dcdaedf2 Mon Sep 17 00:00:00 2001 From: expo <expo@expobox.potato.hut> Date: Sun, 7 Aug 2011 16:11:35 +0200 Subject: [PATCH 01/13] Make caveindex link to urls in the original hierachy such that their hyperlinks and images work. --- templates/caveindex.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/caveindex.html b/templates/caveindex.html index 8f16e87..42322d3 100644 --- a/templates/caveindex.html +++ b/templates/caveindex.html @@ -10,7 +10,7 @@ <h3>Notable caves</h3> <ul> {% for cave in notablecaves %} - <li> <a href="{{ cave.get_absolute_url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li> + <li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li> {% endfor %} </ul> @@ -19,7 +19,7 @@ <ul class="searchable"> {% for cave in caves1623 %} - <li> <a href="{{ cave.get_absolute_url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li> + <li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li> {% endfor %} </ul> @@ -29,7 +29,7 @@ <ul class="searchable"> {% for cave in caves1626 %} - <li> <a href="{{ cave.get_absolute_url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li> + <li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li> {% endfor %} </ul> From 24fdf9be3c4cc2f92e72ff5a120f67dbdff783a3 Mon Sep 17 00:00:00 2001 From: expo <expo@expobox.potato.hut> Date: Sun, 7 Aug 2011 16:12:52 +0200 Subject: [PATCH 02/13] Changed ubuntu local settings to be applicable to the expo machine --- localsettingsubuntu.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/localsettingsubuntu.py b/localsettingsubuntu.py index 79d5db9..0a1d5e8 100644 --- a/localsettingsubuntu.py +++ b/localsettingsubuntu.py @@ -1,9 +1,10 @@ +import sys # link localsettings to this file for use on expo computer in austria DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = 'troggle' # Or path to database file if using sqlite3. -DATABASE_USER = 'troggler3' # Not used with sqlite3. -DATABASE_PASSWORD = 'ggg' # Not used with sqlite3. +DATABASE_USER = 'expo' # Not used with sqlite3. +DATABASE_PASSWORD = 'gosser' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. @@ -42,10 +43,10 @@ TINY_MCE_MEDIA_ROOT = '/usr/share/tinymce/www/' TINY_MCE_MEDIA_URL = URL_ROOT + DIR_ROOT + 'tinymce_media/' TEMPLATE_DIRS = ( - "/home/goatchurch/expoweb/troggle/templates", + "/home/expo/expofiles/troggle/templates", # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) -LOGFILE = '/home/expo/expofiles/expoweb/parsing_log.txt' +LOGFILE = '/home/expo/expofiles/troggle/parsing_log.txt' From f527bd616abcfe3ccbcc08fbdfacdb4c4a22e5f0 Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Sun, 7 Aug 2011 17:30:18 +0100 Subject: [PATCH 03/13] bug fix for edit link for index files --- flatpages/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flatpages/views.py b/flatpages/views.py index e9db223..eed5f38 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -45,7 +45,7 @@ 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 else: From da3efb97ceeb73efd59a3345532e65336cf3ba49 Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Sun, 7 Aug 2011 19:17:27 +0100 Subject: [PATCH 04/13] Changed regex for finding head and body of flat pages. --- flatpages/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flatpages/views.py b/flatpages/views.py index eed5f38..f411bfa 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 @@ -103,7 +102,7 @@ def editflatpage(request, path): except IOError: raise Http404 html = o.read() - m = re.search(r"<head>(.*)</head>.*<body>(.*)</body>", html, re.DOTALL) + 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): From c039183137802dc1a00af876f77ad8f47d4cc8f4 Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 08:51:12 +0100 Subject: [PATCH 05/13] Allow the viewing of noinfo caves on non public website without login --- core/views_caves.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/views_caves.py b/core/views_caves.py index 4a79652..9fcf9b4 100644 --- a/core/views_caves.py +++ b/core/views_caves.py @@ -30,39 +30,39 @@ def caveindex(request): def cave(request, cave_id='', offical_name=''): cave=getCave(cave_id) - if cave.non_public and not request.user.is_authenticated(): + if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): return render_with_context(request,'nonpublic.html', {'instance': cave, 'cavepage': True}) else: return render_with_context(request,'cave.html', {'cave': cave, 'cavepage': True}) def caveEntrance(request, slug): cave = Cave.objects.get(slug = slug) - if cave.non_public and not request.user.is_authenticated(): + if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): return render_with_context(request,'nonpublic.html', {'instance': cave}) else: return render_with_context(request,'cave_entrances.html', {'cave': cave}) def caveDescription(request, slug): cave = Cave.objects.get(slug = slug) - if cave.non_public and not request.user.is_authenticated(): + if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): return render_with_context(request,'nonpublic.html', {'instance': cave}) else: return render_with_context(request,'cave_uground_description.html', {'cave': cave}) def caveQMs(request, slug): cave = Cave.objects.get(slug = slug) - if cave.non_public and not request.user.is_authenticated(): + if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): return render_with_context(request,'nonpublic.html', {'instance': cave}) else: return render_with_context(request,'cave_qms.html', {'cave': cave}) def caveLogbook(request, slug): cave = Cave.objects.get(slug = slug) - if cave.non_public and not request.user.is_authenticated(): + if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): return render_with_context(request,'nonpublic.html', {'instance': cave}) else: return render_with_context(request,'cave_logbook.html', {'cave': cave}) def caveSlug(request, slug): cave = Cave.objects.get(slug = slug) - if cave.non_public and not request.user.is_authenticated(): + if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated(): return render_with_context(request,'nonpublic.html', {'instance': cave}) else: return render_with_context(request,'cave.html', {'cave': cave}) From d75bad22de7e41a7049f6873762f0c38a62cff30 Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 09:51:47 +0100 Subject: [PATCH 06/13] Allow for editing flatpage titles, and made a common uneditable list of links. --- flatpages/views.py | 32 ++++++++++++++++++++++-------- templates/cavebase.html | 7 +------ templates/dataformat/flatfile.html | 4 +++- templates/editflatpage.html | 2 +- templates/flatpage.html | 6 +++--- templates/menu.html | 12 +++++++++++ 6 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 templates/menu.html 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})) diff --git a/templates/cavebase.html b/templates/cavebase.html index 7e83151..a0ffd4d 100644 --- a/templates/cavebase.html +++ b/templates/cavebase.html @@ -16,11 +16,6 @@ </head> <body> {% block content %}{% endblock %} -{% block menu %} -<ul id="links"> -<li>Back to <a href="/index.htm">Expedition home page</a></li> -<li>Back to <a href="http://cucc.survex.com/">CUCC home page</a></li> -</ul> -{% endblock %} +{% include "menu.html" %} </body> </html> diff --git a/templates/dataformat/flatfile.html b/templates/dataformat/flatfile.html index 1ddb7a5..048606e 100644 --- a/templates/dataformat/flatfile.html +++ b/templates/dataformat/flatfile.html @@ -1,7 +1,9 @@ {% autoescape off %} <html> <head> -{{ head }} +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +<title>{{ form.title }}</title> +<link rel="stylesheet" type="text/css" href="css/main2.css" /> </head> <body> {{ form.html }} diff --git a/templates/editflatpage.html b/templates/editflatpage.html index 85a5bcc..67290a7 100644 --- a/templates/editflatpage.html +++ b/templates/editflatpage.html @@ -6,7 +6,7 @@ {% endblock %} {% block content %} <form action="" method="post">{% csrf_token %} -{{form}} +{{form.as_p}} <p><input type="submit" value="Submit" /></p> </form> {% endblock %} diff --git a/templates/flatpage.html b/templates/flatpage.html index 04ff1f8..42b8481 100644 --- a/templates/flatpage.html +++ b/templates/flatpage.html @@ -2,9 +2,9 @@ <head> {{ head|safe }} </head> -<body{% if bodyid %} id="{{ bodyid }}"{% endif %}> +<body{% if homepage %} id="homepage"{% endif %}> {{ body|safe }} -{% if editable %}<a href="{% url editflatpage path %}">Edit</a>{% endif %} -<a href="/troggle">Troggle</a> + +{% include "menu.html" %} </body> </html> diff --git a/templates/menu.html b/templates/menu.html new file mode 100644 index 0000000..f74aed4 --- /dev/null +++ b/templates/menu.html @@ -0,0 +1,12 @@ +{% if not homepage %} +<ul id="links"> +<li><a href="/index.htm">Home</a></li> +<li><a href="/infodx.htm">Main Index</a></li> +<li><a href="/troggle">Troggle</a></li> +<li><a href="/areas.htm">Areas</a></li> +<li><a href="/indxal.htm">Caves</a></li> +<li><a href="/handbook/index.htm">Handbook</a></li> +<li><a href="/pubs.htm">Reports</a></li> +{% if editable %}<li><a href="{% url editflatpage path %}">Edit</a></li>{% endif %} +</ul> +{% endif %} From 4c4b6ef11febe13f6bb7db4510e115853aca50a5 Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 10:04:59 +0100 Subject: [PATCH 07/13] Allow pages to be rendered when the body tag has attributes. Put an edit link on the homepage. --- flatpages/views.py | 2 +- templates/flatpage.html | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/flatpages/views.py b/flatpages/views.py index 1a445ea..a080437 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -56,7 +56,7 @@ 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) + m = re.search(r"<head>(.*)</head>.*<body[^>]*>(.*)</body>", html, re.DOTALL) if m: head, body = m.groups() else: diff --git a/templates/flatpage.html b/templates/flatpage.html index 42b8481..fddc69a 100644 --- a/templates/flatpage.html +++ b/templates/flatpage.html @@ -5,6 +5,8 @@ <body{% if homepage %} id="homepage"{% endif %}> {{ body|safe }} -{% include "menu.html" %} +{% if homepage %}{% if editable %}<a href="{% url editflatpage path %}">Edit</a>{% endif %}{%else %}{% include "menu.html" %}{% endif %} + + </body> </html> From 57ace114278533b461f57ab23b1ca9b199590381 Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 10:58:50 +0100 Subject: [PATCH 08/13] =Make a common base for expoweb pages. Ignore any header information in expoweb except titles. --- flatpages/views.py | 2 +- templates/dataformat/flatfile.html | 2 -- templates/editflatpage.html | 8 +++++--- templates/expobase.html | 13 +++++++++++++ templates/flatpage.html | 15 +++++---------- 5 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 templates/expobase.html diff --git a/flatpages/views.py b/flatpages/views.py index a080437..6279f4d 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -72,7 +72,7 @@ def flatpage(request, path): if re.search(r"iso-8859-1", html): body = unicode(body, "iso-8859-1") body.strip - return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'head': head, 'body': body, 'homepage': (path == "index.htm")}) + 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)) diff --git a/templates/dataformat/flatfile.html b/templates/dataformat/flatfile.html index 048606e..07d03ca 100644 --- a/templates/dataformat/flatfile.html +++ b/templates/dataformat/flatfile.html @@ -1,9 +1,7 @@ {% autoescape off %} <html> <head> -<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>{{ form.title }}</title> -<link rel="stylesheet" type="text/css" href="css/main2.css" /> </head> <body> {{ form.html }} diff --git a/templates/editflatpage.html b/templates/editflatpage.html index 67290a7..547b94d 100644 --- a/templates/editflatpage.html +++ b/templates/editflatpage.html @@ -1,12 +1,14 @@ -{% extends "base.html" %} +{% extends "expobase.html" %} {% block title %}Edit {{ path }}{% endblock %} -{% block head %} +{% block extrahead %} {% load csrffaker %} <script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script> {% endblock %} -{% block content %} +{% block body %} +<h1>Edit {{ path }}</h1> <form action="" method="post">{% csrf_token %} {{form.as_p}} <p><input type="submit" value="Submit" /></p> +{% include "menu.html" %} </form> {% endblock %} diff --git a/templates/expobase.html b/templates/expobase.html new file mode 100644 index 0000000..0ef74c1 --- /dev/null +++ b/templates/expobase.html @@ -0,0 +1,13 @@ +{% autoescape off %} +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +<title>{% block title %}{% endblock %}</title> +<link rel="stylesheet" type="text/css" href="css/main2.css" /> +{% block extrahead %}{% endblock %} +</head> +<body {% block bodyattrs %}{% endblock %}> +{% block body %}{% endblock %} +</body> +</html> +{% endautoescape %} diff --git a/templates/flatpage.html b/templates/flatpage.html index fddc69a..47863e3 100644 --- a/templates/flatpage.html +++ b/templates/flatpage.html @@ -1,12 +1,7 @@ -<html> -<head> -{{ head|safe }} -</head> -<body{% if homepage %} id="homepage"{% endif %}> +{% extends "expobase.html" %} +{% block title %}{{ title }}{% endblock %} +{% block bodyattrs %}{% if homepage %} id="homepage"{% endif %}{% endblock %} +{% block body %} {{ body|safe }} - {% if homepage %}{% if editable %}<a href="{% url editflatpage path %}">Edit</a>{% endif %}{%else %}{% include "menu.html" %}{% endif %} - - -</body> -</html> +{% endblock %} From a0df539ca1db4ae3cf647c2755f4fe279a3b4a3c Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 12:17:38 +0100 Subject: [PATCH 09/13] Fix logbook editing --- core/views_logbooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/views_logbooks.py b/core/views_logbooks.py index 2cf9163..0aee9c6 100644 --- a/core/views_logbooks.py +++ b/core/views_logbooks.py @@ -5,7 +5,7 @@ import troggle.settings as settings import django.db.models from troggle.parsers.logbooks import LoadLogbookForExpedition from troggle.parsers.people import GetPersonExpeditionNameLookup -#from troggle.core.forms import PersonForm, getTripForm, get_name +from troggle.core.forms import getTripForm#, get_name, PersonForm from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect, HttpResponse from django.template import Context, loader From 3205e1752ca43f956da8a2b8d96dc1a1350d3022 Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 12:18:47 +0100 Subject: [PATCH 10/13] Added 'page not found do you wnat to make this page' page. Minor tweaks --- flatpages/views.py | 46 +++++++++++++++++++++---------------- templates/editflatpage.html | 2 +- templates/pagenotfound.html | 7 ++++++ 3 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 templates/pagenotfound.html 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"<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})) 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 @@ <form action="" method="post">{% csrf_token %} {{form.as_p}} <p><input type="submit" value="Submit" /></p> -{% include "menu.html" %} </form> +{% 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 %} +<h1>Page not found {{ path }}</h1> +<a href="{%url editflatpage path %}">Create this page.</a> +{% include "menu.html" %} +{% endblock %} From fe1989001cca6c00f2b2fd75e47a57127d51926a Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 12:40:47 +0100 Subject: [PATCH 11/13] template changes. Fix link to css. --- templates/expobase.html | 2 +- templates/menu.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/expobase.html b/templates/expobase.html index 0ef74c1..5cadb61 100644 --- a/templates/expobase.html +++ b/templates/expobase.html @@ -3,7 +3,7 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>{% block title %}{% endblock %}</title> -<link rel="stylesheet" type="text/css" href="css/main2.css" /> +<link rel="stylesheet" type="text/css" href="/css/main2.css" /> {% block extrahead %}{% endblock %} </head> <body {% block bodyattrs %}{% endblock %}> diff --git a/templates/menu.html b/templates/menu.html index f74aed4..65b8544 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -7,6 +7,6 @@ <li><a href="/indxal.htm">Caves</a></li> <li><a href="/handbook/index.htm">Handbook</a></li> <li><a href="/pubs.htm">Reports</a></li> -{% if editable %}<li><a href="{% url editflatpage path %}">Edit</a></li>{% endif %} +{% if editable %}<li><a href="{% url editflatpage path %}" class="editlink"><strong>Edit this page</strong></a></li>{% endif %} </ul> {% endif %} From 9878cf890db44d693d8168dec167cde56006a8fb Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 12:58:02 +0100 Subject: [PATCH 12/13] ignorecase when finding html tags --- flatpages/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flatpages/views.py b/flatpages/views.py index 3357e64..05405de 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -56,17 +56,17 @@ 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) + m = re.search(r"<head>(.*)</head>.*<body[^>]*>(.*)</body>", html, re.DOTALL + re.IGNORECASE) if m: head, body = m.groups() else: return HttpResponse(html + "Page could not be split into header and body") - m = re.search(r"<title>(.*)</title>", head, re.DOTALL) + 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) + linksmatch = re.match('(.*)<ul id="links">', body, re.DOTALL + re.IGNORECASE) if linksmatch: body, = linksmatch.groups() if re.search(r"iso-8859-1", html): @@ -106,12 +106,12 @@ 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) + m = re.search(r"<head>(.*)</head>.*<body[^>]*>(.*)</body>", html, re.DOTALL + re.IGNORECASE) 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) + linksmatch = re.match('(.*)<ul id="links">', body, re.DOTALL + re.IGNORECASE) if linksmatch: body, = linksmatch.groups() body = unicode(body, "iso-8859-1") @@ -132,7 +132,7 @@ def editflatpage(request, path): return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST else: if filefound: - m = re.search(r"<title>(.*)</title>", head, re.DOTALL) + m = re.search(r"<title>(.*)</title>", head, re.DOTALL + re.IGNORECASE) if m: title, = m.groups() else: From 2145d1187ee401ba0b768a8383b06aef866bdbce Mon Sep 17 00:00:00 2001 From: Martin Green <martin.speleo@gmail.com> Date: Mon, 8 Aug 2011 13:11:57 +0100 Subject: [PATCH 13/13] Bug fix --- flatpages/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flatpages/views.py b/flatpages/views.py index 05405de..f46488e 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -110,10 +110,10 @@ def editflatpage(request, path): 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): - linksmatch = re.match('(.*)<ul id="links">', body, re.DOTALL + re.IGNORECASE) - if linksmatch: - body, = linksmatch.groups() body = unicode(body, "iso-8859-1") else: return HttpResponse("Page could not be split into header and body")