Commit 9423ec6c by Bach Dániel Committed by Guba Sándor

dashboard: fix flake8 errors

parent 61b7b8b0
from django_tables2 import Table, A from django_tables2 import Table
from django_tables2.columns import LinkColumn, TemplateColumn, Column, BooleanColumn from django_tables2.columns import TemplateColumn, Column, BooleanColumn
from vm.models import Instance, Node from vm.models import Instance, Node
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -88,24 +88,17 @@ class NodeListTable(Table): ...@@ -88,24 +88,17 @@ class NodeListTable(Table):
) )
actions = TemplateColumn( actions = TemplateColumn(
attrs={'th': {'class': 'node-list-table-thin'}}, attrs={'th': {'class': 'node-list-table-thin'}},
template_code='{% include "dashboard/node-list/column-actions.html" with btn_size="btn-xs" %}', template_code=('{% include "dashboard/node-list/column-'
# actions = TemplateColumn('{% load my_filters %}{{ record.name|int_to_time }}' 'actions.html" with btn_size="btn-xs" %}'),
# attrs={'th': {'class': 'node-list-table-thin'},'extra_tag':},
) )
# time_of_suspend = TemplateColumn(
# '{{ record.time_of_suspend|timeuntil }}',
# verbose_name=_("Suspend in"))
# time_of_delete = TemplateColumn(
# '{{ record.time_of_delete|timeuntil }}',
# verbose_name=_("Delete in"))
class Meta: class Meta:
model = Node model = Node
attrs = {'class': ('table table-bordered table-striped table-hover ' attrs = {'class': ('table table-bordered table-striped table-hover '
'node-list-table')} 'node-list-table')}
fields = ('pk', 'name', 'host', 'enabled', 'priority', 'overcommit','number_of_VMs', ) fields = ('pk', 'name', 'host', 'enabled', 'priority', 'overcommit',
'number_of_VMs', )
class NodeVmListTable(Table): class NodeVmListTable(Table):
pk = TemplateColumn( pk = TemplateColumn(
......
...@@ -224,9 +224,8 @@ class VmDetailView(CheckedDetailView): ...@@ -224,9 +224,8 @@ class VmDetailView(CheckedDetailView):
def __add_port(self, request): def __add_port(self, request):
object = self.get_object() object = self.get_object()
if not object.has_level(request.user, 'owner'): if (not object.has_level(request.user, 'owner') or
raise PermissionDenied() not request.user.has_perm('vm.config_ports')):
if not request.user.has_perm('vm.config_ports'):
raise PermissionDenied() raise PermissionDenied()
port = request.POST.get("port") port = request.POST.get("port")
...@@ -254,10 +253,10 @@ class NodeDetailView(DetailView): ...@@ -254,10 +253,10 @@ class NodeDetailView(DetailView):
template_name = "dashboard/node-detail.html" template_name = "dashboard/node-detail.html"
model = Node model = Node
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(NodeDetailView, self).get_context_data(**kwargs) context = super(NodeDetailView, self).get_context_data(**kwargs)
context['table'] = NodeVmListTable(Instance.active.filter(node=self.object)) instances = Instance.active.filter(node=self.object)
context['table'] = NodeVmListTable(instances)
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
...@@ -287,7 +286,6 @@ class NodeDetailView(DetailView): ...@@ -287,7 +286,6 @@ class NodeDetailView(DetailView):
kwargs={'pk': self.object.pk})) kwargs={'pk': self.object.pk}))
class AclUpdateView(View, SingleObjectMixin): class AclUpdateView(View, SingleObjectMixin):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
...@@ -369,6 +367,7 @@ class VmList(SingleTableView): ...@@ -369,6 +367,7 @@ class VmList(SingleTableView):
table_class = VmListTable table_class = VmListTable
table_pagination = False table_pagination = False
class NodeList(SingleTableView): class NodeList(SingleTableView):
template_name = "dashboard/node-list.html" template_name = "dashboard/node-list.html"
model = Node model = Node
...@@ -449,6 +448,7 @@ class VmCreate(TemplateView): ...@@ -449,6 +448,7 @@ class VmCreate(TemplateView):
else: else:
return redirect(path) return redirect(path)
class NodeCreate(TemplateView): class NodeCreate(TemplateView):
def get_template_names(self): def get_template_names(self):
...@@ -525,7 +525,6 @@ class NodeCreate(TemplateView): ...@@ -525,7 +525,6 @@ class NodeCreate(TemplateView):
return redirect(reverse_lazy('dashboard.views.detail', resp)) return redirect(reverse_lazy('dashboard.views.detail', resp))
class VmDelete(DeleteView): class VmDelete(DeleteView):
model = Instance model = Instance
template_name = "dashboard/confirm/base-delete.html" template_name = "dashboard/confirm/base-delete.html"
...@@ -536,34 +535,6 @@ class VmDelete(DeleteView): ...@@ -536,34 +535,6 @@ class VmDelete(DeleteView):
else: else:
return ['dashboard/confirm/base-delete.html'] return ['dashboard/confirm/base-delete.html']
def get_context_data(self, **kwargs):
# this is redundant now, but if we wanna add more to print
# we'll need this
print kwargs
context = super(VmDelete, self).get_context_data(**kwargs)
return context
# github.com/django/django/blob/master/django/views/generic/edit.py#L245
def delete(self, request, *args, **kwargs):
object = self.get_object()
if not object.has_level(request.user, 'owner'):
raise PermissionDenied()
object.destroy_async(user=request.user)
success_url = self.get_success_url()
success_message = _("VM successfully deleted!")
if request.is_ajax():
if request.POST.get('redirect').lower() == "true":
messages.success(request, success_message)
return HttpResponse(
json.dumps({'message': success_message}),
content_type="application/json",
)
else:
messages.success(request, success_message)
return HttpResponseRedirect(success_url)
def get_success_url(self): def get_success_url(self):
next = self.request.POST.get('next') next = self.request.POST.get('next')
if next: if next:
...@@ -571,15 +542,6 @@ class VmDelete(DeleteView): ...@@ -571,15 +542,6 @@ class VmDelete(DeleteView):
else: else:
return reverse_lazy('dashboard.index') return reverse_lazy('dashboard.index')
model = Instance
template_name = "dashboard/confirm/base-delete.html"
def get_template_names(self):
if self.request.is_ajax():
return ['dashboard/confirm/ajax-delete.html']
else:
return ['dashboard/confirm/base-delete.html']
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# this is redundant now, but if we wanna add more to print # this is redundant now, but if we wanna add more to print
# we'll need this # we'll need this
...@@ -607,13 +569,6 @@ class VmDelete(DeleteView): ...@@ -607,13 +569,6 @@ class VmDelete(DeleteView):
messages.success(request, success_message) messages.success(request, success_message)
return HttpResponseRedirect(success_url) return HttpResponseRedirect(success_url)
def get_success_url(self):
next = self.request.POST.get('next')
if next:
return next
else:
return reverse_lazy('dashboard.index')
class NodeDelete(DeleteView): class NodeDelete(DeleteView):
...@@ -660,6 +615,7 @@ class NodeDelete(DeleteView): ...@@ -660,6 +615,7 @@ class NodeDelete(DeleteView):
else: else:
return reverse_lazy('dashboard.index') return reverse_lazy('dashboard.index')
class PortDelete(DeleteView): class PortDelete(DeleteView):
model = Rule model = Rule
pk_url_kwarg = 'rule' pk_url_kwarg = 'rule'
......
...@@ -41,7 +41,6 @@ class Node(TimeStampedModel): ...@@ -41,7 +41,6 @@ class Node(TimeStampedModel):
help_text=_("The ratio of total memory with " help_text=_("The ratio of total memory with "
"to without overcommit.")) "to without overcommit."))
class Meta: class Meta:
app_label = 'vm' app_label = 'vm'
db_table = 'vm_node' db_table = 'vm_node'
...@@ -63,12 +62,13 @@ class Node(TimeStampedModel): ...@@ -63,12 +62,13 @@ class Node(TimeStampedModel):
""" """
return self.remote_query(vm_tasks.get_core_num) return self.remote_query(vm_tasks.get_core_num)
@property @property
def state(self): def state(self):
"""Node state. """Node state.
""" """
if self.enabled and self.online : if self.enabled and self.online:
return 'online' return 'online'
elif self.enabled and not self.online: elif self.enabled and not self.online:
return 'missing' return 'missing'
...@@ -141,4 +141,5 @@ class Node(TimeStampedModel): ...@@ -141,4 +141,5 @@ class Node(TimeStampedModel):
@classmethod @classmethod
def get_state_count(cls, online, enabled): def get_state_count(cls, online, enabled):
return len([1 for i in cls.objects.filter(enabled=enabled).all() if i.online==online]) return len([1 for i in cls.objects.filter(enabled=enabled).all()
if i.online == online])
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