3939from .app_name import app_name , main_view_label
4040from .middleware import EmbeddedHolder
4141
42+ from .util import static_asset_path
43+ from .util import serve_locally as serve_locally_setting
4244
4345uid_counter = 0
4446
@@ -84,11 +86,12 @@ class DjangoDash:
8486 To use, construct an instance of DjangoDash() in place of a Dash() one.
8587 '''
8688 #pylint: disable=too-many-instance-attributes
87- def __init__ (self , name = None , serve_locally = False ,
89+ def __init__ (self , name = None , serve_locally = None ,
8890 expanded_callbacks = False ,
8991 add_bootstrap_links = False ,
9092 suppress_callback_exceptions = False ,
9193 ** kwargs ): # pylint: disable=unused-argument, too-many-arguments
94+
9295 if name is None :
9396 global uid_counter # pylint: disable=global-statement
9497 uid_counter += 1
@@ -104,19 +107,40 @@ def __init__(self, name=None, serve_locally=False,
104107 add_usable_app (self ._uid ,
105108 self )
106109
110+ if serve_locally is None :
111+ self ._serve_locally = serve_locally_setting ()
112+ else :
113+ self ._serve_locally = serve_locally
114+
107115 self ._expanded_callbacks = expanded_callbacks
108- self ._serve_locally = serve_locally
109116 self ._suppress_callback_exceptions = suppress_callback_exceptions
110117
111118 if add_bootstrap_links :
112119 from bootstrap4 .bootstrap import css_url
113120 bootstrap_source = css_url ()['href' ]
114- self .css .append_script ({'external_url' :[bootstrap_source ,]})
121+
122+ if self ._serve_locally :
123+ # Ensure package is loaded; if not present then pip install dpd-static-support
124+ import dpd_static_support
125+ hard_coded_package_name = "dpd_static_support"
126+ base_file_name = bootstrap_source .split ('/' )[- 1 ]
127+
128+ self .css .append_script ({'external_url' : [bootstrap_source ,],
129+ 'relative_package_path' : base_file_name ,
130+ 'namespace' : hard_coded_package_name ,
131+ })
132+ else :
133+ self .css .append_script ({'external_url' :[bootstrap_source ,],})
115134
116135 # Remember some caller info for static files
117136 caller_frame = inspect .stack ()[1 ]
118137 self .caller_module = inspect .getmodule (caller_frame [0 ])
119138 self .caller_module_location = inspect .getfile (self .caller_module )
139+ self .assets_folder = "assets"
140+
141+ def get_asset_static_url (self , asset_path ):
142+ module_name = self .caller_module .__name__
143+ return static_asset_path (module_name , asset_path )
120144
121145 def as_dash_instance (self , cache_id = None ):
122146 '''
@@ -205,6 +229,16 @@ def expanded_callback(self, output, inputs=[], state=[], events=[]): # pylint: d
205229 self ._expanded_callbacks = True
206230 return self .callback (output , inputs , state , events )
207231
232+ def get_asset_url (self , asset_name ):
233+ '''URL of an asset associated with this component
234+
235+ Use a placeholder and insert later
236+ '''
237+
238+ return "assets/" + str (asset_name )
239+
240+ #return self.as_dash_instance().get_asset_url(asset_name)
241+
208242class PseudoFlask :
209243 'Dummy implementation of a Flask instance, providing stub functionality'
210244 def __init__ (self ):
@@ -234,7 +268,8 @@ class WrappedDash(Dash):
234268 # pylint: disable=too-many-arguments, too-many-instance-attributes
235269 def __init__ (self ,
236270 base_pathname = None , replacements = None , ndid = None ,
237- expanded_callbacks = False , serve_locally = False , ** kwargs ):
271+ expanded_callbacks = False , serve_locally = False ,
272+ ** kwargs ):
238273
239274 self ._uid = ndid
240275
@@ -245,7 +280,8 @@ def __init__(self,
245280 kwargs ['url_base_pathname' ] = self ._base_pathname
246281 kwargs ['server' ] = self ._notflask
247282
248- super (WrappedDash , self ).__init__ (** kwargs )
283+ super (WrappedDash , self ).__init__ (__name__ ,
284+ ** kwargs )
249285
250286 self .css .config .serve_locally = serve_locally
251287 self .scripts .config .serve_locally = serve_locally
@@ -507,6 +543,8 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
507543
508544 def interpolate_index (self , ** kwargs ): #pylint: disable=arguments-differ
509545
546+ print ("IN INTERPOLATE INDEX" )
547+
510548 if not self ._return_embedded :
511549 resp = super (WrappedDash , self ).interpolate_index (** kwargs )
512550 return resp
0 commit comments