mistral-dashboard/mistraldashboard/actions/tables.py
Akihiro Motoki 3ae1e8aae3 Django 2.0 support
Replace django.core.urlresolves with django.urls

(In Django 2.0) The django.core.urlresolvers module is removed
in favor of its new location, django.urls.
It was deprecated in Django 1.10:
https://docs.djangoproject.com/en/2.0/releases/1.10/#id3

Add py35dj20 job to test Django 2.0 integration.

Change-Id: I6d2e38201387012ba9a02c4b0bd8377895a5919a
2018-05-15 06:14:48 +09:00

143 lines
3.5 KiB
Python

# Copyright 2015 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.urls import reverse
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
from mistraldashboard.default import smart_cell
from mistraldashboard.default import utils
smart_cell.init()
class CreateAction(tables.LinkAction):
name = "create"
verbose_name = _("Create Action")
url = "horizon:mistral:actions:create"
classes = ("ajax-modal",)
icon = "plus"
class UpdateAction(tables.LinkAction):
name = "update"
verbose_name = _("Update Action")
url = "horizon:mistral:actions:update"
classes = ("ajax-modal",)
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
def cut(action, length=100):
inputs = action.input
if inputs and len(inputs) > length:
return "%s..." % inputs[:length]
else:
return inputs
class RunAction(tables.LinkAction):
name = "run"
verbose_name = _("Run")
classes = ("ajax-modal",)
def get_link_url(self, datum):
obj_id = datum.name
url = "horizon:mistral:actions:run"
return reverse(url, args=[obj_id])
class ActionsTable(tables.DataTable):
name = tables.Column(
"name",
verbose_name=_("Name"),
link="horizon:mistral:actions:detail"
)
is_system = tables.Column(
"is_system",
verbose_name=_("Is System"),
filters=[utils.booleanfield]
)
tags = tables.Column(
tags_to_string,
verbose_name=_("Tags")
)
inputs = tables.Column(
cut,
verbose_name=_("Input")
)
created = tables.Column(
"created_at",
verbose_name=_("Created"),
filters=(
filters.parse_isotime,
filters.timesince_or_never
)
)
updated = tables.Column(
"updated_at",
verbose_name=_("Updated"),
filters=(
filters.parse_isotime,
filters.timesince_or_never
)
)
class Meta(object):
name = "actions"
verbose_name = _("Actions")
table_actions = (
CreateAction,
UpdateAction,
DeleteAction,
tables.FilterAction,
)
row_actions = (RunAction, DeleteAction)