tables.py 1.89 KB
Newer Older
1 2
from django_tables2 import Table, A
from django_tables2.columns import LinkColumn, TemplateColumn, Column
3

4
from vm.models import Instance, Node
5 6 7 8
from django.utils.translation import ugettext_lazy as _


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

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

19 20 21 22 23 24 25 26 27 28 29 30
    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'}},
    )
31
    time_of_suspend = TemplateColumn(
32
        '{{ record.time_of_suspend|timeuntil }}',
33
        verbose_name=_("Suspend in"))
34
    time_of_delete = TemplateColumn(
35
        '{{ record.time_of_delete|timeuntil }}',
36
        verbose_name=_("Delete in"))
37 38 39 40 41 42

    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', )
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62


class NodeListTable(Table):

    pk = Column(
        verbose_name="ID",
    )

    name = LinkColumn(
        'dashboard.views.node-detail',
        args=[A('pk')],
        attrs={'a': {'class': 'real-link'}}
    )

    class Meta:
        model = Node
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'node-list-table')}
        fields = ('pk', 'name', 'host' , 'enabled' , 'created' , 'modified' , 'priority' , 'overcommit' ,)