2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

git integration with Save this page

This commit is contained in:
Philip Sargent 2021-05-03 00:52:51 +01:00
parent 5a085ba7ba
commit 254b465755
3 changed files with 18 additions and 9 deletions

View File

@ -1,5 +1,6 @@
import os
import re
import subprocess
from pathlib import Path
from urllib.parse import urljoin, unquote as urlunquote
from urllib.request import urlopen
@ -276,7 +277,6 @@ def editexpopage(request, path):
# if re.search(r"iso-8859-1", html):
# body = str(body, "iso-8859-1")
else:
#return HttpResponse("Page could not be split into header and body")
return HttpResponse(default_head + html + '<h3>HTML Parsing failure:<br>Page could not be parsed into header and body:<br>failure detected in expowebpage in views.expo.py</h3> Please edit this <var>:expoweb:</var> page to be in the expected full HTML format .</body' )
except IOError:
print("### File not found ### ", filepath)
@ -304,9 +304,16 @@ def editexpopage(request, path):
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)
f = open(filepath, "w")
f.write(result)
f.close()
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)
return HttpResponseRedirect(reverse('expopage', args=[path])) # Redirect after POST
else:
if filefound:

View File

@ -195,10 +195,10 @@ def exportlogbook(request,year=None,extension=None):
return render(request,'controlPanel.html', {'expeditions':Expedition.objects.all(),'jobs_completed':[completed]})
def ajax_test(request):
post_text = request.POST['post_data']
return HttpResponse("{'response_text': '"+post_text+" recieved.'}",
content_type="application/json")
# def ajax_test(request):
# post_text = request.POST['post_data']
# return HttpResponse("{'response_text': '"+post_text+" recieved.'}",
# content_type="application/json")

View File

@ -24,6 +24,8 @@ print("* importing troggle/settings.py")
# default value, then gets overwritten by real secrets
SECRET_KEY = "not-the-real-secret-key-a#vaeozn0---^fj!355qki*vj2"
GIT = 'git' # command for running git
# Note that this builds upon the django system installed
# global settings in
# django/conf/global_settings.py which is automatically loaded first.
@ -112,7 +114,7 @@ PENDING = ["2007-06", "2009-02",
"2018-pf-01", "2018-pf-02"]
APPEND_SLASH = False # never relevant because we have urls that match unknown files and produce an 'edit this page' response
SMART_APPEND_SLASH = True
SMART_APPEND_SLASH = True #not eorking as middleware different after Dj2.0
LOGIN_REDIRECT_URL = '/'