Skip to content

Commit

Permalink
fix: enable renaming of folders without markdown file
Browse files Browse the repository at this point in the history
THis came up while implementing #149.
  • Loading branch information
redimp committed Nov 16, 2024
1 parent 1945f2e commit bfd6615
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions otterwiki/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,15 @@ def history(self, rev_a=None, rev_b=None):
def rename(self, new_pagename, message, author):
if not has_permission("WRITE"):
abort(403)
# handle case that the page doesn't exists
self.exists_or_404()
# filename
new_filename = get_filename(new_pagename)
# check for attachments
files, directories = storage.list(self.attachment_directoryname)

# handle case that the page and no attachments exist
if not self.exists and (len(files) + len(directories)) == 0:
self.exists_or_404()

if (len(files) + len(directories)) > 0:
# rename attachment directory
new_attachment_directoryname = get_attachment_directoryname(
Expand All @@ -857,12 +860,15 @@ def rename(self, new_pagename, message, author):
new_attachment_directoryname,
author=author,
message=message,
no_commit=True,
# if self.exists, do not commit yet, commit will follow below, when the md file is renamed
# if not self.exists, do commit, since no md file will be renamed
no_commit=self.exists,
)
# rename page
storage.rename(
self.filename, new_filename, message=message, author=author
)
if self.exists:
storage.rename(
self.filename, new_filename, message=message, author=author
)

def handle_rename(self, new_pagename, message, author):
if not has_permission("WRITE"):
Expand Down

0 comments on commit bfd6615

Please sign in to comment.