Commit 028e8896 by Őry Máté

vm: add Instance.get_activities

parent 64f5b452
...@@ -207,11 +207,7 @@ class VmDetailView(CheckedDetailView): ...@@ -207,11 +207,7 @@ class VmDetailView(CheckedDetailView):
}) })
# activity data # activity data
context['activities'] = ( context['activities'] = self.object.get_activities(self.request.user)
InstanceActivity.objects.filter(
instance=self.object, parent=None).
order_by('-started').
select_related('user').prefetch_related('children'))
context['vlans'] = Vlan.get_objects_with_level( context['vlans'] = Vlan.get_objects_with_level(
'user', self.request.user 'user', self.request.user
...@@ -1683,9 +1679,7 @@ def vm_activity(request, pk): ...@@ -1683,9 +1679,7 @@ def vm_activity(request, pk):
if only_status == "false": # instance activity if only_status == "false": # instance activity
context = { context = {
'instance': instance, 'instance': instance,
'activities': InstanceActivity.objects.filter( 'activities': instance.get_activities(request.user),
instance=instance, parent=None
).order_by('-started').select_related(),
'ops': get_operations(instance, request.user), 'ops': get_operations(instance, request.user),
} }
...@@ -2290,10 +2284,8 @@ class InstanceActivityDetail(SuperuserRequiredMixin, DetailView): ...@@ -2290,10 +2284,8 @@ class InstanceActivityDetail(SuperuserRequiredMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
ctx = super(InstanceActivityDetail, self).get_context_data(**kwargs) ctx = super(InstanceActivityDetail, self).get_context_data(**kwargs)
ctx['activities'] = ( ctx['activities'] = self.object.instance.get_activities(
self.object.instance.activity_log.filter(parent=None). self.request.user)
order_by('-started').select_related('user').
prefetch_related('children'))
return ctx return ctx
......
...@@ -881,3 +881,9 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -881,3 +881,9 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
'PENDING': 'icon-rocket', 'PENDING': 'icon-rocket',
'DESTROYED': 'icon-trash', 'DESTROYED': 'icon-trash',
'MIGRATING': 'icon-truck'}.get(self.status, 'icon-question-sign') 'MIGRATING': 'icon-truck'}.get(self.status, 'icon-question-sign')
def get_activities(self, user=None):
acts = (self.activity_log.filter(parent=None).
order_by('-started').
select_related('user').prefetch_related('children'))
return acts
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