2015-01-15 18:41:24 +03:00
|
|
|
# Copyright (c) 2015 Mirantis, Inc.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2016-03-30 16:50:30 +03:00
|
|
|
from django.conf import settings
|
2015-08-18 21:51:21 +08:00
|
|
|
from django.core.urlresolvers import reverse
|
2015-01-15 18:41:24 +03:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-03-12 18:34:51 +09:00
|
|
|
from django.utils.translation import ungettext_lazy
|
2015-01-15 18:41:24 +03:00
|
|
|
from horizon import exceptions
|
|
|
|
from horizon import tables
|
|
|
|
from muranoclient.common import exceptions as exc
|
2016-07-14 12:38:49 +00:00
|
|
|
from openstack_dashboard import policy
|
2015-07-21 14:23:36 +03:00
|
|
|
from oslo_log import log as logging
|
2015-01-15 18:41:24 +03:00
|
|
|
|
|
|
|
from muranodashboard import api
|
2016-08-25 23:12:00 +08:00
|
|
|
from muranodashboard.common import utils as md_utils
|
2015-01-15 18:41:24 +03:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class AddCategory(tables.LinkAction):
|
|
|
|
name = "add_category"
|
|
|
|
verbose_name = _("Add Category")
|
2016-08-23 17:46:33 +03:00
|
|
|
url = "horizon:app-catalog:categories:add"
|
2015-01-15 18:41:24 +03:00
|
|
|
classes = ("ajax-modal",)
|
|
|
|
icon = "plus"
|
2016-07-14 12:38:49 +00:00
|
|
|
policy_rules = (("murano", "add_category"),)
|
2015-01-15 18:41:24 +03:00
|
|
|
|
|
|
|
|
2016-07-14 12:38:49 +00:00
|
|
|
class DeleteCategory(policy.PolicyTargetMixin, tables.DeleteAction):
|
|
|
|
policy_rules = (("murano", "delete_category"),)
|
|
|
|
|
2016-03-12 18:34:51 +09:00
|
|
|
@staticmethod
|
|
|
|
def action_present(count):
|
|
|
|
return ungettext_lazy(
|
|
|
|
u"Delete Category",
|
|
|
|
u"Delete Categories",
|
|
|
|
count
|
|
|
|
)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def action_past(count):
|
|
|
|
return ungettext_lazy(
|
|
|
|
u"Deleted Category",
|
|
|
|
u"Deleted Categories",
|
|
|
|
count
|
|
|
|
)
|
2015-01-15 18:41:24 +03:00
|
|
|
|
|
|
|
def allowed(self, request, category=None):
|
2016-03-30 16:50:30 +03:00
|
|
|
use_artifacts = getattr(settings, 'MURANO_USE_GLARE', False)
|
|
|
|
if use_artifacts:
|
|
|
|
return category is not None
|
2015-01-15 18:41:24 +03:00
|
|
|
if category is not None:
|
|
|
|
if not category.package_count:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def delete(self, request, obj_id):
|
|
|
|
try:
|
|
|
|
api.muranoclient(request).categories.delete(obj_id)
|
|
|
|
except exc.HTTPException:
|
2016-02-09 18:05:48 +03:00
|
|
|
msg = _('Unable to delete category')
|
|
|
|
LOG.exception(msg)
|
2016-08-23 17:46:33 +03:00
|
|
|
url = reverse('horizon:app-catalog:categories:index')
|
2016-02-09 18:05:48 +03:00
|
|
|
exceptions.handle(request, msg, redirect=url)
|
2015-01-15 18:41:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
class CategoriesTable(tables.DataTable):
|
2016-08-25 23:12:00 +08:00
|
|
|
name = md_utils.Column('name', verbose_name=_('Category Name'))
|
2016-03-30 16:50:30 +03:00
|
|
|
use_artifacts = getattr(settings, 'MURANO_USE_GLARE', False)
|
|
|
|
if not use_artifacts:
|
|
|
|
package_count = tables.Column('package_count',
|
|
|
|
verbose_name=_('Package Count'))
|
2015-01-15 18:41:24 +03:00
|
|
|
|
2015-07-24 17:54:22 +03:00
|
|
|
class Meta(object):
|
2015-01-15 18:41:24 +03:00
|
|
|
name = 'categories'
|
|
|
|
verbose_name = _('Application Categories')
|
|
|
|
table_actions = (AddCategory,)
|
|
|
|
row_actions = (DeleteCategory,)
|
|
|
|
multi_select = False
|