Move set_meta_options logic to the base Block class

pull/6730/head
Matt Westcott 2021-01-25 14:39:49 +00:00
rodzic d42b9b4a74
commit a8f41258b5
2 zmienionych plików z 9 dodań i 11 usunięć

Wyświetl plik

@ -127,15 +127,18 @@ class Block(metaclass=BaseBlock):
if not self.meta.label: if not self.meta.label:
self.label = capfirst(force_str(name).replace('_', ' ')) 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 Update this block's meta options (out of the ones designated as mutable) from the given dict.
from the StreamField constructor that ought to be handled by the block, e.g. 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) body = StreamField(SomeStreamBlock(), max_num=5)
""" """
# Ignore all options here; block types that are allowed at the top level (i.e. currently just for attr, value in opts.items():
# StreamBlock) and recognise these options will override this method if attr in self.MUTABLE_META_ATTRIBUTES:
pass setattr(self.meta, attr, value)
else:
raise TypeError("set_meta_options received unexpected option: %r" % attr)
@property @property
def media(self): def media(self):

Wyświetl plik

@ -51,11 +51,6 @@ class BaseStreamBlock(Block):
self.dependencies = self.child_blocks.values() 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): def get_default(self):
""" """
Default values set on a StreamBlock should be a list of (type_name, value) tuples - Default values set on a StreamBlock should be a list of (type_name, value) tuples -