branch merge

This commit is contained in:
expo 2011-09-02 03:39:20 +02:00
commit 77dea07b40
12 changed files with 103 additions and 55 deletions

View File

@ -30,39 +30,39 @@ def caveindex(request):
def cave(request, cave_id='', offical_name=''): def cave(request, cave_id='', offical_name=''):
cave=getCave(cave_id) 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}) return render_with_context(request,'nonpublic.html', {'instance': cave, 'cavepage': True})
else: else:
return render_with_context(request,'cave.html', {'cave': cave, 'cavepage': True}) return render_with_context(request,'cave.html', {'cave': cave, 'cavepage': True})
def caveEntrance(request, slug): def caveEntrance(request, slug):
cave = Cave.objects.get(slug = 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}) return render_with_context(request,'nonpublic.html', {'instance': cave})
else: else:
return render_with_context(request,'cave_entrances.html', {'cave': cave}) return render_with_context(request,'cave_entrances.html', {'cave': cave})
def caveDescription(request, slug): def caveDescription(request, slug):
cave = Cave.objects.get(slug = 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}) return render_with_context(request,'nonpublic.html', {'instance': cave})
else: else:
return render_with_context(request,'cave_uground_description.html', {'cave': cave}) return render_with_context(request,'cave_uground_description.html', {'cave': cave})
def caveQMs(request, slug): def caveQMs(request, slug):
cave = Cave.objects.get(slug = 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}) return render_with_context(request,'nonpublic.html', {'instance': cave})
else: else:
return render_with_context(request,'cave_qms.html', {'cave': cave}) return render_with_context(request,'cave_qms.html', {'cave': cave})
def caveLogbook(request, slug): def caveLogbook(request, slug):
cave = Cave.objects.get(slug = 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}) return render_with_context(request,'nonpublic.html', {'instance': cave})
else: else:
return render_with_context(request,'cave_logbook.html', {'cave': cave}) return render_with_context(request,'cave_logbook.html', {'cave': cave})
def caveSlug(request, slug): def caveSlug(request, slug):
cave = Cave.objects.get(slug = 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}) return render_with_context(request,'nonpublic.html', {'instance': cave})
else: else:
return render_with_context(request,'cave.html', {'cave': cave}) return render_with_context(request,'cave.html', {'cave': cave})

View File

@ -5,7 +5,7 @@ import troggle.settings as settings
import django.db.models import django.db.models
from troggle.parsers.logbooks import LoadLogbookForExpedition from troggle.parsers.logbooks import LoadLogbookForExpedition
from troggle.parsers.people import GetPersonExpeditionNameLookup 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.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.template import Context, loader from django.template import Context, loader

View File

@ -15,7 +15,6 @@ import os
import re import re
def flatpage(request, path): def flatpage(request, path):
print "gggggg", path
try: try:
r = Redirect.objects.get(originalURL = path) r = Redirect.objects.get(originalURL = path)
return HttpResponseRedirect(r.newURL) # Redirect after POST 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(): 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) return HttpResponseRedirect(reverse("auth_login") + '?next=%s' % request.path)
if path.endswith("/") or path == "": if path.endswith("/") or path == "":
@ -45,29 +45,34 @@ def flatpage(request, path):
except IOError: except IOError:
try: try:
o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb") o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb")
path = path + "index.html" path = path + "index.htm"
except IOError: except IOError:
raise Http404 return render_with_context(request, 'pagenotfound.html', {'path': path})
else: else:
try: try:
o = open(os.path.normpath(settings.EXPOWEB + path), "rb") o = open(os.path.normpath(settings.EXPOWEB + path), "rb")
except IOError: except IOError:
raise Http404 return render_with_context(request, 'pagenotfound.html', {'path': path})
if path.endswith(".htm") or path.endswith(".html"): if path.endswith(".htm") or path.endswith(".html"):
html = o.read() 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)
mwithid = re.search(r'<head>(.*)</head>.*<body id="([^"]*)">(.*)</body>', html, re.DOTALL)
if m: if m:
head, body = m.groups() head, body = m.groups()
bodyid = None
elif mwithid:
head, bodyid, body = mwithid.groups()
else: else:
return HttpResponse(html + "Page could not be split into header and body") 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): if re.search(r"iso-8859-1", html):
body = unicode(body, "iso-8859-1") 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: else:
return HttpResponse(o.read(), mimetype=getmimetype(path)) return HttpResponse(o.read(), mimetype=getmimetype(path))
@ -100,28 +105,44 @@ def editflatpage(request, path):
try: try:
filepath = os.path.normpath(settings.EXPOWEB + path) filepath = os.path.normpath(settings.EXPOWEB + path)
o = open(filepath, "r") 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: except IOError:
raise Http404 filefound = False
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")
if request.method == 'POST': # If the form has been submitted... if request.method == 'POST': # If the form has been submitted...
flatpageForm = FlatPageForm(request.POST) # A form bound to the POST data flatpageForm = FlatPageForm(request.POST) # A form bound to the POST data
if flatpageForm.is_valid():# Form valid therefore write file if flatpageForm.is_valid():# Form valid therefore write file
f = open(filepath, "w") f = open(filepath, "w")
template = loader.get_template('dataformat/flatfile.html') 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.write(template.render(context))
f.close() f.close()
return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST
else: 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, }) return render_with_context(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, })
class FlatPageForm(forms.Form): 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}))

View File

@ -1,9 +1,10 @@
import sys
# link localsettings to this file for use on expo computer in austria # link localsettings to this file for use on expo computer in austria
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'troggle' # Or path to database file if using sqlite3. DATABASE_NAME = 'troggle' # Or path to database file if using sqlite3.
DATABASE_USER = 'troggler3' # Not used with sqlite3. DATABASE_USER = 'expo' # Not used with sqlite3.
DATABASE_PASSWORD = 'ggg' # Not used with sqlite3. DATABASE_PASSWORD = 'gosser' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. 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. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
@ -48,4 +49,4 @@ TEMPLATE_DIRS = (
# Don't forget to use absolute paths, not relative paths. # 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'

View File

@ -16,11 +16,6 @@
</head> </head>
<body> <body>
{% block content %}{% endblock %} {% block content %}{% endblock %}
{% block menu %} {% include "menu.html" %}
<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 %}
</body> </body>
</html> </html>

View File

@ -10,7 +10,7 @@
<h3>Notable caves</h3> <h3>Notable caves</h3>
<ul> <ul>
{% for cave in notablecaves %} {% 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 %} {% endfor %}
</ul> </ul>
@ -19,7 +19,7 @@
<ul class="searchable"> <ul class="searchable">
{% for cave in caves1623 %} {% 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 %} {% endfor %}
</ul> </ul>
@ -29,7 +29,7 @@
<ul class="searchable"> <ul class="searchable">
{% for cave in caves1626 %} {% 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 %} {% endfor %}
</ul> </ul>

View File

@ -1,7 +1,7 @@
{% autoescape off %} {% autoescape off %}
<html> <html>
<head> <head>
{{ head }} <title>{{ form.title }}</title>
</head> </head>
<body> <body>
{{ form.html }} {{ form.html }}

View File

@ -1,12 +1,14 @@
{% extends "base.html" %} {% extends "expobase.html" %}
{% block title %}Edit {{ path }}{% endblock %} {% block title %}Edit {{ path }}{% endblock %}
{% block head %} {% block extrahead %}
{% load csrffaker %} {% load csrffaker %}
<script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script> <script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script>
{% endblock %} {% endblock %}
{% block content %} {% block body %}
<h1>Edit {{ path }}</h1>
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{form}} {{form.as_p}}
<p><input type="submit" value="Submit" /></p> <p><input type="submit" value="Submit" /></p>
</form> </form>
{% include "menu.html" %}
{% endblock %} {% endblock %}

13
templates/expobase.html Normal file
View File

@ -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 %}

View File

@ -1,10 +1,7 @@
<html> {% extends "expobase.html" %}
<head> {% block title %}{{ title }}{% endblock %}
{{ head|safe }} {% block bodyattrs %}{% if homepage %} id="homepage"{% endif %}{% endblock %}
</head> {% block body %}
<body{% if bodyid %} id="{{ bodyid }}"{% endif %}>
{{ body|safe }} {{ body|safe }}
{% if editable %}<a href="{% url editflatpage path %}">Edit</a>{% endif %} {% if homepage %}{% if editable %}<a href="{% url editflatpage path %}">Edit</a>{% endif %}{%else %}{% include "menu.html" %}{% endif %}
<a href="/troggle">Troggle</a> {% endblock %}
</body>
</html>

12
templates/menu.html Normal file
View File

@ -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 %}" class="editlink"><strong>Edit this page</strong></a></li>{% endif %}
</ul>
{% endif %}

View 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 %}