Skip to content

Commit bfd6615

Browse files
committed
fix: enable renaming of folders without markdown file
THis came up while implementing #149.
1 parent 1945f2e commit bfd6615

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

otterwiki/wiki.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -840,12 +840,15 @@ def history(self, rev_a=None, rev_b=None):
840840
def rename(self, new_pagename, message, author):
841841
if not has_permission("WRITE"):
842842
abort(403)
843-
# handle case that the page doesn't exists
844-
self.exists_or_404()
845843
# filename
846844
new_filename = get_filename(new_pagename)
847845
# check for attachments
848846
files, directories = storage.list(self.attachment_directoryname)
847+
848+
# handle case that the page and no attachments exist
849+
if not self.exists and (len(files) + len(directories)) == 0:
850+
self.exists_or_404()
851+
849852
if (len(files) + len(directories)) > 0:
850853
# rename attachment directory
851854
new_attachment_directoryname = get_attachment_directoryname(
@@ -857,12 +860,15 @@ def rename(self, new_pagename, message, author):
857860
new_attachment_directoryname,
858861
author=author,
859862
message=message,
860-
no_commit=True,
863+
# if self.exists, do not commit yet, commit will follow below, when the md file is renamed
864+
# if not self.exists, do commit, since no md file will be renamed
865+
no_commit=self.exists,
861866
)
862867
# rename page
863-
storage.rename(
864-
self.filename, new_filename, message=message, author=author
865-
)
868+
if self.exists:
869+
storage.rename(
870+
self.filename, new_filename, message=message, author=author
871+
)
866872

867873
def handle_rename(self, new_pagename, message, author):
868874
if not has_permission("WRITE"):

0 commit comments

Comments
 (0)