views.py 1.24 KB
Newer Older
1
from django.views.generic import TemplateView, DetailView
Kálmán Viktor committed
2 3
# from django_tables2 import SingleTableView

4
from vm.models import Instance
5
from django.core import signing
6 7 8


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

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

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

23

24
class VmDetailView(DetailView):
Kálmán Viktor committed
25
    template_name = "dashboard/vm-detail.html"
26 27 28 29 30 31 32 33 34 35 36 37 38 39
    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
40 41 42 43


class VmList(TemplateView):
    template_name = "dashboard/vm-list.html"