2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-15 12:37:10 +00:00

fix final \n on edited files

This commit is contained in:
Philip Sargent
2021-12-07 23:46:55 +00:00
parent 406b4590a9
commit 02e475642a
2 changed files with 15 additions and 7 deletions

View File

@@ -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: