From e48c17f2a355e44ca67c1e339ad5554150ce01d8 Mon Sep 17 00:00:00 2001 From: Vladimir Komarov Date: Tue, 13 Jul 2021 14:33:59 +0700 Subject: [PATCH 1/4] vak-1629 fixed web address content. --- services/web/apps/gis/building/views.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/services/web/apps/gis/building/views.py b/services/web/apps/gis/building/views.py index 4aceb0fa7a..733e15afc1 100644 --- a/services/web/apps/gis/building/views.py +++ b/services/web/apps/gis/building/views.py @@ -5,6 +5,11 @@ # See LICENSE for details # --------------------------------------------------------------------- +# Third-party modules +from django.http import HttpResponse +import orjson + + # NOC modules from noc.lib.app.extdocapplication import ExtDocApplication from noc.lib.app.docinline import DocInline @@ -40,3 +45,18 @@ class BuildingApplication(ExtDocApplication): if not a: return o.adm_division.full_path return a.display_ru(levels=10) + + def repair_content(self, content): + content["data"][0]["remote_system"] = str(content["data"][0]["remote_system"]) + return content + + def response(self, content="", status=200): + content = self.repair_content(content) + if not isinstance(content, str): + return HttpResponse( + orjson.dumps(content, option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NON_STR_KEYS), + content_type="text/json; charset=utf-8", + status=status, + ) + else: + return HttpResponse(content, content_type="text/plain; charset=utf-8", status=status) -- GitLab From 35c91edb46983dbe58e505cb03e4945eaae3a65d Mon Sep 17 00:00:00 2001 From: Vladimir Komarov Date: Tue, 13 Jul 2021 15:55:16 +0700 Subject: [PATCH 2/4] vak-1629 changed repair_content func. --- services/web/apps/gis/building/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/web/apps/gis/building/views.py b/services/web/apps/gis/building/views.py index 733e15afc1..8fd518d06a 100644 --- a/services/web/apps/gis/building/views.py +++ b/services/web/apps/gis/building/views.py @@ -47,7 +47,8 @@ class BuildingApplication(ExtDocApplication): return a.display_ru(levels=10) def repair_content(self, content): - content["data"][0]["remote_system"] = str(content["data"][0]["remote_system"]) + for c in content["data"]: + c["remote_system"] = str(c["remote_system"]) return content def response(self, content="", status=200): -- GitLab From 64e57c81543286bdb18ce2613494283e8330d5ef Mon Sep 17 00:00:00 2001 From: Vladimir Komarov Date: Wed, 14 Jul 2021 16:26:59 +0700 Subject: [PATCH 3/4] vak-1629 changed AddressInline. --- services/web/apps/gis/building/views.py | 56 ++++++++++++++++--------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/services/web/apps/gis/building/views.py b/services/web/apps/gis/building/views.py index 8fd518d06a..e61c44de24 100644 --- a/services/web/apps/gis/building/views.py +++ b/services/web/apps/gis/building/views.py @@ -1,14 +1,12 @@ # --------------------------------------------------------------------- # gis.building application # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2021 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- # Third-party modules -from django.http import HttpResponse -import orjson - +from mongoengine.fields import GeoPointField # NOC modules from noc.lib.app.extdocapplication import ExtDocApplication @@ -17,12 +15,46 @@ from noc.gis.models.division import Division from noc.gis.models.building import Building from noc.gis.models.address import Address from noc.core.translation import ugettext as _ +from noc.core.comp import smart_text +from noc.core.mongo.fields import PlainReferenceField, ForeignKeyField class AddressInline(DocInline): def field_text_address(self, o): return o.display_ru() + def instance_to_dict(self, o, fields=None): + r = {} + for n, f in o._fields.items(): + if fields and n not in fields: + continue + v = getattr(o, n) + if v is not None: + v = f.to_python(v) + if v is not None: + if isinstance(f, GeoPointField): + pass + elif isinstance(f, ForeignKeyField): + r["%s__label" % f.name] = smart_text(v) + v = v.id + elif isinstance(f, PlainReferenceField): + r["%s__label" % f.name] = smart_text(v) + if hasattr(v, "id"): + v = str(v.id) + else: + v = str(v) + elif not isinstance(v, int) and not isinstance(v, str) and not isinstance(v, bool): + if hasattr(v, "id"): + v = v.id + else: + v = smart_text(v) + r[n] = v + # Add custom fields + for f in self.custom_fields: + r[f] = self.custom_fields[f](o) + r["remote_system"] = smart_text(r["remote_system"]) + return r + class BuildingApplication(ExtDocApplication): """ @@ -45,19 +77,3 @@ class BuildingApplication(ExtDocApplication): if not a: return o.adm_division.full_path return a.display_ru(levels=10) - - def repair_content(self, content): - for c in content["data"]: - c["remote_system"] = str(c["remote_system"]) - return content - - def response(self, content="", status=200): - content = self.repair_content(content) - if not isinstance(content, str): - return HttpResponse( - orjson.dumps(content, option=orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_NON_STR_KEYS), - content_type="text/json; charset=utf-8", - status=status, - ) - else: - return HttpResponse(content, content_type="text/plain; charset=utf-8", status=status) -- GitLab From fbc555c2dcab7de7c39c20fb4ac6b87c76297d5f Mon Sep 17 00:00:00 2001 From: Vladimir Komarov Date: Wed, 14 Jul 2021 17:30:12 +0700 Subject: [PATCH 4/4] vak-1629 fixed instance_to_dict method. --- services/web/apps/gis/building/views.py | 33 +------------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/services/web/apps/gis/building/views.py b/services/web/apps/gis/building/views.py index e61c44de24..96395df6b6 100644 --- a/services/web/apps/gis/building/views.py +++ b/services/web/apps/gis/building/views.py @@ -5,9 +5,6 @@ # See LICENSE for details # --------------------------------------------------------------------- -# Third-party modules -from mongoengine.fields import GeoPointField - # NOC modules from noc.lib.app.extdocapplication import ExtDocApplication from noc.lib.app.docinline import DocInline @@ -16,7 +13,6 @@ from noc.gis.models.building import Building from noc.gis.models.address import Address from noc.core.translation import ugettext as _ from noc.core.comp import smart_text -from noc.core.mongo.fields import PlainReferenceField, ForeignKeyField class AddressInline(DocInline): @@ -24,34 +20,7 @@ class AddressInline(DocInline): return o.display_ru() def instance_to_dict(self, o, fields=None): - r = {} - for n, f in o._fields.items(): - if fields and n not in fields: - continue - v = getattr(o, n) - if v is not None: - v = f.to_python(v) - if v is not None: - if isinstance(f, GeoPointField): - pass - elif isinstance(f, ForeignKeyField): - r["%s__label" % f.name] = smart_text(v) - v = v.id - elif isinstance(f, PlainReferenceField): - r["%s__label" % f.name] = smart_text(v) - if hasattr(v, "id"): - v = str(v.id) - else: - v = str(v) - elif not isinstance(v, int) and not isinstance(v, str) and not isinstance(v, bool): - if hasattr(v, "id"): - v = v.id - else: - v = smart_text(v) - r[n] = v - # Add custom fields - for f in self.custom_fields: - r[f] = self.custom_fields[f](o) + r = super().instance_to_dict(o, fields=fields) r["remote_system"] = smart_text(r["remote_system"]) return r -- GitLab