kopia lustrzana https://github.com/wagtail/wagtail
Move set_meta_options logic to the base Block class
rodzic
d42b9b4a74
commit
a8f41258b5
|
@ -127,15 +127,18 @@ class Block(metaclass=BaseBlock):
|
|||
if not self.meta.label:
|
||||
self.label = capfirst(force_str(name).replace('_', ' '))
|
||||
|
||||
def set_meta_options(self, options):
|
||||
def set_meta_options(self, opts):
|
||||
"""
|
||||
Called when this block is used as the top-level block of a StreamField, to pass on any options
|
||||
from the StreamField constructor that ought to be handled by the block, e.g.
|
||||
Update this block's meta options (out of the ones designated as mutable) from the given dict.
|
||||
Used by the StreamField constructor to pass on kwargs that are to be handled by the block,
|
||||
since the block object has already been created by that point, e.g.:
|
||||
body = StreamField(SomeStreamBlock(), max_num=5)
|
||||
"""
|
||||
# Ignore all options here; block types that are allowed at the top level (i.e. currently just
|
||||
# StreamBlock) and recognise these options will override this method
|
||||
pass
|
||||
for attr, value in opts.items():
|
||||
if attr in self.MUTABLE_META_ATTRIBUTES:
|
||||
setattr(self.meta, attr, value)
|
||||
else:
|
||||
raise TypeError("set_meta_options received unexpected option: %r" % attr)
|
||||
|
||||
@property
|
||||
def media(self):
|
||||
|
|
|
@ -51,11 +51,6 @@ class BaseStreamBlock(Block):
|
|||
|
||||
self.dependencies = self.child_blocks.values()
|
||||
|
||||
def set_meta_options(self, opts):
|
||||
for attr in ['required', 'min_num', 'max_num', 'block_counts']:
|
||||
if attr in opts:
|
||||
setattr(self.meta, attr, opts[attr])
|
||||
|
||||
def get_default(self):
|
||||
"""
|
||||
Default values set on a StreamBlock should be a list of (type_name, value) tuples -
|
||||
|
|
Ładowanie…
Reference in New Issue