refactor to put Martins git stuff in utils

This commit is contained in:
Philip Sargent
2022-07-18 17:37:22 +03:00
parent ee9b808461
commit dd00ff69aa
3 changed files with 58 additions and 58 deletions

View File

@@ -21,7 +21,7 @@ from troggle.core.models.caves import Cave
import troggle.core.views.caves
import troggle.settings as settings
from troggle.lib import version_control
from troggle.core.utils import write_and_commit, WriteAndCommitError
from troggle.core.views.editor_helpers import HTMLarea
@@ -339,8 +339,8 @@ def editexpopage(request, path):
if request.method == 'POST': # If the form has been submitted...
pageform = ExpoPageForm(request.POST) # A form bound to the POST data
if pageform.is_valid():# Form valid therefore write file
print("### \n", str(pageform)[0:300])
print("### \n csrfmiddlewaretoken: ",request.POST['csrfmiddlewaretoken'])
#print("### \n", str(pageform)[0:300])
#print("### \n csrfmiddlewaretoken: ",request.POST['csrfmiddlewaretoken'])
if filefound:
headmatch = re.match(r"(.*)<title>.*</title>(.*)", head, re.DOTALL + re.IGNORECASE)
if headmatch:
@@ -358,12 +358,13 @@ def editexpopage(request, path):
body = body.replace("\r", "")
result = "%s<head%s>%s</head>%s<body%s>\n%s</body>%s" % (preheader, headerargs, head, postheader, bodyargs, body, postbody)
if result != html: # Check if content changed
if result != html: # Check if content changed at all
try:
change_message = pageform.cleaned_data["change_message"]
version_control.write_and_commit([(filepath, result, "utf-8")], f'{change_message} - online edit of {path}')
except version_control.WriteAndCommitError as e:
write_and_commit([(filepath, result, "utf-8")], f'{change_message} - online edit of {path}')
except WriteAndCommitError as e:
return render(request,'errors/generic.html', {'message': e.message})
return HttpResponseRedirect(reverse('expopage', args=[path])) # Redirect after POST
else:
@@ -385,4 +386,4 @@ class ExpoPageForm(forms.Form):
html = forms.CharField(widget=HTMLarea(attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"},
preview = True
))
change_message = forms.CharField(widget=forms.Textarea(attrs={"cols":80, "rows":3, 'placeholder': "Descibe the change made (for git)"}))
change_message = forms.CharField(widget=forms.Textarea(attrs={"cols":80, "rows":3, 'placeholder': "Describe the change made (for version control records)"}))