From cb81a066dbbc61bd55adac3180533eaf8f073064 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 3 Jul 2024 11:48:38 +0300 Subject: [PATCH] initial text file editing stuff --- core/views/expo.py | 11 ++++++++- core/views/uploads.py | 38 +++++++++++++++++++++++++++++- parsers/caves.py | 2 +- templates/textfileform.html | 46 +++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 templates/textfileform.html 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 = """ @@ -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): + "

UTF-8 Parsing Failure:
Default file encoding on this Troggle installation is not UTF-8:
failure detected in expowebpage in views.expo.py

Please Please reconfigure Debian/Apache/Django to fix this, i.e. contact Wookey. " + default_head + f"

File not found '{filepath}'

failure detected in expowebpage() in views.expo.py

" + 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 %} + +

Editing text file (not fully working yet)

+ +
+File: {{path}}
+Full path on server: {{filepath}} + +
+ {% csrf_token %} +
+ +
+ [Edit the text by just typing in the box.] + + + +
+
+ + +
+ +
+
+ + + + + +{% endblock %} \ No newline at end of file