diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2024-07-03 11:48:38 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2024-07-03 11:48:38 +0300 |
commit | cb81a066dbbc61bd55adac3180533eaf8f073064 (patch) | |
tree | 6d6d493765723bfceac160c4815804f9da1fe336 | |
parent | 704ff8335dc78b497586e773c4ed7a596672b920 (diff) | |
download | troggle-cb81a066dbbc61bd55adac3180533eaf8f073064.tar.gz troggle-cb81a066dbbc61bd55adac3180533eaf8f073064.tar.bz2 troggle-cb81a066dbbc61bd55adac3180533eaf8f073064.zip |
initial text file editing stuff
-rw-r--r-- | core/views/expo.py | 11 | ||||
-rw-r--r-- | core/views/uploads.py | 38 | ||||
-rw-r--r-- | parsers/caves.py | 2 | ||||
-rw-r--r-- | templates/textfileform.html | 46 |
4 files changed, 94 insertions, 3 deletions
diff --git a/core/views/expo.py b/core/views/expo.py index fadc6ed..4902502 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -16,12 +16,15 @@ import troggle.settings as settings from troggle.core.models.caves import Cave from troggle.core.utils import WriteAndCommitError, write_and_commit from troggle.core.views.editor_helpers import HTMLarea +from troggle.core.views.uploads import edittxtpage from .auth import login_required_if_public """Formerly a separate package called 'flatpages' written by Martin Green 2011. This was NOT django.contrib.flatpages which stores HTML in the database, so the name was changed to expopages. Then it was incorporated into troggle directly, rather than being an unnecessary external package. + +This is a succession of hacks and needs to be redisgned and refactored. """ default_head = """<head> @@ -356,7 +359,7 @@ def getmimetype(path): return "application/zip" return "" - + @login_required_if_public @ensure_csrf_cookie def editexpopage(request, path): @@ -377,6 +380,12 @@ def editexpopage(request, path): + "<h3>UTF-8 Parsing Failure:<br>Default file encoding on this Troggle installation is not UTF-8:<br>failure detected in expowebpage in views.expo.py</h3> Please Please reconfigure Debian/Apache/Django to fix this, i.e. contact Wookey. </body" ) + # detect if this is a text file for editing + filepath = Path(settings.EXPOWEB) / path + if filepath.suffix == ".txt": + print("Editing TEXT file", filepath) + return edittxtpage(request, path, filepath) + try: filepath = Path(settings.EXPOWEB) / path o = open(filepath, "r", encoding="utf8") diff --git a/core/views/uploads.py b/core/views/uploads.py index 7265fff..2ee01f3 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -146,9 +146,45 @@ class TextForm(forms.Form): # not a model-form, just a form-form class ExpofileRenameForm(forms.Form): # not a model-form, just a form-form renameto = forms.CharField(strip=True, required=False) +class ExpotextfileForm(forms.Form): # not a model-form, just a form-form + text = forms.CharField(strip=True, required=False) + class LogbookEditForm(forms.Form): # not a model-form, just a form-form author = forms.CharField(strip=True, required=False) - + +def edittxtpage(request, path, filepath): + """Editing a .txt file on expoweb/ + """ + def simple_get(): + form = ExpotextfileForm() + return render( + request, + "textfileform.html", + { + "form": form, + "path": path, + "filepath": filepath, + "text": text, + }, + ) + + if not filepath.is_file(): + print(f"Not a file: {filepath}") + errpage = f"<html>" + default_head + f"<h3>File not found '{filepath}'<br><br>failure detected in expowebpage() in views.expo.py</h3> </body>" + return HttpResponse(errpage) + try: + with open(filepath) as f: + text = f.read() + except IOError: + print("### File reading failue, but it exists.. ### ", filepath) + filefound = False + + if request.method == "GET": + return simple_get() + + elif request.method == "POST": + pass + @login_required_if_public def logbookedit(request, year=None, slug=None): """Edit a logbook entry diff --git a/parsers/caves.py b/parsers/caves.py index efaa0e9..4d35a51 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -855,7 +855,7 @@ def read_cave(filename, mvf=None, cave=None): # we have already checked for uniqueness but the Cave object may/should be already created by the Entrance parsing manual_edit = False - # The Cave object might be known by another (alias) name + # The Cave object should already have been created when reading the entrance_data file caves = Cave.objects.filter(filename=filename) if len(caves) ==1: cave = caves[0] diff --git a/templates/textfileform.html b/templates/textfileform.html new file mode 100644 index 0000000..27fa0d3 --- /dev/null +++ b/templates/textfileform.html @@ -0,0 +1,46 @@ +{% extends "base.html" %} + +{% block title %}Online text file editor{% endblock %} + +{% block content %} + +<h2>Editing text file (not fully working yet)</h2> + <style> + input, textarea, pre {font-family: monospace; font-weight: bold; text-align:left; font-size: 100%; padding: 0.5em; } + textarea {text-align:left } + pre {text-align:left; font-size: 110% } + </style> +<div style = "max-width:95%; margin-left:4%; font-family: monospace; font-weight: bold; font-size: 110%; text-align: left; " > +File: {{path}} <br> +Full path on server: {{filepath}} + + <form method ='post' > + {% csrf_token %} + <br /> + <textarea {% if not user.username %} disabled{% endif %} + rows="{% if textrows%}{{textrows}}{% else %}20{% endif %}" cols="100" + label = "" name = "text" + required />{% if text %}{{text}}{% else %}We had a lot of fun...{% endif %} + </textarea> + <br> + [Edit the text by just typing in the box.] + + + <button class="fancybutton2" style="padding: 0.5em 25px; margin-left: 110px" name="Save" type = "submit" +title="Saves the file in UTF-8 characterset" value = "Save" > + Save the file + </button> + </form> + <br /> + + +</div> + +<br /> +<hr /> + + + + + +{% endblock %}
\ No newline at end of file |