Skip to content
Snippets Groups Projects
Commit d2615485 authored by Martin Burchell's avatar Martin Burchell
Browse files

Implemented delete item from form

parent 5ad09a8f
No related branches found
No related tags found
1 merge request!41Delete item from form
......@@ -482,3 +482,20 @@ def test_item_term_delete_transport_exception_logs_message(view, form):
assert_message(view.request,
messages.ERROR,
"Taxonomy with slug 'unknown-slug' does not exist.")
@pytest.mark.django_db
def test_item_can_be_deleted(view, form):
view.request.POST['next'] = '/'
response = view._delete_item()
assert response.url == '/'
assert_message(view.request,
messages.SUCCESS,
"Question %s successfully deleted." % view.item['id'])
with pytest.raises(TransportException) as excinfo:
transport.items.get(view.item['id'])
assert excinfo.value.message['status_code'] == 404
......@@ -82,11 +82,7 @@ class AddEditItemView(FormView):
_('No action performed')
)
if 'delete' in self.request.POST['action']:
return self._response(
self.request.POST['next'],
messages.ERROR,
_('Delete item not implemented')
)
return self._delete_item()
return super(AddEditItemView, self).post(request, *args, **kwargs)
......@@ -153,11 +149,11 @@ class AddEditItemView(FormView):
""" Form submit handler """
id = int(form.cleaned_data['id'])
item_description = self._get_item_description()
if self.item_type:
item_description = self.item_type['long_name']
taxonomy = ITEM_TYPE_CATEGORY.get(self.item_type['name'])
else:
item_description = 'Item'
taxonomy = None
# TODO: Combine terms into single transaction
......@@ -211,3 +207,24 @@ class AddEditItemView(FormView):
"""
messages.add_message(self.request, message_type, message)
return HttpResponseRedirect(url)
def _delete_item(self):
id = self.item['id']
transport.items.delete(id)
item_description = self._get_item_description()
return self._response(
self.request.POST['next'],
messages.SUCCESS,
_("%s %d successfully deleted.") % (
item_description,
id,
)
)
def _get_item_description(self):
if self.item_type:
return self.item_type['long_name']
return _('Item')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment