@@ -96,21 +96,18 @@ def has_gist_block(value):
96
96
if not isinstance (value , StreamValue ):
97
97
return False
98
98
99
- for block in value ._raw_data :
100
- # special case for work page section block as the streamfields are nested within sections
101
- if block ["type" ] == "section" :
102
- try :
103
- for sub_block in block ["value" ]["content" ]:
104
- if (
105
- sub_block ["type" ] == "raw_html"
106
- and "https://gist.github.com" in sub_block ["value" ]
107
- ):
108
- return True
109
- except (KeyError , TypeError ):
110
- pass
111
-
112
- if block ["type" ] == "raw_html" and "https://gist.github.com" in block ["value" ]:
99
+ for block in value .blocks_by_name (block_name = "raw_html" ):
100
+ if "https://gist.github.com" in block .value :
113
101
return True
102
+
103
+ # Special case for work page section block as the StreamField blockss are nested within sections
104
+ for block in value .blocks_by_name (block_name = "section" ):
105
+ if "content" not in block .value :
106
+ continue
107
+ for sub_block in block .value ["content" ].blocks_by_name ("raw_html" ):
108
+ if "https://gist.github.com" in sub_block .value :
109
+ return True
110
+
114
111
return False
115
112
116
113
@@ -119,15 +116,14 @@ def has_markdown_block(value):
119
116
if not isinstance (value , StreamValue ):
120
117
return False
121
118
122
- for block in value ._raw_data :
123
- if block ["type" ] == "section" :
124
- try :
125
- for sub_block in block ["value" ]["content" ]:
126
- if sub_block ["type" ] == "markdown" :
127
- return True
128
- except (KeyError , TypeError ):
129
- pass
130
- if block ["type" ] == "markdown" :
119
+ if len (value .blocks_by_name (block_name = "markdown" )):
120
+ return True
121
+
122
+ # Special case for work page section block as the StreamField blockss are nested within sections
123
+ for block in value .blocks_by_name (block_name = "section" ):
124
+ if "content" not in block .value :
125
+ continue
126
+ if len (block .value ["content" ].blocks_by_name ("markdown" )):
131
127
return True
132
128
133
129
return False
0 commit comments