Commit 3199d66f by Szabolcs Gelencser

Show templates on UI

parent 9e76ed54
......@@ -48,9 +48,6 @@
<a href="{% url "dashboard.views.template-list" %}" class="btn btn-primary btn-xs">
<i class="fa fa-chevron-circle-right"></i> {% trans "show all" %}
</a>
<a href="{% url "dashboard.views.template-choose" %}" class="btn btn-success btn-xs template-choose">
<i class="fa fa-plus-circle"></i> {% trans "new" %}
</a>
</div>
</div>
</div>
......
......@@ -31,11 +31,10 @@
{# </div>#}
{# {% endif %}#}
{##}
{# {% if perms.vm.create_template %}#}
{# <div class="col-lg-4 col-sm-6">#}
{# {% include "dashboard/index-templates.html" %}#}
{# </div>#}
{# {% endif %}#}
{# #TODO: check permissions for template (as well as for other resources) #}
<div class="col-lg-4 col-sm-6">
{% include "dashboard/index-templates.html" %}
</div>
{##}
{# {% if perms.vm.view_statistics %}#}
{# <div class="col-lg-4 col-sm-6">#}
......
......@@ -18,6 +18,7 @@
from __future__ import absolute_import
from dashboard.views.autocomplete import AclUserGroupAutocomplete, AclUserAutocomplete
from dashboard.views.template import TemplateList, TemplateChoose, TemplateDetail
from dashboard.views.vm import VmDetailView, VmList, VmCreate, vm_activity, vm_ops, FavouriteView, VmPlainImageCreate
from django.conf.urls import url
......@@ -43,14 +44,14 @@ urlpatterns = [
#
# url(r'^template/create/$', TemplateCreate.as_view(),
# name="dashboard.views.template-create"),
# url(r'^template/choose/$', TemplateChoose.as_view(),
# name="dashboard.views.template-choose"),
url(r'^template/choose/$', TemplateChoose.as_view(),
name="dashboard.views.template-choose"),
# url(r'template/(?P<pk>\d+)/acl/$', TemplateAclUpdateView.as_view(),
# name='dashboard.views.template-acl'),
# url(r'^template/(?P<pk>\d+)/$', TemplateDetail.as_view(),
# name='dashboard.views.template-detail'),
# url(r"^template/list/$", TemplateList.as_view(),
# name="dashboard.views.template-list"),
url(r'^template/(?P<pk>\d+)/$', TemplateDetail.as_view(),
name='dashboard.views.template-detail'),
url(r"^template/list/$", TemplateList.as_view(),
name="dashboard.views.template-list"),
# url(r"^template/delete/(?P<pk>\d+)/$", TemplateDelete.as_view(),
# name="dashboard.views.template-delete"),
# url(r'^template/(?P<pk>\d+)/tx/$', TransferTemplateOwnershipView.as_view(),
......
......@@ -102,9 +102,7 @@ class IndexView(LoginRequiredMixin, TemplateView):
})
# template
if user.has_perm('vm.create_template'):
context['templates'] = InstanceTemplate.get_objects_with_level(
'operator', user, disregard_superuser=True).all()[:5]
context['templates'] = InstanceTemplate.objects.filter(owner_id=user.id)
# vxlan
all_vxlans = openstack_api.neutron.network_list_for_tenant(self.request, self.request.user.tenant_id)
......
......@@ -51,8 +51,8 @@ from ..tables import TemplateListTable, LeaseListTable
from .util import (
AclUpdateView, FilterMixin,
TransferOwnershipConfirmView, TransferOwnershipView,
DeleteViewBase,
# TransferOwnershipConfirmView, TransferOwnershipView,
# DeleteViewBase,
GraphMixin
)
......@@ -285,18 +285,18 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
return qs.select_related("lease", "owner", "owner__profile")
class TemplateDelete(DeleteViewBase):
model = InstanceTemplate
success_message = _("Template successfully deleted.")
def get_success_url(self):
return reverse("dashboard.views.template-list")
def delete_obj(self, request, *args, **kwargs):
object = self.get_object()
object.destroy_disks()
object.delete()
#
# class TemplateDelete(DeleteViewBase):
# model = InstanceTemplate
# success_message = _("Template successfully deleted.")
#
# def get_success_url(self):
# return reverse("dashboard.views.template-list")
#
# def delete_obj(self, request, *args, **kwargs):
# object = self.get_object()
# object.destroy_disks()
# object.delete()
class TemplateDetail(LoginRequiredMixin, GraphMixin,
......@@ -360,41 +360,41 @@ class TemplateDetail(LoginRequiredMixin, GraphMixin,
kwargs['user'] = self.request.user
return kwargs
class DiskRemoveView(DeleteViewBase):
model = Disk
success_message = _("Disk successfully removed.")
def get_queryset(self):
qs = super(DiskRemoveView, self).get_queryset()
return qs.exclude(template_set=None)
def check_auth(self):
disk = self.get_object()
template = disk.template_set.get()
if not template.has_level(self.request.user, 'owner'):
raise PermissionDenied()
def get_context_data(self, **kwargs):
disk = self.get_object()
template = disk.template_set.get()
context = super(DiskRemoveView, self).get_context_data(**kwargs)
context['title'] = _("Disk remove confirmation")
context['text'] = _("Are you sure you want to remove "
"<strong>%(disk)s</strong> from "
"<strong>%(app)s</strong>?" % {'disk': disk,
'app': template}
)
return context
def delete_obj(self, request, *args, **kwargs):
disk = self.get_object()
template = disk.template_set.get()
template.remove_disk(disk)
disk.destroy()
def get_success_url(self):
return self.request.POST.get("next") or "/"
#
# class DiskRemoveView(DeleteViewBase):
# model = Disk
# success_message = _("Disk successfully removed.")
#
# def get_queryset(self):
# qs = super(DiskRemoveView, self).get_queryset()
# return qs.exclude(template_set=None)
#
# def check_auth(self):
# disk = self.get_object()
# template = disk.template_set.get()
# if not template.has_level(self.request.user, 'owner'):
# raise PermissionDenied()
#
# def get_context_data(self, **kwargs):
# disk = self.get_object()
# template = disk.template_set.get()
# context = super(DiskRemoveView, self).get_context_data(**kwargs)
# context['title'] = _("Disk remove confirmation")
# context['text'] = _("Are you sure you want to remove "
# "<strong>%(disk)s</strong> from "
# "<strong>%(app)s</strong>?" % {'disk': disk,
# 'app': template}
# )
# return context
#
# def delete_obj(self, request, *args, **kwargs):
# disk = self.get_object()
# template = disk.template_set.get()
# template.remove_disk(disk)
# disk.destroy()
#
# def get_success_url(self):
# return self.request.POST.get("next") or "/"
class LeaseCreate(LoginRequiredMixin, PermissionRequiredMixin,
......@@ -447,47 +447,47 @@ class LeaseDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
return super(LeaseDetail, self).post(request, *args, **kwargs)
class LeaseDelete(DeleteViewBase):
model = Lease
success_message = _("Lease successfully deleted.")
def get_success_url(self):
return reverse("dashboard.views.template-list")
def get_context_data(self, *args, **kwargs):
c = super(LeaseDelete, self).get_context_data(*args, **kwargs)
lease = self.get_object()
templates = lease.instancetemplate_set
if templates.count() > 0:
text = _("You can't delete this lease because some templates "
"are still using it, modify these to proceed: ")
c['text'] = text + ", ".join("<strong>%s (#%d)</strong>"
"" % (o.name, o.pk)
for o in templates.all())
c['disable_submit'] = True
return c
def delete_obj(self, request, *args, **kwargs):
object = self.get_object()
if object.instancetemplate_set.count() > 0:
raise SuspiciousOperation()
object.delete()
class TransferTemplateOwnershipConfirmView(TransferOwnershipConfirmView):
template = "dashboard/confirm/transfer-template-ownership.html"
model = InstanceTemplate
class TransferTemplateOwnershipView(TransferOwnershipView):
confirm_view = TransferTemplateOwnershipConfirmView
model = InstanceTemplate
notification_msg = ugettext_noop(
'%(owner)s offered you to take the ownership of '
'his/her template called %(instance)s. '
'<a href="%(token)s" '
'class="btn btn-success btn-small">Accept</a>')
token_url = 'dashboard.views.template-transfer-ownership-confirm'
template = "dashboard/template-tx-owner.html"
#
# class LeaseDelete(DeleteViewBase):
# model = Lease
# success_message = _("Lease successfully deleted.")
#
# def get_success_url(self):
# return reverse("dashboard.views.template-list")
#
# def get_context_data(self, *args, **kwargs):
# c = super(LeaseDelete, self).get_context_data(*args, **kwargs)
# lease = self.get_object()
# templates = lease.instancetemplate_set
# if templates.count() > 0:
# text = _("You can't delete this lease because some templates "
# "are still using it, modify these to proceed: ")
#
# c['text'] = text + ", ".join("<strong>%s (#%d)</strong>"
# "" % (o.name, o.pk)
# for o in templates.all())
# c['disable_submit'] = True
# return c
#
# def delete_obj(self, request, *args, **kwargs):
# object = self.get_object()
# if object.instancetemplate_set.count() > 0:
# raise SuspiciousOperation()
# object.delete()
#
#
# class TransferTemplateOwnershipConfirmView(TransferOwnershipConfirmView):
# template = "dashboard/confirm/transfer-template-ownership.html"
# model = InstanceTemplate
#
#
# class TransferTemplateOwnershipView(TransferOwnershipView):
# confirm_view = TransferTemplateOwnershipConfirmView
# model = InstanceTemplate
# notification_msg = ugettext_noop(
# '%(owner)s offered you to take the ownership of '
# 'his/her template called %(instance)s. '
# '<a href="%(token)s" '
# 'class="btn btn-success btn-small">Accept</a>')
# token_url = 'dashboard.views.template-transfer-ownership-confirm'
# template = "dashboard/template-tx-owner.html"
......@@ -164,11 +164,11 @@ class InstanceTemplate(TimeStampedModel):
def os_type(self):
"""The type of the template's operating system.
"""
return 'linux' #TODO
if self.access_method == 'rdp':
return 'windows'
else:
return 'linux'
#TODO
@permalink
def get_absolute_url(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment