Replace deprecated stream_data with raw_data
This commit is contained in:
parent
cf66702d75
commit
41bbfd7177
|
|
@ -18,15 +18,15 @@ logger = logging.getLogger(__name__)
|
||||||
class GenericStreamFieldType(Scalar):
|
class GenericStreamFieldType(Scalar):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def serialize(stream_value):
|
def serialize(stream_value):
|
||||||
stream_data = stream_value.stream_data
|
raw_data = stream_value.raw_data
|
||||||
return augment_fields(stream_data)
|
return augment_fields(raw_data)
|
||||||
|
|
||||||
# by_api = stream_value.stream_block.get_api_representation(stream_value)
|
# by_api = stream_value.stream_block.get_api_representation(stream_value)
|
||||||
# return by_api
|
# return by_api
|
||||||
|
|
||||||
|
|
||||||
def augment_fields(stream_data):
|
def augment_fields(raw_data):
|
||||||
for data in stream_data:
|
for data in raw_data:
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
_type = data['type']
|
_type = data['type']
|
||||||
if _type == 'image_block':
|
if _type == 'image_block':
|
||||||
|
|
@ -88,7 +88,7 @@ def augment_fields(stream_data):
|
||||||
item_data = data['value']
|
item_data = data['value']
|
||||||
data['value'] = augment_fields(item_data)
|
data['value'] = augment_fields(item_data)
|
||||||
|
|
||||||
return stream_data
|
return raw_data
|
||||||
|
|
||||||
|
|
||||||
@convert_django_field.register(StreamField)
|
@convert_django_field.register(StreamField)
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ class ContentBlock(StrictHierarchyPage):
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
for data in self.contents.stream_data:
|
for data in self.contents.raw_data:
|
||||||
block_type, value = get_type_and_value(data)
|
block_type, value = get_type_and_value(data)
|
||||||
|
|
||||||
if block_type == 'survey':
|
if block_type == 'survey':
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,9 @@ class ContentBlockNode(DjangoObjectType, HiddenAndVisibleForMixin):
|
||||||
return parent.owner is not None and parent.owner.pk == info.context.user.pk
|
return parent.owner is not None and parent.owner.pk == info.context.user.pk
|
||||||
|
|
||||||
def resolve_contents(self, info, **kwargs):
|
def resolve_contents(self, info, **kwargs):
|
||||||
updated_stream_data = []
|
updated_raw_data = []
|
||||||
for content in self.contents.stream_data:
|
# todo: deprecated as of wagtail 2.12 https://docs.wagtail.io/en/stable/releases/2.12.html
|
||||||
|
for content in self.contents.raw_data:
|
||||||
# only show solutions to teachers and students for whom their teachers have them enabled
|
# only show solutions to teachers and students for whom their teachers have them enabled
|
||||||
if is_solution_and_hidden_for_user(content['type'], info.context.user, self.module):
|
if is_solution_and_hidden_for_user(content['type'], info.context.user, self.module):
|
||||||
logger.debug('Solution is hidden for this user')
|
logger.debug('Solution is hidden for this user')
|
||||||
|
|
@ -68,9 +69,10 @@ class ContentBlockNode(DjangoObjectType, HiddenAndVisibleForMixin):
|
||||||
content['value'][index] = process_module_room_slug_block(list_block)
|
content['value'][index] = process_module_room_slug_block(list_block)
|
||||||
|
|
||||||
content = process_module_room_slug_block(content)
|
content = process_module_room_slug_block(content)
|
||||||
updated_stream_data.append(content)
|
updated_raw_data.append(content)
|
||||||
|
|
||||||
self.contents.stream_data = updated_stream_data
|
# todo: deprecated as of wagtail 2.12 https://docs.wagtail.io/en/stable/releases/2.12.html
|
||||||
|
self.contents.raw_data = updated_raw_data
|
||||||
return self.contents
|
return self.contents
|
||||||
|
|
||||||
def resolve_bookmarks(self, info, **kwargs):
|
def resolve_bookmarks(self, info, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -28,31 +28,31 @@ def do_after_page_edit(request, page):
|
||||||
|
|
||||||
|
|
||||||
def get_room_blocks(page):
|
def get_room_blocks(page):
|
||||||
top_level_module_room_slug_blocks = get_block_from_stream_data(page.contents.stream_data, 'module_room_slug')
|
top_level_module_room_slug_blocks = get_block_from_raw_data(page.contents.raw_data, 'module_room_slug')
|
||||||
content_list_module_room_slug_blocks = get_admin_slugs_from_content_list(page.contents.stream_data)
|
content_list_module_room_slug_blocks = get_admin_slugs_from_content_list(page.contents.raw_data)
|
||||||
return top_level_module_room_slug_blocks + content_list_module_room_slug_blocks
|
return top_level_module_room_slug_blocks + content_list_module_room_slug_blocks
|
||||||
|
|
||||||
|
|
||||||
def get_block_from_stream_data(stream_data, block_name):
|
def get_block_from_raw_data(raw_data, block_name):
|
||||||
if len(stream_data) == 0:
|
if len(raw_data) == 0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if isinstance(stream_data[0], tuple):
|
if isinstance(raw_data[0], tuple):
|
||||||
return [block for block in stream_data if block[0] in [block_name]]
|
return [block for block in raw_data if block[0] in [block_name]]
|
||||||
if isinstance(stream_data[0], dict):
|
if isinstance(raw_data[0], dict):
|
||||||
return [block for block in stream_data if block['type'] in [block_name]]
|
return [block for block in raw_data if block['type'] in [block_name]]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def get_admin_slugs_from_content_list(stream_data):
|
def get_admin_slugs_from_content_list(raw_data):
|
||||||
module_room_slug_blocks = []
|
module_room_slug_blocks = []
|
||||||
content_list_items = get_block_from_stream_data(stream_data, 'content_list_item')
|
content_list_items = get_block_from_raw_data(raw_data, 'content_list_item')
|
||||||
for content_list_item in content_list_items:
|
for content_list_item in content_list_items:
|
||||||
stream_data = None
|
raw_data = None
|
||||||
if isinstance(content_list_item, tuple):
|
if isinstance(content_list_item, tuple):
|
||||||
stream_data = content_list_item[1]
|
raw_data = content_list_item[1]
|
||||||
if isinstance(content_list_item, dict):
|
if isinstance(content_list_item, dict):
|
||||||
stream_data = content_list_item['value']
|
raw_data = content_list_item['value']
|
||||||
module_room_slug_blocks = module_room_slug_blocks + get_block_from_stream_data(stream_data,
|
module_room_slug_blocks = module_room_slug_blocks + get_block_from_raw_data(raw_data,
|
||||||
'module_room_slug')
|
'module_room_slug')
|
||||||
return module_room_slug_blocks
|
return module_room_slug_blocks
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue