summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/utils.py14
-rw-r--r--core/views/expo.py13
2 files changed, 18 insertions, 9 deletions
diff --git a/core/utils.py b/core/utils.py
index 50746eb..6086b60 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -233,19 +233,19 @@ nothing to commit, working tree clean
f"CANNOT git COMMIT on server for this file {filename}. Subprocess error. Edits not saved.\nAsk a nerd to fix this."
)
-def g_string(author_string):
+def git_string(author_string):
# Regular expression for a git-compatible author string
# valid example "John Doe <john.doe@example.com>"
- author_regex = re.compile(r'^[a-zA-Z][\w\s\.\-]* <[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}>$')
+ author_regex = re.compile(r'^[a-zA-Z][\w\s\_\.\-]* <[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-_]+\.[a-zA-Z]{2,}>$')
if author_regex.match(author_string):
- print(f"Valid git-compatible author string: {author_string}")
+ print(f"Valid git-compatible author string: '{author_string}'")
return author_string
else:
editor = author_string.replace("@","_at_")
- editor = re.sub('[^0-9a-zA-Z_]+', '*', editor)
+ editor = re.sub('[^0-9a-zA-Z_\.]+', '*', editor)
editor += f" <{editor}@potatohut.expo>"
print(f"Not git-compatible author string, replacing as '{editor}'")
return editor
@@ -258,7 +258,7 @@ def write_and_commit(files, message, editor=None):
git = settings.GIT
commands = []
if editor:
- editor = g_string(editor)
+ editor = git_string(editor)
else:
# cannot happen as form verification has this as an obligatory field
editor = "Automatic <automaton@potatohut.expo>"
@@ -373,6 +373,10 @@ class WriteAndCommitError(Exception):
def writetrogglefile(filepath, filecontent, commit_msg=None):
"""
REPLACE with call to write_and_commit + any necessary setup
+ used only by cave editor in
+ core/models/caves.py
+ and by
+ make_new_expo_dir(year)
Commit the new saved file to git
Callers to cave.writeDataFile() or entrance.writeDataFile() should handle the exception PermissionsError explicitly
diff --git a/core/views/expo.py b/core/views/expo.py
index a151a4d..5fa3b33 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -451,11 +451,14 @@ def editexpopage(request, path):
print("### File not found ### ", filepath)
filefound = False
+ editor_name = request.COOKIES.get('editor_id', '') # if no cookie, then get empty string
+
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'])
+ if not editor_name:
if filefound:
headmatch = re.match(r"(.*)<title>.*</title>(.*)", head, re.DOTALL + re.IGNORECASE)
if headmatch:
@@ -476,7 +479,7 @@ def editexpopage(request, path):
bodyargs = ""
postbody = "</html>\n"
body = pageform.cleaned_data["html"]
- body = body.replace("\r", "\n")
+ body = body.replace("\r", "")
result = f"{preheader}<head{headerargs}>{head}</head>{postheader}<body{bodyargs}>\n{body}</body>{postbody}"
if not filefound or result != html: # Check if content changed at all
@@ -495,9 +498,11 @@ def editexpopage(request, path):
(title,) = m.groups()
else:
title = ""
- pageform = ExpoPageForm(initial={"html": body, "title": title})
+ pageform = ExpoPageForm(initial={"who_are_you":editor_name, "html": body, "title": title})
else:
- pageform = ExpoPageForm()
+ pageform = ExpoPageForm(initial={"who_are_you":editor_name})
+
+
return render(
request,
"editexpopage.html",
@@ -528,7 +533,7 @@ class ExpoPageForm(forms.Form):
)
who_are_you = forms.CharField(
widget=forms.Textarea(
- attrs={"cols": 90, "rows": 1, "placeholder": "You have edited this page, who are you ? e.g. 'Animal <mta@loveshack.expo>'",
+ attrs={"cols": 90, "rows": 1, "placeholder": "You have edited this page, who are you ? e.g. 'Animal <mta@gasthof.expo>'",
"style": "vertical-align: text-top;"}
),
label = "Editor"