Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow blocks to override Field defaults without copying the original field #169

Open
cpennington opened this issue Jan 24, 2014 · 4 comments

Comments

@cpennington
Copy link
Contributor

Currently, to change the default value of a field (such as display_name), a block needs to copy the definition. This means that if other values in the field need to change, they need to be changed in many places, which is subpar.

@cpennington
Copy link
Contributor Author

When this happens, accidentally overriding a field should raise an exception.

Proposal:

class FooBlock(XBlock):
    display_name = OverrideField(default='Foo Block')  # Uses the same field definition as the parent, with kwargs overridden
    tags = Field(...)  # raises an exception, because it hides a parent field
    name = OverrideField(scope=scope.user_state)  # Error, can't override the scope

@cpennington
Copy link
Contributor Author

@nedbat @jorr-at-google: Thoughts?

@nedbat
Copy link
Contributor

nedbat commented Jan 27, 2014

How often has a subclass wanted to keep a field but change its default? This seems like an odd operation to me. There must be some real examples we can look at, I know you didn't invent this for the fun of it.

@cpennington
Copy link
Contributor Author

We do it constantly for display_name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants