summaryrefslogtreecommitdiffstats
path: root/core/views/survex.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/views/survex.py')
-rw-r--r--core/views/survex.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/core/views/survex.py b/core/views/survex.py
index 7f62f58..21d558e 100644
--- a/core/views/survex.py
+++ b/core/views/survex.py
@@ -132,7 +132,9 @@ class SvxForm(forms.Form):
self.survexfile = False
return survextemplatefile
refs = SurvexFile.objects.filter(path=self.data["filename"])
- if len(refs)==1:
+ if len(refs)==0: # new survex file, not created in db yet
+ self.survexfile = False
+ elif len(refs)==1:
self.survexfile = SurvexFile.objects.get(path=self.data["filename"])
else:
self.survexfile = refs[0]
@@ -160,9 +162,11 @@ class SvxForm(forms.Form):
def SaveCode(self, rcode):
fname = survexdatasetpath / (self.data["filename"] + ".svx")
- if not os.path.isfile(fname):
+ if not fname.is_file():
if re.search(r"\[|\]", rcode):
- return "Error: remove all []s from the text. They are only template guidance."
+ errmsg = "Error: remove all []s from the text.\nEverything inside [] are only template guidance.\n\n"
+ errmsg += "All [] must be edited out and replaced with real data before you can save this file.\n"
+ return errmsg
mbeginend = re.search(r"(?s)\*begin\s+(\w+).*?\*end\s+(\w+)", rcode)
if not mbeginend:
return "Error: no begin/end block here"
@@ -194,7 +198,7 @@ class SvxForm(forms.Form):
comment = f"Online survex edit: {self.data['filename']}.svx on dev machine '{socket.gethostname()}' "
only_commit(fname, comment)
- return "SAVED and committed to git"
+ return "SAVED and committed to git (if there were differences)"
def Process(self):
print(">>>>....\n....Processing\n")
@@ -241,6 +245,10 @@ def svx(request, survex_file):
editing) with buttons which allow SAVE, check for DIFFerences from saved, and RUN (which runs the
cavern executable and displays the output below the main textarea).
Requires CSRF to be set up correctly, and requires permission to write to the filesystem.
+
+ Originally the non-existence of difflist was used as a marker to say that the file had been saved
+ and that thuis there were no differences. This is inadequate, as a new file which has not been saved
+ also has no difflist.
"""
warning = False
@@ -286,30 +294,39 @@ def svx(request, survex_file):
form.data["code"] = rcode
# process(survex_file)
+ svxfile = form.survexfile # only valid once form.GetDiscCode() called
+
if "code" not in form.data:
form.data["code"] = form.GetDiscCode()
if form.template:
warning = True
if not difflist:
- difflist.append("No differences - file was saved")
+ if svxfile:
+ difflist.append("No differences.")
+ else:
+ difflist.append("No differences from initial template.")
if message:
difflist.insert(0, message)
# print [ form.data['code'] ]
svxincludes = re.findall(r"(?i)\*include\s+(\S+)", form.data["code"] or "")
- svxfile = form.survexfile # only valid once form.GetDiscCode() called
- print(svxfile)
- try:
- svxblocksall = svxfile.survexblock_set.all()
- except AttributeError: # some survexfiles just *include files and have no blocks themselves
- svxblocksall = []
# collect all the survex blocks which actually have a valid date
if svxfile:
- svxblocks = svxfile.survexblock_set.filter(date__isnull=False).order_by('date')
+ try:
+ svxblocks = svxfile.survexblock_set.filter(date__isnull=False).order_by('date')
+ except:
+ svxblocks = []
+ try:
+ svxblocksall = svxfile.survexblock_set.all()
+ except AttributeError: # some survexfiles just *include files and have no blocks themselves
+ svxblocksall = []
else:
svxblocks = []
+ svxblocksall = []
+ if not difflist:
+ difflist = ["Survex file does not exist yet"]
events = events_on_dates(svxblocks)