def delete_part(user_slug, doc_slug, part_slug): """ Delete a part from a document. Must be logged in, and be the owner. To Do: - Form and confirmation step? - Delete parts including unused? """ require_authority_for_user(user_slug) # or 401 document = Document(data) document.set_host(domain_name(bottle.request)) if not document.load(user_slug, doc_slug): msg = "Document '{:s}/{:s}' not found." bottle.abort(HTTP_NOT_FOUND, msg.format(user_slug, doc_slug)) document.delete_part(part_slug) if len(document.parts) > 0: document.save() bottle.redirect('/read/{:s}/{:s}'.format(user_slug, doc_slug)) else: document.delete() bottle.redirect('/user/{:s}'.format(user_slug))
def test_delete_part(): """Confirms that the index is updated when a part is deleted.""" test_parts = { 'index': trim(""" Index - Part One - Part Two """), 'part-one': trim(""" Part One Text. """), 'part-two': trim(""" Part Two Text. """) } doc = Document(data) doc.set_parts('user-slug', 'doc-slug', test_parts) doc.delete_part('part-one') assert doc.parts == { 'index': trim(""" Index - Part Two """), 'part-two': trim(""" Part Two Text. """) }