Merge "Angular vs. Django Table Danger Button Inconsistency"

This commit is contained in:
Jenkins 2016-04-15 21:05:44 +00:00 committed by Gerrit Code Review
commit 32e0fbba9e
11 changed files with 40 additions and 27 deletions

View File

@ -96,6 +96,7 @@ class BaseAction(html.HTMLElement):
self.requires_input = kwargs.get('requires_input', False)
self.preempt = kwargs.get('preempt', False)
self.policy_rules = kwargs.get('policy_rules', None)
self.action_type = kwargs.get('action_type', 'default')
def data_type_matched(self, datum):
"""Method to see if the action is allowed for a certain type of data.
@ -352,6 +353,7 @@ class LinkAction(BaseAction):
self.allowed_data_types = kwargs.get('allowed_data_types', [])
self.icon = kwargs.get('icon', None)
self.kwargs = kwargs
self.action_type = kwargs.get('action_type', 'default')
if not kwargs.get('verbose_name', None):
raise NotImplementedError('A LinkAction object must have a '
@ -930,6 +932,7 @@ class DeleteAction(BatchAction):
if not hasattr(self, "action_past"):
self.action_past = kwargs.get('action_past', _("Deleted"))
self.icon = "trash"
self.action_type = "danger"
def action(self, request, obj_id):
"""Action entry point. Overrides base class' action method.
@ -945,16 +948,6 @@ class DeleteAction(BatchAction):
Override to provide delete functionality specific to your data.
"""
def get_default_classes(self):
"""Appends ``btn-danger`` to the action's default css classes.
This method ensures the corresponding button is highlighted
as a trigger for a potentially dangerous action.
"""
classes = super(DeleteAction, self).get_default_classes()
classes += ("btn-danger",)
return classes
class UpdateAction(object):
"""A table action for cell updates by inline editing."""

View File

@ -2,7 +2,15 @@
{% minifyspace %}
{% if action.method != "GET" %}
<button {{ action.attr_string_nc|safe }}
class="{% if is_single %}btn btn-default {% endif %}{% if is_small %}btn-sm {% endif %}{{ action.get_final_css|safe }}"
class="
{% if is_single %}btn {% endif %}
{% if is_small %}btn-sm{% endif %}
{% for class in action.get_default_classes %}
{{ class }}
{% endfor %}
{% if action.action_type %}
btn-{{ action.action_type }}
{% endif %}"
name="action"
{% if action.help_text %}
help_text="{{ action.help_text }}"

View File

@ -87,9 +87,10 @@ class EnableService(policy.PolicyTargetMixin, tables.BatchAction):
class MigrateMaintenanceHost(tables.LinkAction):
name = "migrate_maintenance"
policy_rules = (("compute", "compute_extension:admin_actions:migrate"),)
classes = ('ajax-modal', 'btn-migrate', 'btn-danger')
classes = ('ajax-modal', 'btn-migrate')
verbose_name = _("Migrate Host")
url = "horizon:admin:hypervisors:compute:migrate_host"
action_type = "danger"
@staticmethod
def action_present(count):

View File

@ -40,9 +40,10 @@ class AdminLogLink(project_tables.LogLink):
class MigrateInstance(policy.PolicyTargetMixin, tables.BatchAction):
name = "migrate"
classes = ("btn-migrate", "btn-danger")
classes = ("btn-migrate",)
policy_rules = (("compute", "compute_extension:admin_actions:migrate"),)
help_text = _("Migrating instances may cause some unrecoverable results.")
action_type = "danger"
@staticmethod
def action_present(count):
@ -74,9 +75,10 @@ class LiveMigrateInstance(policy.PolicyTargetMixin,
name = "live_migrate"
verbose_name = _("Live Migrate Instance")
url = "horizon:admin:instances:live_migrate"
classes = ("ajax-modal", "btn-migrate", "btn-danger")
classes = ("ajax-modal", "btn-migrate")
policy_rules = (
("compute", "compute_extension:admin_actions:migrateLive"),)
action_type = "danger"
def allowed(self, request, instance):
return ((instance.status in project_tables.ACTIVE_STATES)

View File

@ -75,11 +75,12 @@ class ViewCredentials(tables.LinkAction):
class RecreateCredentials(tables.LinkAction):
name = "recreate_credentials"
verbose_name = _("Recreate EC2 Credentials")
classes = ("ajax-modal", "btn-danger")
classes = ("ajax-modal",)
icon = "refresh"
url = \
"horizon:project:access_and_security:api_access:recreate_credentials"
policy_rules = (("compute", "compute_extension:certificates"))
action_type = "danger"
def allowed(self, request, datum=None):
try:

View File

@ -71,7 +71,7 @@ class AllocateIP(tables.LinkAction):
class ReleaseIPs(tables.BatchAction):
name = "release"
classes = ('btn-danger',)
action_type = "danger"
icon = "unlink"
help_text = _("Once a floating IP is released, there is"
" no guarantee the same IP can be allocated again.")
@ -130,8 +130,9 @@ class AssociateIP(tables.LinkAction):
class DisassociateIP(tables.Action):
name = "disassociate"
verbose_name = _("Disassociate")
classes = ("btn-disassociate", "btn-danger")
classes = ("btn-disassociate",)
icon = "unlink"
action_type = "danger"
def allowed(self, request, fip):
if api.base.is_service_enabled(request, "network"):

View File

@ -203,9 +203,10 @@ class RemoveRuleFromPolicyLink(policy.PolicyTargetMixin,
tables.LinkAction):
name = "removerule"
verbose_name = _("Remove Rule")
classes = ("ajax-modal", "btn-danger",)
classes = ("ajax-modal",)
policy_rules = (("network", "get_firewall_policy"),
("network", "remove_rule"),)
action_type = "danger"
def get_link_url(self, policy):
base_url = reverse("horizon:project:firewalls:removerule",

View File

@ -111,10 +111,11 @@ class DeleteInstance(policy.PolicyTargetMixin, tables.DeleteAction):
class RebootInstance(policy.PolicyTargetMixin, tables.BatchAction):
name = "reboot"
classes = ('btn-danger', 'btn-reboot')
classes = ('btn-reboot',)
policy_rules = (("compute", "compute:reboot"),)
help_text = _("Restarted instances will lose any data"
" not saved in persistent storage.")
action_type = "danger"
@staticmethod
def action_present(count):
@ -675,8 +676,9 @@ class SimpleAssociateIP(policy.PolicyTargetMixin, tables.Action):
class SimpleDisassociateIP(policy.PolicyTargetMixin, tables.Action):
name = "disassociate"
verbose_name = _("Disassociate Floating IP")
classes = ("btn-danger", "btn-disassociate",)
classes = ("btn-disassociate",)
policy_rules = (("compute", "network:disassociate_floating_ip"),)
action_type = "danger"
def allowed(self, request, instance):
if not api.network.floating_ip_supported(request):
@ -820,9 +822,9 @@ class StartInstance(policy.PolicyTargetMixin, tables.BatchAction):
class StopInstance(policy.PolicyTargetMixin, tables.BatchAction):
name = "stop"
classes = ('btn-danger',)
policy_rules = (("compute", "compute:stop"),)
help_text = _("The instance(s) will be shut off.")
action_type = "danger"
@staticmethod
def action_present(count):

View File

@ -84,7 +84,7 @@ class DeleteVipLink(policy.PolicyTargetMixin, tables.Action):
preempt = True
verbose_name = _("Delete VIP")
policy_rules = (("network", "delete_vip"),)
classes = ('btn-danger',)
action_type = "danger"
def allowed(self, request, datum=None):
if datum and datum.vip_id:
@ -280,9 +280,10 @@ class DeletePMAssociationLink(policy.PolicyTargetMixin,
name = "deleteassociation"
verbose_name = _("Disassociate Monitor")
url = "horizon:project:loadbalancers:deleteassociation"
classes = ("ajax-modal", "btn-danger")
classes = ("ajax-modal",)
icon = "trash"
policy_rules = (("network", "delete_pool_health_monitor"),)
action_type = "danger"
def allowed(self, request, datum=None):
if datum and not datum['health_monitors']:
@ -336,8 +337,9 @@ class RemoveVIPFloatingIP(policy.PolicyTargetMixin, tables.Action):
preempt = True
icon = "unlink"
verbose_name = _("Disassociate Floating IP")
classes = ("btn-danger", "btn-disassociate",)
classes = ("btn-disassociate",)
policy_rules = (("compute", "network:disassociate_floating_ip"),)
action_type = "danger"
def allowed(self, request, pool):
if not api.network.floating_ip_supported(request):

View File

@ -147,9 +147,10 @@ class ClearGateway(policy.PolicyTargetMixin, tables.BatchAction):
)
name = "cleargateway"
classes = ('btn-danger', 'btn-cleargateway')
classes = ('btn-cleargateway',)
redirect_url = "horizon:project:routers:index"
policy_rules = (("network", "update_router"),)
action_type = "danger"
def action(self, request, obj_id):
obj = self.table.get_object_by_id(obj_id)

View File

@ -298,8 +298,8 @@ class DeleteTransfer(VolumePolicyTargetMixin, tables.Action):
name = "delete_transfer"
verbose_name = _("Cancel Transfer")
policy_rules = (("volume", "volume:delete_transfer"),)
classes = ('btn-danger',)
help_text = _("This action cannot be undone.")
action_type = "danger"
def allowed(self, request, volume):
return (volume.status == "awaiting-transfer" and
@ -491,11 +491,12 @@ class VolumesTable(VolumesTableBase):
class DetachVolume(tables.BatchAction):
name = "detach"
classes = ('btn-danger', 'btn-detach')
classes = ('btn-detach',)
policy_rules = (("compute", "compute:detach_volume"),)
help_text = _("The data will remain in the volume and another instance"
" will be able to access the data if you attach"
" this volume to it.")
action_type = "danger"
@staticmethod
def action_present(count):