django-orchestra-test/orchestra/apps/resources/actions.py

33 lines
1.2 KiB
Python
Raw Normal View History

2014-10-27 13:29:02 +00:00
from django.contrib import messages
from django.db import transaction
from django.shortcuts import redirect
from django.utils.translation import ungettext, ugettext_lazy as _
def run_monitor(modeladmin, request, queryset):
""" Resource and ResourceData run monitors """
referer = request.META.get('HTTP_REFERER')
if not queryset:
modeladmin.message_user(request, _("No resource has been selected,"))
return redirect(referer)
2014-10-27 13:29:02 +00:00
for resource in queryset:
resource.monitor()
modeladmin.log_change(request, resource, _("Run monitors"))
num = len(queryset)
async = resource.monitor.func_defaults[0]
if async:
# TODO schedulet link to celery taskstate page
msg = ungettext(
_("One selected resource has been scheduled for monitoring."),
_("%s selected resource have been scheduled for monitoring.") % num,
num)
else:
msg = ungettext(
_("One selected resource has been monitored."),
_("%s selected resource have been monitored.") % num,
num)
2014-10-27 13:29:02 +00:00
modeladmin.message_user(request, msg)
if referer:
return redirect(referer)
run_monitor.url_name = 'monitor'