From 550c541215b662c13c8a6dd8161fad7494a7c412 Mon Sep 17 00:00:00 2001 From: bashmak Date: Fri, 6 Apr 2018 15:44:23 +0300 Subject: [PATCH] Fix status updating --- devapp/views.py | 2 +- mapapp/templates/maps/ya_index.html | 5 +++-- mapapp/views.py | 31 +++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/devapp/views.py b/devapp/views.py index 13df1c7..9a246d2 100644 --- a/devapp/views.py +++ b/devapp/views.py @@ -591,7 +591,7 @@ def nagios_objects_conf(request): "}\n" ]) - def norm_name(name: str, replreg=re.compile(r'\W+', re.IGNORECASE)): + def norm_name(name: str, replreg=re.compile(r'\W{1,255}', re.IGNORECASE)): return replreg.sub('', name) for dev in Device.objects.exclude(devtype='On', ip_address='127.0.0.1').select_related('parent_dev').only('ip_address', 'comment', 'parent_dev'): diff --git a/mapapp/templates/maps/ya_index.html b/mapapp/templates/maps/ya_index.html index b8c6e39..916a66a 100644 --- a/mapapp/templates/maps/ya_index.html +++ b/mapapp/templates/maps/ya_index.html @@ -117,7 +117,7 @@ } function get_placemark_states(){ - $.getJSON("{% url 'mapapp:get_dots' %}", update_placemark_states); + $.getJSON("{% url 'mapapp:get_dots' %}?is_obtain_pk=on", update_placemark_states); } /* @@ -132,7 +132,8 @@ if(server_info === undefined) continue; var r = get_params_for_placemark(server_info); - placemark.events.remove('click'); + placemark.events.remove('click', open_in_new_window); + placemark.events.remove('click', placemark_click); placemark.events.add('click', r[1]); placemark.options.set({'iconImageHref': '/static/img/gmarkers/' + r[0]}); } diff --git a/mapapp/views.py b/mapapp/views.py index ca580e6..e9c38d3 100644 --- a/mapapp/views.py +++ b/mapapp/views.py @@ -109,14 +109,29 @@ def get_dots(request): 'comment': dev.comment } if dev is not None else None - res = [{ - 'devcount': e.devcount, - 'latitude': e.latitude, - 'longitude': e.longitude, - 'title': e.title, - 'pk': e.pk, - 'device': fill_dev(e.devices.first()) - } for e in dots] + is_obtain_pk = request.GET.get('is_obtain_pk') + + if is_obtain_pk == 'on': + res = dict() + for e in dots: + res[str(e.pk)] = { + 'devcount': e.devcount, + 'latitude': e.latitude, + 'longitude': e.longitude, + 'title': e.title, + 'pk': e.pk, + 'device': fill_dev(e.devices.first()) + } + else: + res = [{ + 'devcount': e.devcount, + 'latitude': e.latitude, + 'longitude': e.longitude, + 'title': e.title, + 'pk': e.pk, + 'device': fill_dev(e.devices.first()) + } for e in dots] + return res