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

@ -1,5 +1,6 @@
import os import os
import re import re
import subprocess
from pathlib import Path from pathlib import Path
from urllib.parse import urljoin, unquote as urlunquote from urllib.parse import urljoin, unquote as urlunquote
from urllib.request import urlopen from urllib.request import urlopen
@ -276,7 +277,6 @@ def editexpopage(request, path):
# if re.search(r"iso-8859-1", html): # if re.search(r"iso-8859-1", html):
# body = str(body, "iso-8859-1") # body = str(body, "iso-8859-1")
else: 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' ) 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: except IOError:
print("### File not found ### ", filepath) print("### File not found ### ", filepath)
@ -304,9 +304,16 @@ def editexpopage(request, path):
body = pageform.cleaned_data["html"] body = pageform.cleaned_data["html"]
body = body.replace("\r", "") body = body.replace("\r", "")
result = "%s<head%s>%s</head>%s<body%s>\n%s</body>%s" % (preheader, headerargs, head, postheader, bodyargs, body, postbody) 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) cwd = filepath.parent
f.close() 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 return HttpResponseRedirect(reverse('expopage', args=[path])) # Redirect after POST
else: else:
if filefound: if filefound:

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

@ -24,6 +24,8 @@ print("* importing troggle/settings.py")
# default value, then gets overwritten by real secrets # default value, then gets overwritten by real secrets
SECRET_KEY = "not-the-real-secret-key-a#vaeozn0---^fj!355qki*vj2" 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 # Note that this builds upon the django system installed
# global settings in # global settings in
# django/conf/global_settings.py which is automatically loaded first. # 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"] "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 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 = '/' LOGIN_REDIRECT_URL = '/'