Plugins and flexible field types#947
Closed
geigerzaehler wants to merge 22 commits intobeetbox:masterfrom
Closed
Conversation
added 22 commits
September 11, 2014 22:48
Removing a fixed field sets it to NULL in the database. If the model is loaded, all NULL values are passed to `Type.normalize()`, so attributes do not return `None`. Fixes beetbox#886.
We can now set model fields to `None`. `MediaFile` removes the tags corresponding to `None` fields. Hopefully fixes beetbox#157.
All field operations of a model use the methods of a `Type` instance to provide custom handling. Field operations include getting, setting, deleting and conversion to and from SQL. * There is a one-to-one mapping between SQL values and the values stored in the model. Conversion is done with `Type.from_sql()` and `Type.to_sql()`. `NULL` values in SQL are directly mapped to `None` values in the model * `Model[field]` retrieves the internal value stored in the model. For fixed field this either gives a value or `None`. For flex fields this may raise a `KeyError`. * `Model.get(field, default)` uses `Type.default` to replace missing and `None` values * `Model[field] = value` uses `Type.normalize()` to make sure internal values are consisten. Normalization is skipped for `None`. * `Model.set(field, value)` excpects a string value and uses `Type.parse()` to convert and normalize it to an internal value.
This abstraction allows us to generalise a lot of code. It also makes the the `normalize` method, and by extension assignment of values in models, more restrictive. I therefore had to fix a few test cases. For a description of the `model_type` property, see its documentation.
This partially solves beetbox#647.
Member
|
Awesome! At long last, this will be great to have. I've rebased the relevant commits in #951. |
Author
|
Superseded by #951. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is based on #919, so only the commits from 0477420 on are of interest. The PR accomplishes two things.
typesplugin lets the user configure the types of flexible fields.This means we can do the following.
TODO
Supersedes #445 and resolves #647.