Commit aae239c1 authored by Dmitry Volodin's avatar Dmitry Volodin
Browse files

Merge branch 'noc-1819-3' into 'master'

Exclude Auto generate fields from managedobject save.

See merge request noc/noc!6360
parents a18c2d8e d2acaffb
......@@ -29,6 +29,13 @@ class NOCModelBase(ModelBase):
# NB: Every hipster may be misused
if not is_base:
mcs.tuck_up_pants(m)
# Exclude non-update fields
if hasattr(m, "_non_update_fields"):
m._allow_update_fields = tuple(
field.name
for field in m._meta.fields
if field.name not in m._ignore_on_save and not field.primary_key
)
return m
@classmethod
......@@ -62,5 +69,5 @@ class NOCModelBase(ModelBase):
return kls
class NOCModel(object, metaclass=NOCModelBase):
pass
class NOCModel(Model, metaclass=NOCModelBase):
...
......@@ -616,6 +616,18 @@ class ManagedObject(NOCModel):
_e_labels_cache = cachetools.TTLCache(maxsize=1000, ttl=60)
_neighbor_cache = cachetools.TTLCache(1000, ttl=300)
_ignore_on_save = (
"caps",
"uplinks",
"links",
"rca_neighbors",
"dlm_windows",
"adm_path",
"segment_path",
"container_path",
"affected_maintenances",
)
def __str__(self):
return self.name
......@@ -1402,6 +1414,12 @@ class ManagedObject(NOCModel):
caps[cc.name] = c.get("value")
return caps
def save(self, **kwargs):
kwargs = kwargs or {}
if getattr(self, "_allow_update_fields", None) and "update_fields" not in kwargs:
kwargs["update_fields"] = self._allow_update_fields
super().save(**kwargs)
def update_caps(self, caps: Dict[str, Any], source: str) -> Dict[str, Any]:
"""
Update existing capabilities with a new ones.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment