summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-12-07 23:46:55 +0000
committerPhilip Sargent <philip.sargent@klebos.com>2021-12-07 23:46:55 +0000
commit02e475642a813fad3cd7863180a16c272138ccc5 (patch)
tree70e0ee64ccf57129ca086d4958b2af4231407963
parent406b4590a9470aa0a965b46bbe06730d3a278f9b (diff)
downloadtroggle-02e475642a813fad3cd7863180a16c272138ccc5.tar.gz
troggle-02e475642a813fad3cd7863180a16c272138ccc5.tar.bz2
troggle-02e475642a813fad3cd7863180a16c272138ccc5.zip
fix final \n on edited files
-rw-r--r--core/views/expo.py21
-rw-r--r--core/views/survex.py1
2 files changed, 15 insertions, 7 deletions
diff --git a/core/views/expo.py b/core/views/expo.py
index 57d1a7d..0bff259 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -300,7 +300,7 @@ def editexpopage(request, path):
headerargs = ""
postheader = ""
bodyargs = ""
- postbody = "</html>"
+ postbody = "</html>\n"
body = pageform.cleaned_data["html"]
body = body.replace("\r", "")
result = "%s<head%s>%s</head>%s<body%s>\n%s</body>%s" % (preheader, headerargs, head, postheader, bodyargs, body, postbody)
@@ -308,12 +308,19 @@ def editexpopage(request, path):
cwd = filepath.parent
filename = filepath.name
git = settings.GIT
- with open(filepath, "w") as f:
- f.write(result)
- #print(f'WROTE {cwd}---{filename} ')
- subprocess.call([git, "add", filename], cwd=cwd)
- subprocess.call([git, "commit", "-m", 'Edit this page'], cwd=cwd)
-
+ try:
+ with open(filepath, "w") as f:
+ f.write(result)
+ #print(f'WROTE {cwd}---{filename} ')
+ subprocess.call([git, "add", filename], cwd=cwd)
+ subprocess.call([git, "commit", "-m", 'Edit this page'], cwd=cwd)
+ except PermissionError:
+ message = f'CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filename}. Ask a nerd to fix this.'
+ return render(request,'errors/generic.html', {'message': message})
+ except:
+ message = f'CANNOT git on server for this file {filename}. Edits not saved.\nAsk a nerd to fix this.'
+ return render(request,'errors/generic.html', {'message': message})
+
return HttpResponseRedirect(reverse('expopage', args=[path])) # Redirect after POST
else:
if filefound:
diff --git a/core/views/survex.py b/core/views/survex.py
index a3ff5bd..332ad75 100644
--- a/core/views/survex.py
+++ b/core/views/survex.py
@@ -152,6 +152,7 @@ class SvxForm(forms.Form):
# javascript seems to insert CRLF on WSL1 whatever you say. So fix that:
res = fout.write(rcode.replace("\r",""))
+ res = fout.write("\n")
fout.close()
return "SAVED ."