MCPcopy Create free account
hub / github.com/StackStorm/st2 / to_model

Method to_model

st2common/st2common/models/api/execution.py:175–197  ·  view source on GitHub ↗
(cls, instance)

Source from the content-addressed store, hash-verified

173
174 @classmethod
175 def to_model(cls, instance):
176 values = {}
177 for attr, meta in six.iteritems(cls.schema.get("properties", dict())):
178 if not getattr(instance, attr, None):
179 continue
180
181 default = fast_deepcopy_dict(meta.get("default", None))
182 value = getattr(instance, attr, default)
183
184 # pylint: disable=no-member
185 # TODO: Add plugin which lets pylint know each MongoEngine document has _fields
186 # attribute
187 attr_schema = cls.model._fields.get(attr, None)
188 if not value and (attr_schema and not attr_schema.required):
189 continue
190 if attr not in ActionExecutionAPI.SKIP:
191 values[attr] = value
192
193 values["start_timestamp"] = isotime.parse(instance.start_timestamp)
194 values["end_timestamp"] = isotime.parse(instance.end_timestamp)
195
196 model = cls.model(**values)
197 return model
198
199
200class ActionExecutionOutputAPI(BaseAPI):

Callers

nothing calls this directly

Calls 3

fast_deepcopy_dictFunction · 0.90
parseMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected