Set the fields of a `dbcore.Model` object according to a dictionary. This is the opposite of `flatten`. The `data` dictionary should have strings as values.
(obj, data)
| 121 | |
| 122 | |
| 123 | def apply_(obj, data): |
| 124 | """Set the fields of a `dbcore.Model` object according to a |
| 125 | dictionary. |
| 126 | |
| 127 | This is the opposite of `flatten`. The `data` dictionary should have |
| 128 | strings as values. |
| 129 | """ |
| 130 | for key, value in data.items(): |
| 131 | if _safe_value(obj, key, value): |
| 132 | # A safe value *stayed* represented as a safe type. Assign it |
| 133 | # directly. |
| 134 | obj[key] = value |
| 135 | else: |
| 136 | # Either the field was stringified originally or the user changed |
| 137 | # it from a safe type to an unsafe one. Parse it as a string. |
| 138 | obj.set_parse(key, str(value)) |
| 139 | |
| 140 | |
| 141 | class EditPlugin(plugins.BeetsPlugin): |
no test coverage detected