Add delete action support
Partially implements blueprint mistral-dashboard-crud-operations Change-Id: Iceda724d771df567c82180e44200fe60c4e88153
This commit is contained in:
parent
386f8342a6
commit
9dc6b9ea7f
|
@ -13,10 +13,13 @@
|
|||
# limitations under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
|
||||
from horizon import tables
|
||||
from horizon.utils import filters
|
||||
|
||||
from mistraldashboard import api
|
||||
|
||||
|
||||
class CreateAction(tables.LinkAction):
|
||||
name = "create"
|
||||
|
@ -34,6 +37,33 @@ class UpdateAction(tables.LinkAction):
|
|||
icon = "pencil"
|
||||
|
||||
|
||||
class DeleteAction(tables.DeleteAction):
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Delete Action",
|
||||
u"Delete Actions",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Deleted Action",
|
||||
u"Deleted Actions",
|
||||
count
|
||||
)
|
||||
|
||||
def delete(self, request, action_name):
|
||||
api.action_delete(request, action_name)
|
||||
|
||||
def allowed(self, request, action=None):
|
||||
if action:
|
||||
return not action.is_system
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def tags_to_string(action):
|
||||
return ', '.join(action.tags) if action.tags else None
|
||||
|
||||
|
@ -80,4 +110,5 @@ class ActionsTable(tables.DataTable):
|
|||
class Meta(object):
|
||||
name = "actions"
|
||||
verbose_name = _("Actions")
|
||||
table_actions = (CreateAction, UpdateAction)
|
||||
table_actions = (CreateAction, UpdateAction, DeleteAction)
|
||||
row_actions = (DeleteAction,)
|
||||
|
|
|
@ -221,3 +221,12 @@ def action_update(request, action_definition):
|
|||
"""
|
||||
|
||||
return mistralclient(request).actions.update(action_definition)
|
||||
|
||||
|
||||
def action_delete(request, action_name):
|
||||
"""Delete action.
|
||||
|
||||
:param action_name: Action name
|
||||
"""
|
||||
|
||||
return mistralclient(request).actions.delete(action_name)
|
||||
|
|
Loading…
Reference in New Issue