How to use the horizon.tables.DataTable function in horizon

To help you get started, we’ve selected a few horizon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / horizon / horizon / horizon / dashboards / syspanel / services / tables.py View on Github external
return filter(comp, services)


def get_stats(service):
    return template.loader.render_to_string('syspanel/services/_stats.html',
                                            {'service': service})


def get_enabled(service, reverse=False):
    options = ["Enabled", "Disabled"]
    if reverse:
        options.reverse()
    return options[0] if not service.disabled else options[1]


class ServicesTable(tables.DataTable):
    id = tables.Column('id', verbose_name=_('Id'), hidden=True)
    service = tables.Column('type', verbose_name=_('Service'))
    host = tables.Column('host', verbose_name=_('Host'))
    enabled = tables.Column(get_enabled,
                            verbose_name=_('Enabled'),
                            status=True)

    class Meta:
        name = "services"
        verbose_name = _("Services")
        table_actions = (ServiceFilterAction,)
        multi_select = False
        status_column = "enabled"
github openstack / horizon / openstack_dashboard / dashboards / identity / roles / tables.py View on Github external
def allowed(self, request, role):
        return api.keystone.keystone_can_edit_role()

    def delete(self, request, obj_id):
        api.keystone.role_delete(request, obj_id)


class RoleFilterAction(tables.FilterAction):
    def filter(self, table, roles, filter_string):
        """Naive case-insensitive search."""
        q = filter_string.lower()
        return [role for role in roles
                if q in role.name.lower()]


class RolesTable(tables.DataTable):
    name = tables.WrappingColumn('name', verbose_name=_('Role Name'))
    id = tables.Column('id', verbose_name=_('Role ID'))

    class Meta(object):
        name = "roles"
        verbose_name = _("Roles")
        row_actions = (EditRoleLink, DeleteRolesAction)
        table_actions = (RoleFilterAction, CreateRoleLink, DeleteRolesAction)
github cmusatyalab / elijah-openstack / dashboard / images / tables.py View on Github external
verbose_name=_("Public"),
                           empty_value=False,
                           filters=(filters.yesno, filters.capfirst))

    class Meta:
        name = "images"
        row_class = UpdateRow
        status_columns = ["status"]
        verbose_name = _("Images")
        columns = ["name", "status", "public", "disk_format"]
        table_actions = (ImportBaseVM, DeleteImage,)
        row_actions = (ResumeBaseVM, EditImage, DeleteImage,)
        pagination_param = "cloudlet_base_marker"


class VMOverlaysTable(tables.DataTable):
    STATUS_CHOICES = (
        ("active", True),
        ("saving", None),
        ("queued", None),
        ("pending_delete", None),
        ("killed", False),
        ("resume", False),
    )
    name = tables.Column("name",
                         link=("horizon:project:images:images:detail"),
                         verbose_name=_("VM Overlays"))
    image_type = tables.Column(get_image_type,
                               verbose_name=_("Type"),
                               filters=(filters.title,))
    status = tables.Column("status",
                           filters=(filters.title,),
github openstack / heat-dashboard / heat_dashboard / content / stacks / tables.py View on Github external
return stack
        except Http404:
            raise
        except Exception as e:
            messages.error(request, e)
            raise


class StacksFilterAction(tables.FilterAction):
    filter_type = 'server'
    filter_choices = (('name', _('Stack Name ='), True, _('Case-sensitive')),
                      ('id', _('Stack ID ='), True),
                      ('status', _('Status ='), True))


class StacksTable(tables.DataTable):
    STATUS_CHOICES = (
        ("Complete", True),
        ("Failed", False),
    )
    STACK_STATUS_DISPLAY_CHOICES = (
        ("init_in_progress", pgettext_lazy("current status of stack",
                                           u"Init In Progress")),
        ("init_complete", pgettext_lazy("current status of stack",
                                        u"Init Complete")),
        ("init_failed", pgettext_lazy("current status of stack",
                                      u"Init Failed")),
        ("create_in_progress", pgettext_lazy("current status of stack",
                                             u"Create In Progress")),
        ("create_complete", pgettext_lazy("current status of stack",
                                          u"Create Complete")),
        ("create_failed", pgettext_lazy("current status of stack",
github openstack / horizon / openstack_dashboard / dashboards / project / data_processing / clusters / tables.py View on Github external
def get_instances_count(cluster):
    return sum([len(ng["instances"])
                for ng in cluster.node_groups])


class ConfigureCluster(tables.LinkAction):
    name = "configure"
    verbose_name = _("Configure Cluster")
    url = "horizon:project:data_processing.clusters:configure-cluster"
    classes = ("ajax-modal", "configure-cluster-btn")
    icon = "plus"
    attrs = {"style": "display: none"}


class ClustersTable(tables.DataTable):
    STATUS_CHOICES = (
        ("active", True),
        ("error", False)
    )

    name = tables.Column("name",
                         verbose_name=_("Name"),
                         link=("horizon:project:data_processing."
                               "clusters:details"))
    status = tables.Column("status",
                           verbose_name=_("Status"),
                           status=True,
                           status_choices=STATUS_CHOICES)
    instances_count = tables.Column(get_instances_count,
                                    verbose_name=_("Instances Count"))
github openstack / horizon / horizon / horizon / usage / tables.py View on Github external
from django.utils.translation import ugettext as _
from django.template.defaultfilters import timesince

from horizon import tables
from horizon.templatetags.sizeformat import mbformat


class CSVSummary(tables.LinkAction):
    name = "csv_summary"
    verbose_name = _("Download CSV Summary")

    def get_link_url(self, usage=None):
        return self.table.kwargs['usage'].csv_link()


class BaseUsageTable(tables.DataTable):
    vcpus = tables.Column('vcpus', verbose_name=_("VCPUs"))
    disk = tables.Column('local_gb', verbose_name=_("Disk"))
    memory = tables.Column('memory_mb',
                           verbose_name=_("RAM"),
                           filters=(mbformat,))
    hours = tables.Column('vcpu_hours', verbose_name=_("VCPU Hours"))


class GlobalUsageTable(BaseUsageTable):
    tenant = tables.Column('tenant_id', verbose_name=_("Project ID"))
    disk_hours = tables.Column('disk_gb_hours',
                               verbose_name=_("Disk GB Hours"))

    def get_object_id(self, datum):
        return datum.tenant_id
github openstack / heat-dashboard / heat_dashboard / content / template_versions / tables.py View on Github external
#    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.template import defaultfilters as filters
from django.utils.translation import ugettext_lazy as _

from horizon import tables


class TemplateVersionsTable(tables.DataTable):
    version = tables.Column(
        "version",
        verbose_name=_("Version"),
        link="horizon:project:template_versions:details",)
    type = tables.Column(
        "type",
        verbose_name=_("Type"),
        filters=(filters.upper,))

    def get_object_id(self, template_versions):
        return template_versions.version

    class Meta(object):
        name = "template_versions"
        table_actions = (tables.FilterAction,)
        verbose_name = _("Template Versions")
github openstack / horizon / openstack_dashboard / dashboards / project / loadbalancers / tables.py View on Github external
context = {"vip": pool.vip, }
        return template.loader.render_to_string(template_name, context)
    else:
        return None


def get_subnet(pool):
    if hasattr(pool, "subnet") and pool.subnet:
        template_name = 'project/loadbalancers/_pool_table_subnet_cell.html'
        context = {"subnet": pool.subnet}
        return template.loader.render_to_string(template_name, context)
    else:
        return None


class PoolsTable(tables.DataTable):
    METHOD_DISPLAY_CHOICES = (
        ("round_robin", pgettext_lazy("load balancing method",
                                      u"Round Robin")),
        ("least_connections", pgettext_lazy("load balancing method",
                                            u"Least Connections")),
        ("source_ip", pgettext_lazy("load balancing method",
                                    u"Source IP")),
    )

    name = tables.Column("name_or_id",
                         verbose_name=_("Name"),
                         link="horizon:project:loadbalancers:pooldetails")
    description = tables.Column('description', verbose_name=_("Description"))
    provider = tables.Column('provider', verbose_name=_("Provider"),
                             filters=(lambda v: filters.default(v, _('N/A')),))
    subnet_name = tables.Column(get_subnet, verbose_name=_("Subnet"))
github openstack / sahara-dashboard / saharadashboard / data_sources / tables.py View on Github external
class DeleteDataSource(tables.BatchAction):
    name = "delete"
    action_present = _("Delete")
    action_past = _("Deleted")
    data_type_singular = _("Data source")
    data_type_plural = _("Data sources")
    classes = ('btn-danger', 'btn-terminate')

    def action(self, request, obj_id):
        sahara = saharaclient(request)
        sahara.data_sources.delete(obj_id)


class DataSourcesTable(tables.DataTable):
    name = tables.Column("name",
                         verbose_name=_("Name"),
                         link=("horizon:sahara:data_sources:details"))
    type = tables.Column("type",
                         verbose_name=_("Type"))
    description = tables.Column("description",
                                verbose_name=_("Description"))

    class Meta:
        name = "data_sources"
        verbose_name = _("Data Sources")
        table_actions = (CreateDataSource,
                         DeleteDataSource)
        row_actions = (DeleteDataSource,)
github openstack / horizon / openstack_dashboard / dashboards / project / networks / ports / tables.py View on Github external
policy_rules = (("network", "delete_port"),)

    def delete(self, request, port_id):
        failure_url = "horizon:project:networks:detail"
        try:
            api.neutron.port_delete(request, port_id)
        except Exception:
            msg = _('Failed to delete port: %s') % port_id
            LOG.info(msg)
            network_id = self.table.kwargs['network_id']
            redirect = reverse(failure_url,
                               args=[network_id])
            exceptions.handle(request, msg, redirect=redirect)


class PortsTable(tables.DataTable):
    name = tables.WrappingColumn("name_or_id",
                                 verbose_name=_("Name"),
                                 link="horizon:project:networks:ports:detail")
    fixed_ips = tables.Column(get_fixed_ips, verbose_name=_("Fixed IPs"))
    mac_address = tables.Column("mac_address", verbose_name=_("MAC Address"))
    attached = tables.Column(get_attached, verbose_name=_("Attached Device"))
    status = tables.Column("status",
                           verbose_name=_("Status"),
                           display_choices=STATUS_DISPLAY_CHOICES)
    admin_state = tables.Column("admin_state",
                                verbose_name=_("Admin State"),
                                display_choices=DISPLAY_CHOICES)
    mac_state = tables.Column("mac_state", empty_value=api.neutron.OFF_STATE,
                              verbose_name=_("MAC Learning State"))

    def get_object_display(self, port):