diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2021-05-03 00:52:51 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2021-05-03 00:52:51 +0100 |
commit | 254b465755f7ebfc1650730ac2d51bb33543a85c (patch) | |
tree | bbff19795f4dd5a853c86ea74315e2cb39f466c4 | |
parent | 5a085ba7ba0303732c765d6d0a52e8d560ea9353 (diff) | |
download | troggle-254b465755f7ebfc1650730ac2d51bb33543a85c.tar.gz troggle-254b465755f7ebfc1650730ac2d51bb33543a85c.tar.bz2 troggle-254b465755f7ebfc1650730ac2d51bb33543a85c.zip |
git integration with Save this page
-rw-r--r-- | core/views/expo.py | 15 | ||||
-rw-r--r-- | core/views/other.py | 8 | ||||
-rw-r--r-- | settings.py | 4 |
3 files changed, 18 insertions, 9 deletions
diff --git a/core/views/expo.py b/core/views/expo.py index 4b7e378..9ff533b 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -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: diff --git a/core/views/other.py b/core/views/other.py index 3159a33..83d6113 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -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") diff --git a/settings.py b/settings.py index 5579a07..a89f6ee 100644 --- a/settings.py +++ b/settings.py @@ -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 = '/' |