diff --git a/abonapp/locale/ru/LC_MESSAGES/django.po b/abonapp/locale/ru/LC_MESSAGES/django.po
index c3328c8..40513ea 100644
--- a/abonapp/locale/ru/LC_MESSAGES/django.po
+++ b/abonapp/locale/ru/LC_MESSAGES/django.po
@@ -787,6 +787,9 @@ msgstr "Поле или одно из полей не найдено"
msgid "ok ping, %d/%d loses"
msgstr "пингуется, %d/%d"
+msgid "no ping, %d/%d loses"
+msgstr "не пингуется, %d/%d"
+
msgid "no ping"
msgstr "не пингуется"
diff --git a/abonapp/views.py b/abonapp/views.py
index ebda7d5..ae74fe6 100644
--- a/abonapp/views.py
+++ b/abonapp/views.py
@@ -829,36 +829,34 @@ def extra_field_delete(request, gid, uid, fid):
def abon_ping(request):
ip = request.GET.get('cmd_param')
status = False
- text = _('no ping')
+ text = ' %s' % _('no ping')
try:
tm = Transmitter()
- r = tm.ping(ip)
- if r is None:
+ ping_result = tm.ping(ip)
+ if ping_result is None:
if mydefs.ping(ip, 10):
status = True
- text = _('ping ok')
+ text = ' %s' % _('ping ok')
else:
- if type(r) is tuple:
- text = _('ok ping, %d/%d loses') % r
+ if type(ping_result) is tuple:
+ loses_percent = (ping_result[0] / ping_result[1])
+ if loses_percent > 0.5:
+ text = ' %s' % _('ok ping, %d/%d loses') % ping_result
+ status = True
+ else:
+ text = ' %s' % _('no ping, %d/%d loses') % ping_result
else:
- text = _('ping ok') + ' ' + str(r)
- status = True
+ text = ' %s' % _('ping ok') + ' ' + str(ping_result)
+ status = True
except NasFailedResult as e:
messages.error(request, e)
except NasNetworkError as e:
messages.warning(request, e)
- if status:
- status = 0
- res = ' %s' % text
- else:
- status = 1
- res = ' %s' % text
-
return HttpResponse(dumps({
- 'status': status,
- 'dat': res
+ 'status': 0 if status else 1,
+ 'dat': text
}))