tables.py 6.11 KB
Newer Older
1
from django.contrib.auth.models import Group
2 3 4
from django_tables2 import Table, A
from django_tables2.columns import (TemplateColumn, Column, BooleanColumn,
                                    LinkColumn)
5

6
from vm.models import Instance, Node, InstanceTemplate, Lease
7 8 9 10
from django.utils.translation import ugettext_lazy as _


class VmListTable(Table):
11 12
    pk = TemplateColumn(
        template_name='dashboard/vm-list/column-id.html',
13 14 15
        verbose_name="ID",
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
16 17 18

    name = TemplateColumn(
        template_name="dashboard/vm-list/column-name.html"
19
    )
20

21 22 23 24 25 26 27 28 29 30 31 32
    admin = TemplateColumn(
        template_name='dashboard/vm-list/column-admin.html',
        attrs={'th': {'class': 'vm-list-table-admin'}},
    )
    details = TemplateColumn(
        template_name='dashboard/vm-list/column-details.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
    actions = TemplateColumn(
        template_name='dashboard/vm-list/column-actions.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
33
    time_of_suspend = TemplateColumn(
34
        '{{ record.time_of_suspend|timeuntil }}',
35
        verbose_name=_("Suspend in"))
36
    time_of_delete = TemplateColumn(
37
        '{{ record.time_of_delete|timeuntil }}',
38
        verbose_name=_("Delete in"))
39 40 41 42 43 44

    class Meta:
        model = Instance
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'vm-list-table')}
        fields = ('pk', 'name', 'state', 'time_of_suspend', 'time_of_delete', )
45 46 47 48 49 50


class NodeListTable(Table):

    pk = Column(
        verbose_name="ID",
51
        attrs={'th': {'class': 'node-list-table-thin'}},
52 53
    )

54 55 56
    overcommit = Column(
        verbose_name="Overcommit",
        attrs={'th': {'class': 'node-list-table-thin'}},
57 58
    )

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    host = Column(
        verbose_name="Host",
    )

    enabled = BooleanColumn(
        verbose_name="Enabled",
        attrs={'th': {'class': 'node-list-table-thin'}},
    )

    name = TemplateColumn(
        template_name="dashboard/node-list/column-name.html"
    )

    priority = Column(
        verbose_name=_("Priority"),
        attrs={'th': {'class': 'node-list-table-thin'}},
    )

    number_of_VMs = TemplateColumn(
        template_name='dashboard/node-list/column-vm.html',
        attrs={'th': {'class': 'node-list-table-admin'}},
    )

    admin = TemplateColumn(
        template_name='dashboard/node-list/column-admin.html',
        attrs={'th': {'class': 'node-list-table-admin'}},
    )

    details = TemplateColumn(
        template_name='dashboard/node-list/column-details.html',
        attrs={'th': {'class': 'node-list-table-thin'}},
    )
    actions = TemplateColumn(
        attrs={'th': {'class': 'node-list-table-thin'}},
93 94
        template_code=('{% include "dashboard/node-list/column-'
                       'actions.html" with btn_size="btn-xs" %}'),
95 96
    )

97 98 99 100
    class Meta:
        model = Node
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'node-list-table')}
101 102 103
        fields = ('pk', 'name', 'host', 'enabled', 'priority', 'overcommit',
                  'number_of_VMs', )

104

105 106 107 108 109 110 111 112
class GroupListTable(Table):
    class Meta:
        model = Group
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'group-list-table')}
        fields = ('id', 'name', )


113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
class NodeVmListTable(Table):
    pk = TemplateColumn(
        template_name='dashboard/vm-list/column-id.html',
        verbose_name="ID",
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )

    name = TemplateColumn(
        template_name="dashboard/vm-list/column-name.html"
    )

    admin = TemplateColumn(
        template_name='dashboard/vm-list/column-admin.html',
        attrs={'th': {'class': 'vm-list-table-admin'}},
    )
    details = TemplateColumn(
        template_name='dashboard/vm-list/column-details.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
    actions = TemplateColumn(
        template_name='dashboard/vm-list/column-actions.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
    time_of_suspend = TemplateColumn(
        '{{ record.time_of_suspend|timeuntil }}',
        verbose_name=_("Suspend in"))
    time_of_delete = TemplateColumn(
        '{{ record.time_of_delete|timeuntil }}',
        verbose_name=_("Delete in"))

    class Meta:
        model = Instance
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'vm-list-table')}
        fields = ('pk', 'name', 'state', 'time_of_suspend', 'time_of_delete', )
148 149 150


class TemplateListTable(Table):
151
    name = LinkColumn(
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        'dashboard.views.template-detail',
        args=[A('pk')],
    )
    num_cores = Column(
        verbose_name=_("Cores"),
    )
    ram_size = TemplateColumn(
        "{{ record.ram_size }} Mb",
    )
    lease = TemplateColumn(
        "{{ record.lease.name }}",
        verbose_name=_("Lease"),
    )
    actions = TemplateColumn(
        verbose_name=_("Actions"),
167 168
        template_name="dashboard/template-list/column-template-actions.html",
        attrs={'th': {'class': 'template-list-table-thin'}},
169 170 171 172 173 174
    )

    class Meta:
        model = InstanceTemplate
        attrs = {'class': ('table table-bordered table-striped table-hover'
                           ' template-list-table')}
175
        fields = ('name', 'num_cores', 'ram_size', 'arch',
176
                  'system', 'access_method', 'lease', 'state',
177 178 179 180
                  'actions', )


class LeaseListTable(Table):
181
    name = LinkColumn(
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        'dashboard.views.lease-detail',
        args=[A('pk')],
    )

    suspend_in = TemplateColumn(
        "{{ record.get_readable_suspend_time }}"
    )

    delete_in = TemplateColumn(
        "{{ record.get_readable_delete_time }}"
    )

    actions = TemplateColumn(
        verbose_name=_("Actions"),
        template_name="dashboard/template-list/column-lease-actions.html"
    )

    class Meta:
        model = Lease
        attrs = {'class': ('table table-bordered table-striped table-hover'
                           ' lease-list-table')}
203
        fields = ('name', 'suspend_in', 'delete_in', )