views.py 1.35 KB
Newer Older
1
from django.views.generic import TemplateView, DetailView
2 3 4
from django_tables2 import SingleTableView

from tables import VmListTable
Kálmán Viktor committed
5

6
from vm.models import Instance
7
from django.core import signing
8 9 10


class IndexView(TemplateView):
Kálmán Viktor committed
11
    template_name = "dashboard/index.html"
12

13
    def get_context_data(self, **kwargs):
14 15 16 17 18
        if self.request.user.is_authenticated():
            user = self.request.user
        else:
            user = None

19 20
        context = super(IndexView, self).get_context_data(**kwargs)
        context.update({
21
            'instances': Instance.objects.filter(owner=user),
22 23 24
        })
        return context

25

26
class VmDetailView(DetailView):
Kálmán Viktor committed
27
    template_name = "dashboard/vm-detail.html"
28 29 30 31 32 33 34 35 36 37 38 39 40 41
    queryset = Instance.objects.all()

    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        instance = context['instance']
        if instance.node:
            port = instance.vnc_port
            host = instance.node.host.ipv4
            value = signing.dumps({'host': host,
                                   'port': port}, key='asdasd')
            context.update({
                'vnc_url': '%s' % value
            })
        return context
Kálmán Viktor committed
42 43


44
class VmList(SingleTableView):
Kálmán Viktor committed
45
    template_name = "dashboard/vm-list.html"
46 47
    model = Instance
    table_class = VmListTable
48
    table_pagination = False