@@ -200,6 +200,7 @@ def __init__(self, user_settings=None, defaults=None, import_strings=None):
200
200
self ._user_settings = self .__check_user_settings (user_settings )
201
201
self .defaults = defaults or DEFAULTS
202
202
self .import_strings = import_strings or IMPORT_STRINGS
203
+ self ._cached_attrs = set ()
203
204
204
205
@property
205
206
def user_settings (self ):
@@ -223,6 +224,7 @@ def __getattr__(self, attr):
223
224
val = perform_import (val , attr )
224
225
225
226
# Cache the result
227
+ self ._cached_attrs .add (attr )
226
228
setattr (self , attr , val )
227
229
return val
228
230
@@ -233,15 +235,21 @@ def __check_user_settings(self, user_settings):
233
235
raise RuntimeError ("The '%s' setting has been removed. Please refer to '%s' for available settings." % (setting , SETTINGS_DOC ))
234
236
return user_settings
235
237
238
+ def reload (self ):
239
+ for attr in self ._cached_attrs :
240
+ delattr (self , attr )
241
+ self ._cached_attrs .clear ()
242
+ if hasattr (self , '_user_settings' ):
243
+ delattr (self , '_user_settings' )
244
+
236
245
237
246
api_settings = APISettings (None , DEFAULTS , IMPORT_STRINGS )
238
247
239
248
240
249
def reload_api_settings (* args , ** kwargs ):
241
- global api_settings
242
- setting , value = kwargs ['setting' ], kwargs ['value' ]
250
+ setting = kwargs ['setting' ]
243
251
if setting == 'REST_FRAMEWORK' :
244
- api_settings = APISettings ( value , DEFAULTS , IMPORT_STRINGS )
252
+ api_settings . reload ( )
245
253
246
254
247
255
setting_changed .connect (reload_api_settings )
0 commit comments