diff --git a/sourcing/templates/view.html b/sourcing/templates/view.html
index e47dd8e..a18e9d5 100644
--- a/sourcing/templates/view.html
+++ b/sourcing/templates/view.html
@@ -4,6 +4,9 @@
{% block content %}
+{% set subject_count = doc.subjects.count() %}
+{% set can_delete = subject_count == 0 %}
+
{% if current_user.is_authenticated and doc.user == current_user %}
{% set title = doc.title_from_link() %}
@@ -32,6 +35,31 @@
+
+{% if can_delete %}
+
+{% endif %}
+
{% endif %}
{% if doc.type != 'sourcedoc' %}
@@ -64,6 +92,9 @@
{{ self.title() }}
{% if current_user.is_authenticated and doc.user == current_user %}
+ {% if can_delete %}
+
+ {% endif %}
{% endif %}
{% if version %}
@@ -132,7 +163,6 @@
References
- {% set subject_count = doc.subjects.count() %}
{% if subject_count %}
There are {{ subject_count }} documents that refer to this {{ doc.type }}.
diff --git a/sourcing/view.py b/sourcing/view.py
index ebfe9df..eb64a0b 100644
--- a/sourcing/view.py
+++ b/sourcing/view.py
@@ -250,6 +250,14 @@ def set_title(username, hashid):
flash('title change saved' if has_title else 'title added')
return redirect(item.url)
+@bp.route('///delete', methods=['POST'])
+def delete_item(username, hashid):
+ item = get_item(username, hashid)
+ session.delete(item)
+ session.commit()
+ flash('item deleted')
+ return redirect_to_home()
+
@bp.route('//')
def view_item(username, hashid, raw=False):
if ',' in hashid: