|
114 | 114 |
|
115 | 115 | """
|
116 | 116 |
|
| 117 | +import copy |
117 | 118 | import datetime
|
118 | 119 |
|
119 | 120 | from ... import ShotgunError
|
@@ -227,13 +228,48 @@ def schema_read(self):
|
227 | 228 | return self._schema
|
228 | 229 |
|
229 | 230 | def schema_field_create(self, entity_type, data_type, display_name, properties=None):
|
230 |
| - raise NotImplementedError |
| 231 | + _properties = { |
| 232 | + "data_type": {"editable": True, "value": None}, |
| 233 | + "description": {"editable": True, "value": ""}, |
| 234 | + "editable": {"editable": True, "value": True}, |
| 235 | + "entity_type": {"editable": True, "value": None}, |
| 236 | + "mandatory": {"editable": True, "value": False}, |
| 237 | + "name": {"editable": True, "value": None}, |
| 238 | + "properties": { |
| 239 | + "default_value": {"editable": True, "value": None}, |
| 240 | + "regex_validation": {"editable": True, "value": ""}, |
| 241 | + "regex_validation_enabled": {"editable": True, "value": None}, |
| 242 | + "summary_default": {"editable": True, "value": "none"} |
| 243 | + }, |
| 244 | + "ui_value_displayable": {"editable": True, "value": True}, |
| 245 | + "unique": {"editable": True, "value": True}, |
| 246 | + "visible": {"editable": True, "value": True} |
| 247 | + } |
| 248 | + _properties["entity_type"]["value"] = entity_type |
| 249 | + _properties["entity_type"]["editable"] = False |
| 250 | + |
| 251 | + _properties["data_type"]["value"] = data_type |
| 252 | + _properties["data_type"]["editable"] = False |
| 253 | + |
| 254 | + _properties["name"]["value"] = display_name |
| 255 | + _properties["name"]["editable"] = False |
| 256 | + |
| 257 | + if isinstance(properties, dict) and properties: |
| 258 | + for prop in properties: |
| 259 | + self._set_property(_properties, prop, properties[prop]) |
| 260 | + |
| 261 | + self._schema[entity_type][display_name] = _properties |
231 | 262 |
|
232 | 263 | def schema_field_update(self, entity_type, field_name, properties):
|
233 |
| - raise NotImplementedError |
| 264 | + _properties = copy.deepcopy(self._schema[entity_type][field_name]) |
| 265 | + for key in properties: |
| 266 | + self._set_property(_properties, key, properties[key]) |
| 267 | + self._schema[entity_type][field_name] = _properties |
234 | 268 |
|
235 | 269 | def schema_field_delete(self, entity_type, field_name):
|
236 |
| - raise NotImplementedError |
| 270 | + if field_name not in self._schema[entity_type]: |
| 271 | + return |
| 272 | + del self._schema[entity_type][field_name] |
237 | 273 |
|
238 | 274 | def schema_entity_read(self):
|
239 | 275 | return self._schema_entity
|
@@ -422,8 +458,29 @@ def upload(self, entity_type, entity_id, path, field_name=None, display_name=Non
|
422 | 458 | def upload_thumbnail(self, entity_type, entity_id, path, **kwargs):
|
423 | 459 | pass
|
424 | 460 |
|
| 461 | + def dump_schemas(self): |
| 462 | + schema_path, schema_entity_path = self.get_schema_paths() |
| 463 | + SchemaFactory.set_schemas(self.schema_read(), schema_path, self.schema_entity_read(), schema_entity_path) |
| 464 | + |
425 | 465 | ###################################################################################################
|
426 | 466 | # internal methods and members
|
| 467 | + @classmethod |
| 468 | + def _set_property(cls, property_data, property_key, property_value): |
| 469 | + result = False |
| 470 | + for key in property_data: |
| 471 | + if key == property_key: |
| 472 | + property_data[key]["value"] = property_value |
| 473 | + result = True |
| 474 | + break |
| 475 | + elif isinstance(property_data[key], dict): |
| 476 | + _result = cls._set_property(property_data[key], property_key, property_value) |
| 477 | + if _result is True: |
| 478 | + result = _result |
| 479 | + break |
| 480 | + if result is False and "properties" in property_data: |
| 481 | + property_data["properties"][property_key] = {"editable": True, "value": property_value} |
| 482 | + result = True |
| 483 | + return result |
427 | 484 |
|
428 | 485 | def _validate_entity_type(self, entity_type):
|
429 | 486 | if entity_type not in self._schema:
|
|
0 commit comments