Improved performance of resource data changelist
This commit is contained in:
parent
8feac931c6
commit
50c2397924
5
TODO.md
5
TODO.md
|
@ -175,12 +175,9 @@ Remember that, as always with QuerySets, any subsequent chained methods which im
|
||||||
* admin systemuser home/directory, add default home and empty directory with has_shell on admin
|
* admin systemuser home/directory, add default home and empty directory with has_shell on admin
|
||||||
|
|
||||||
|
|
||||||
* Backendlog doesn't show during execution, transaction isolation or what?
|
|
||||||
|
|
||||||
* Resource used_list_display=True, allocated_list_displat=True, allow resources to show up on list_display
|
* Resource used_list_display=True, allocated_list_displat=True, allow resources to show up on list_display
|
||||||
|
|
||||||
|
|
||||||
* Move plugins back from apps to orchestra main app
|
* Move plugins back from apps to orchestra main app
|
||||||
|
|
||||||
|
* BackendLog.updated_at (tasks that run over several minutes when finished they do not appear first on the changelist) (like celery tasks.when)
|
||||||
* BackendLog.updated_at (tasks that run over several minutes when finished they do not appear first on the changelist)
|
|
||||||
|
|
|
@ -112,11 +112,12 @@ def Python(backend, log, server, cmds, async=False):
|
||||||
script = json.dumps(script, indent=4).replace('"', '')
|
script = json.dumps(script, indent=4).replace('"', '')
|
||||||
log.script = '\n'.join([log.script, script])
|
log.script = '\n'.join([log.script, script])
|
||||||
log.save(update_fields=['script'])
|
log.save(update_fields=['script'])
|
||||||
stdout = ''
|
|
||||||
try:
|
try:
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
result = cmd(server)
|
result = cmd(server)
|
||||||
stdout += str(result)
|
log.stdout += str(result)
|
||||||
|
if async:
|
||||||
|
log.save(update_fields=['stdout'])
|
||||||
except:
|
except:
|
||||||
log.exit_code = 1
|
log.exit_code = 1
|
||||||
log.state = log.FAILURE
|
log.state = log.FAILURE
|
||||||
|
@ -124,5 +125,4 @@ def Python(backend, log, server, cmds, async=False):
|
||||||
else:
|
else:
|
||||||
log.exit_code = 0
|
log.exit_code = 0
|
||||||
log.state = log.SUCCESS
|
log.state = log.SUCCESS
|
||||||
log.stdout += stdout
|
|
||||||
log.save()
|
log.save()
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
from django.conf.urls import patterns, url
|
||||||
from django.contrib import admin, messages
|
from django.contrib import admin, messages
|
||||||
from django.contrib.admin.utils import unquote
|
from django.contrib.admin.utils import unquote
|
||||||
from django.contrib.contenttypes import generic
|
from django.contrib.contenttypes import generic
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.shortcuts import redirect
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ungettext, ugettext, ugettext_lazy as _
|
from django.utils.translation import ungettext, ugettext, ugettext_lazy as _
|
||||||
|
@ -95,13 +97,25 @@ class ResourceDataAdmin(ExtendedModelAdmin):
|
||||||
actions = (run_monitor,)
|
actions = (run_monitor,)
|
||||||
change_view_actions = actions
|
change_view_actions = actions
|
||||||
ordering = ('-updated_at',)
|
ordering = ('-updated_at',)
|
||||||
list_select_related = ('resource',)
|
list_select_related = ('resource__content_type',)
|
||||||
prefetch_related = ('content_object',)
|
prefetch_related = ('content_object',)
|
||||||
|
|
||||||
resource_link = admin_link('resource')
|
resource_link = admin_link('resource')
|
||||||
content_object_link = admin_link('content_object')
|
content_object_link = admin_link('content_object')
|
||||||
display_updated = admin_date('updated_at', short_description=_("Updated"))
|
display_updated = admin_date('updated_at', short_description=_("Updated"))
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
"""Returns the additional urls for the change view links"""
|
||||||
|
urls = super(ResourceDataAdmin, self).get_urls()
|
||||||
|
admin_site = self.admin_site
|
||||||
|
opts = self.model._meta
|
||||||
|
return patterns('',
|
||||||
|
url('^(\d+)/used-monitordata/$',
|
||||||
|
admin_site.admin_view(self.used_monitordata_view),
|
||||||
|
name='%s_%s_used_monitordata' % (opts.app_label, opts.model_name)
|
||||||
|
)
|
||||||
|
) + urls
|
||||||
|
|
||||||
def display_unit(self, data):
|
def display_unit(self, data):
|
||||||
return data.unit
|
return data.unit
|
||||||
display_unit.short_description = _("Unit")
|
display_unit.short_description = _("Unit")
|
||||||
|
@ -110,6 +124,21 @@ class ResourceDataAdmin(ExtendedModelAdmin):
|
||||||
def display_used(self, data):
|
def display_used(self, data):
|
||||||
if not data.used:
|
if not data.used:
|
||||||
return ''
|
return ''
|
||||||
|
url = reverse('admin:resources_resourcedata_used_monitordata', args=(data.pk,))
|
||||||
|
return '<a href="%s">%s</a>' % (url, data.used)
|
||||||
|
display_used.short_description = _("Used")
|
||||||
|
display_used.admin_order_field = 'used'
|
||||||
|
display_used.allow_tags = True
|
||||||
|
|
||||||
|
def has_add_permission(self, *args, **kwargs):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def used_monitordata_view(self, request, object_id):
|
||||||
|
"""
|
||||||
|
Does the redirect on a separated view for performance reassons
|
||||||
|
(calculate this on a changelist is expensive)
|
||||||
|
"""
|
||||||
|
data = self.get_object(request, object_id)
|
||||||
ids = []
|
ids = []
|
||||||
for dataset in data.get_monitor_datasets():
|
for dataset in data.get_monitor_datasets():
|
||||||
if isinstance(dataset, MonitorData):
|
if isinstance(dataset, MonitorData):
|
||||||
|
@ -118,12 +147,7 @@ class ResourceDataAdmin(ExtendedModelAdmin):
|
||||||
ids += dataset.values_list('id', flat=True)
|
ids += dataset.values_list('id', flat=True)
|
||||||
url = reverse('admin:resources_monitordata_changelist')
|
url = reverse('admin:resources_monitordata_changelist')
|
||||||
url += '?id__in=%s' % ','.join(map(str, ids))
|
url += '?id__in=%s' % ','.join(map(str, ids))
|
||||||
return '<a href="%s">%s</a>' % (url, data.used)
|
return redirect(url)
|
||||||
display_used.short_description = _("Used")
|
|
||||||
display_used.allow_tags = True
|
|
||||||
|
|
||||||
def has_add_permission(self, *args, **kwargs):
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class MonitorDataAdmin(ExtendedModelAdmin):
|
class MonitorDataAdmin(ExtendedModelAdmin):
|
||||||
|
|
Loading…
Reference in New Issue