Editing no longer changes files more than nesecary. Removed TinyMCE editing. /Sumbit/Submit

This commit is contained in:
expo 2012-08-06 12:19:48 +02:00
parent c221b75afc
commit 44eb3c0caf
8 changed files with 45 additions and 37 deletions

View File

@ -8,14 +8,14 @@ from datetime import date
from tinymce.widgets import TinyMCE from tinymce.widgets import TinyMCE
class CaveForm(ModelForm): class CaveForm(ModelForm):
underground_description = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) underground_description = forms.CharField(required = False, widget=forms.Textarea())
explorers = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) explorers = forms.CharField(required = False, widget=forms.Textarea())
equipment = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) equipment = forms.CharField(required = False, widget=forms.Textarea())
survey = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) survey = forms.CharField(required = False, widget=forms.Textarea())
kataster_status = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) kataster_status = forms.CharField(required = False, widget=forms.Textarea())
underground_centre_line = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) underground_centre_line = forms.CharField(required = False, widget=forms.Textarea())
notes = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) notes = forms.CharField(required = False, widget=forms.Textarea())
references = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10})) references = forms.CharField(required = False, widget=forms.Textarea())
class Meta: class Meta:
model = Cave model = Cave

View File

@ -57,9 +57,9 @@ def flatpage(request, 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 + re.IGNORECASE) m = re.search(r"(.*)<\s*head([^>]*)>(.*)<\s*/head\s*>(.*)<\s*body([^>]*)>(.*)<\s*/body\s*>(.*)", html, re.DOTALL + re.IGNORECASE)
if m: if m:
head, body = m.groups() preheader, headerattrs, head, postheader, bodyattrs, body, postbody = m.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) 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) filepath = os.path.normpath(settings.EXPOWEB + path)
o = open(filepath, "r") o = open(filepath, "r")
html = o.read() 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: if m:
filefound = True filefound = True
head, body = m.groups() preheader, headerargs, head, postheader, bodyargs, body, postbody = m.groups()
linksmatch = re.match('(.*)<ul\s+id="links">', body, re.DOTALL + re.IGNORECASE) linksmatch = re.match('(.*)(<ul\s+id="links">.*)', body, re.DOTALL + re.IGNORECASE)
if linksmatch: if linksmatch:
body, = linksmatch.groups() body, links = 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")
else: else:
@ -126,9 +126,22 @@ def editflatpage(request, path):
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') if filefound:
context = Context({'form': flatpageForm.cleaned_data}) headmatch = re.match(r"(.*)<title>.*</title>(.*)", head, re.DOTALL + re.IGNORECASE)
f.write(template.render(context)) 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() f.close()
return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST return HttpResponseRedirect(reverse('flatpage', args=[path])) # Redirect after POST
else: else:
@ -146,4 +159,4 @@ def editflatpage(request, path):
class FlatPageForm(forms.Form): class FlatPageForm(forms.Form):
title = forms.CharField(widget=forms.TextInput(attrs={'size':'60'})) 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())

View File

@ -51,11 +51,16 @@
{% if ent.entrance.bearings %} {% if ent.entrance.bearings %}
<dt>Bearings</dt><dd>{{ ent.entrance.bearings|safe }}</dd> <dt>Bearings</dt><dd>{{ ent.entrance.bearings|safe }}</dd>
{% endif %} {% endif %}
{% if ent.entrance.exact_station %}
{{ ent.entrance.tag_station|safe }} <dt>Exact Station</dt><dd>{{ ent.entrance.exact_station|safe }}</dd>
{{ ent.entrance.exact_station|safe }} {% endif %}
{{ ent.entrance.other_station|safe }} {% if ent.entrance.other_station %}
{{ ent.entrance.other_description|safe }} <dt>Other Station</dt><dd>{{ ent.entrance.other_station|safe }}
{% if ent.entrance.other_description %}
- {{ ent.entrance.other_description|safe }}
{% endif %}
</dd>
{% endif %}
</dl> </dl>
</li> </li>
{% endfor %} {% endfor %}

View File

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

View File

@ -13,7 +13,7 @@
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form }} {{ form }}
<p><input type="submit" value="Sumbit" /></p> <p><input type="submit" value="Submit" /></p>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -12,7 +12,7 @@
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
<table>{{ form }}{{caveAndEntranceFormSet}}</table> <table>{{ form }}{{caveAndEntranceFormSet}}</table>
{{ versionControlForm }} {{ versionControlForm }}
<p><input type="submit" value="Sumbit" /></p> <p><input type="submit" value="Submit" /></p>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -12,7 +12,7 @@
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
<table>{{ form }}</table> <table>{{ form }}</table>
{{ versionControlForm }} {{ versionControlForm }}
<p><input type="submit" value="Sumbit" /></p> <p><input type="submit" value="Submit" /></p>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -90,7 +90,7 @@
<label for="id_date">Content:</label> <label for="id_date">Content:</label>
{{ fileForm.html }} {{ fileForm.html }}
</div> </div>
<p><input type="submit" value="Sumbit Trip Report" /></p> <p><input type="submit" value="Submit Trip Report" /></p>
</form> </form>
{% endblock %} {% endblock %}