예제 #1
0
파일: base.py 프로젝트: swamim/eNMS
 def update(self, instance_type, **kwargs):
     try:
         must_be_new = kwargs.get("id") == ""
         for arg in ("name", "scoped_name"):
             if arg in kwargs:
                 kwargs[arg] = kwargs[arg].strip()
         kwargs["last_modified"] = self.get_time()
         kwargs["creator"] = kwargs["user"] = getattr(
             current_user, "name", "admin")
         instance = factory(instance_type,
                            must_be_new=must_be_new,
                            **kwargs)
         if kwargs.get("original"):
             fetch(instance_type,
                   id=kwargs["original"]).duplicate(clone=instance)
         Session.flush()
         return instance.serialized
     except Exception as exc:
         Session.rollback()
         if isinstance(exc, IntegrityError):
             return {
                 "alert":
                 (f"There already is a {instance_type} with the same name")
             }
         return {"alert": str(exc)}
예제 #2
0
파일: base.py 프로젝트: Trungmaster5/eNMS
 def update(self, cls: str, **kwargs: Any) -> dict:
     try:
         must_be_new = kwargs.get("id") == ""
         kwargs["last_modified"] = self.get_time()
         kwargs["creator"] = getattr(current_user, "name", "admin")
         instance = factory(cls, must_be_new=must_be_new, **kwargs)
         Session.flush()
         return instance.serialized
     except Exception as exc:
         Session.rollback()
         if isinstance(exc, IntegrityError):
             return {"error": (f"There already is a {cls} with the same name")}
         return {"error": str(exc)}