Commit db8ae8b0 by Oláh István Gergely

dashboard: create add trait in NodeDetail, fix traits list

parent e12f401e
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
<div style="font-weight: bold;">{% trans "Traits" %}</div> <div style="font-weight: bold;">{% trans "Traits" %}</div>
<div id="node-details-traits" style="margin-bottom: 20px;"> <div id="node-details-traits" style="margin-bottom: 20px;">
<div id="node-details-traits-list"> <div id="node-details-traits-list">
{% if node.tags.all %} {% if node.traits.all %}
{% for t in node.tags.all %} {% for t in node.traits.all %}
<div class="label label-primary label-tag" style="display: inline-block"> <div class="label label-primary label-tag" style="display: inline-block">
{{ t }} {{ t }}
<a href="#" class="node-details-remove-trait"><i class="icon-remove"></i></a> <a href="#" class="node-details-remove-trait"><i class="icon-remove"></i></a>
......
...@@ -34,7 +34,7 @@ from .tables import (VmListTable, NodeListTable, NodeVmListTable, ...@@ -34,7 +34,7 @@ from .tables import (VmListTable, NodeListTable, NodeVmListTable,
TemplateListTable, LeaseListTable, GroupListTable,) TemplateListTable, LeaseListTable, GroupListTable,)
from vm.models import (Instance, InstanceTemplate, InterfaceTemplate, from vm.models import (Instance, InstanceTemplate, InterfaceTemplate,
InstanceActivity, Node, instance_activity, Lease, InstanceActivity, Node, instance_activity, Lease,
Interface) Interface, NodeActivity, Trait)
from firewall.models import Vlan, Host, Rule from firewall.models import Vlan, Host, Rule
from storage.models import Disk from storage.models import Disk
from dashboard.models import Favourite from dashboard.models import Favourite
...@@ -444,6 +444,10 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -444,6 +444,10 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
context = super(NodeDetailView, self).get_context_data(**kwargs) context = super(NodeDetailView, self).get_context_data(**kwargs)
instances = Instance.active.filter(node=self.object) instances = Instance.active.filter(node=self.object)
context['table'] = NodeVmListTable(instances) context['table'] = NodeVmListTable(instances)
ia = NodeActivity.objects.filter(
node=self.object, parent=None
).order_by('-started').select_related()
context['activities'] = ia
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
...@@ -451,6 +455,8 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -451,6 +455,8 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return self.__set_name(request) return self.__set_name(request)
if request.POST.get('new_status'): if request.POST.get('new_status'):
return self.__set_status(request) return self.__set_status(request)
if request.POST.get('new_trait'):
return self.__add_trait(request)
def __set_name(self, request): def __set_name(self, request):
self.object = self.get_object() self.object = self.get_object()
...@@ -500,6 +506,25 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -500,6 +506,25 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return redirect(reverse_lazy("dashboard.views.node-detail", return redirect(reverse_lazy("dashboard.views.node-detail",
kwargs={'pk': self.object.pk})) kwargs={'pk': self.object.pk}))
def __add_trait(self, request):
new_trait_name = request.POST.get('new_trait')
self.object = self.get_object()
if len(new_trait_name) < 1:
message = u"Please input something!"
elif len(new_trait_name) > 20:
message = u"Trait name is too long!"
else:
self.object.traits.create(name=new_trait_name)
try:
messages.error(request, message)
except:
pass
return redirect(reverse_lazy("dashboard.views.node-detail",
kwargs={'pk': self.object.pk}))
class GroupDetailView(CheckedDetailView): class GroupDetailView(CheckedDetailView):
template_name = "dashboard/group-detail.html" template_name = "dashboard/group-detail.html"
......
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