Skip to content

Commit

Permalink
feature: allow renaming of folders, allow removing of pages without t…
Browse files Browse the repository at this point in the history
…heir attachments

- Renaming of folders was brought up in #149.
- Deleting pages without deleting their subpages (subpages are
  technically just attachments) was brought up in #150.
  • Loading branch information
redimp committed Nov 16, 2024
1 parent bfd6615 commit e7d92be
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
18 changes: 11 additions & 7 deletions otterwiki/templates/delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
<form action="{{url_for("delete", path=pagepath )}}" method="POST" class="form-inline">
<div class="form-group">
<label for="message" class="w-150">Commit message</label>
<input type="text" class="form-control" name="message" id="message" placeholder="Deleted {{pagename}}." value="{{message}}">
<input type="text" class="form-control" name="message" id="message" placeholder="Deleted {{pagename}}." value="{{message}}">
</div>
<div class="form-group">
<div class="form-text">
Reverting a delete will restore the file.
</div>
<div class="custom-checkbox">
<input type="checkbox" id="delete-attachments" name="recursive" value="recursive" checked>
<label for="delete-attachments">Recursive remove all attached files and folders</label>
</div>
<div class="form-group mt-10">
<input class="btn btn-danger" type="submit" value="Delete">
<a href="{{ url_for("view", path=pagepath) }}" class="btn" role="button">Cancel</a>
</div>
<div class="form-text">
<em>Note: Reverting a delete will restore the deleted file(s).</em>
</div>
<input class="btn btn-danger" type="submit" value="Delete">
<a href="{{ url_for("view", path=pagepath) }}" class="btn" role="button">Cancel</a>
</form>
{% endblock %}
15 changes: 1 addition & 14 deletions otterwiki/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,7 @@
View Source
</a>
{% endif %}
{% if has_permission('WRITE') %}
<a href="{{ url_for('rename', path=pagepath) }}" class="dropdown-item-with-icon">
<span class="dropdown-icon">
<i class="far fa-edit"></i>
</span>
Rename
</a>
<a href="{{ url_for('delete', path=pagepath) }}" class="dropdown-item-with-icon">
<span class="dropdown-icon">
<i class="far fa-trash-alt"></i>
</span>
Delete
</a>
{% endif %}
{% include 'snippets/navbardropdown_rename_remove.html' %}
<div class="dropdown-divider mt-5 mb-5"></div>
{{ super() }}
{% endblock %}
Expand Down
5 changes: 5 additions & 0 deletions otterwiki/templates/pageindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
{% include 'snippets/menu.html' %}
{% include 'snippets/menutree.html' %}
{% endblock %}
{% block navbardropdown %}
{% include 'snippets/navbardropdown_rename_remove.html' %}
<div class="dropdown-divider mt-5 mb-5"></div>
{{ super() }}
{% endblock %}
{% block content %}
<h2 class="pr-20 d-inline-block">{{ title }}</h2>
<div class="d-inline-block custom-switch font-size-12 mb-10">
Expand Down
15 changes: 15 additions & 0 deletions otterwiki/templates/snippets/navbardropdown_rename_remove.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{#- vim: set et ts=8 sts=4 sw=4 ai: -#}
{% if has_permission('WRITE') %}
<a href="{{ url_for('rename', path=pagepath) }}" class="dropdown-item-with-icon">
<span class="dropdown-icon">
<i class="far fa-edit"></i>
</span>
Rename
</a>
<a href="{{ url_for('delete', path=pagepath) }}" class="dropdown-item-with-icon">
<span class="dropdown-icon">
<i class="far fa-trash-alt"></i>
</span>
Delete
</a>
{% endif %}
1 change: 1 addition & 0 deletions otterwiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def delete(path):
return p.delete(
message=request.form.get("message"),
author=otterwiki.auth.get_author(),
recursive=request.form.get("recursive", False) == "recursive",
)
return p.delete_form()

Expand Down
12 changes: 10 additions & 2 deletions otterwiki/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,21 @@ def rename_form(self, new_pagename=None, message=None):
),
)

def delete(self, message, author):
def delete(self, message, author, recursive=True):
if not has_permission("WRITE"):
abort(403)
if empty(message):
message = "{} deleted.".format(self.pagename)
files = []
if self.exists:
files.append(self.filename)
if recursive:
files.append(self.attachment_directoryname)
if len(files) < 1:
toast("Nothing to delete.")
return redirect(url_for("view", path=self.pagepath))
storage.delete(
[self.filename, self.attachment_directoryname],
files,
message=message,
author=author,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_otterwiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def test_nested_files(test_client):
# delete the image
rv = test_client.post(
"/{}/delete".format(pagename),
data={"message": "deleted ..."},
data={"message": "deleted ...", "recursive": "recursive"},
follow_redirects=True,
)
assert rv.status_code == 200
Expand Down

0 comments on commit e7d92be

Please sign in to comment.