Skip to content
Snippets Groups Projects
Commit c88381f2 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Allow the __iter__ method to return display objects

parent 4a498690
No related branches found
No related tags found
No related merge requests found
...@@ -16,14 +16,23 @@ class MixedFieldMetaclass(DeclarativeFieldsMetaclass): ...@@ -16,14 +16,23 @@ class MixedFieldMetaclass(DeclarativeFieldsMetaclass):
class StreamBaseForm(BaseForm, metaclass=MixedFieldMetaclass): class StreamBaseForm(BaseForm, metaclass=MixedFieldMetaclass):
def swap_fields_for_display(func):
def wrapped(self, *args, **kwargs):
# Replaces the form fields with the display fields
# should only add new streamblocks and wont affect validation
fields = self.fields.copy()
self.fields = self.display
yield from func(self, *args, **kwargs)
self.fields = fields
return wrapped
@swap_fields_for_display
def __iter__(self):
yield from super().__iter__()
@swap_fields_for_display
def _html_output(self, *args, **kwargs): def _html_output(self, *args, **kwargs):
# Replaces the form fields with the display fields return super()._html_output(*args, **kwargs)
# should only add new streamblocks and wont affect validation
fields = self.fields.copy()
self.fields = self.display
render = super()._html_output(*args, **kwargs)
self.fields = fields
return render
class BlockFieldWrapper: class BlockFieldWrapper:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment