19
19
#-----------------------------------------------------------------------------
20
20
21
21
from warnings import warn
22
-
22
+ import os
23
23
from ..utils .base import NbConvertBase
24
24
25
25
__all__ = ['WidgetsDataTypeFilter' ]
@@ -33,13 +33,13 @@ class WidgetsDataTypeFilter(NbConvertBase):
33
33
""" Returns the preferred display format, excluding the widget output if
34
34
there is no widget state available """
35
35
36
- def __init__ (self , notebook_metadata = None , ** kwargs ):
37
- metadata = notebook_metadata or {}
38
-
39
- self . widgets_state = (
40
- metadata [ 'widgets' ][ WIDGET_STATE_MIMETYPE ][ 'state' ] if
41
- metadata .get ('widgets' ) is not None else {}
42
- )
36
+ def __init__ (self , notebook_metadata = None , resources = None , ** kwargs ):
37
+ self . metadata = notebook_metadata
38
+ self . notebook_path = ''
39
+ if resources is not None :
40
+ name = resources . get ( ' metadata' , {}). get ( 'name' , '' )
41
+ path = resources .get ('metadata' , {}). get ( 'path' , '' )
42
+ self . notebook_path = os . path . join ( path , name )
43
43
44
44
super ().__init__ (** kwargs )
45
45
@@ -51,12 +51,17 @@ def __call__(self, output):
51
51
`output` is dict with structure {mimetype-of-element: value-of-element}
52
52
53
53
"""
54
+ metadata = self .metadata .get (self .notebook_path , {})
55
+ widgets_state = (
56
+ metadata ['widgets' ][WIDGET_STATE_MIMETYPE ]['state' ] if
57
+ metadata .get ('widgets' ) is not None else {}
58
+ )
54
59
for fmt in self .display_data_priority :
55
60
if fmt in output :
56
61
# If there is no widget state available, we skip this mimetype
57
62
if (
58
63
fmt == WIDGET_VIEW_MIMETYPE and
59
- output [WIDGET_VIEW_MIMETYPE ]['model_id' ] not in self . widgets_state
64
+ output [WIDGET_VIEW_MIMETYPE ]['model_id' ] not in widgets_state
60
65
):
61
66
continue
62
67
0 commit comments