@@ -11,16 +11,17 @@ class LookupChannelRegistry:
1111 This includes any installed apps that contain lookup.py modules (django 1.7+)
1212 and any lookups that are explicitly declared in `settings.AJAX_LOOKUP_CHANNELS`
1313 """
14+
1415 _registry = {}
1516
1617 def load_channels (self ):
1718 """
1819 Called when loading the application. Cannot be called a second time,
1920 (eg. for testing) as Django will not re-import and re-register anything.
2021 """
21- autodiscover_modules (' lookups' )
22+ autodiscover_modules (" lookups" )
2223
23- if hasattr (settings , ' AJAX_LOOKUP_CHANNELS' ):
24+ if hasattr (settings , " AJAX_LOOKUP_CHANNELS" ):
2425 self .register (settings .AJAX_LOOKUP_CHANNELS )
2526
2627 def register (self , lookup_specs ):
@@ -54,9 +55,10 @@ def get(self, channel):
5455
5556 try :
5657 lookup_spec = self ._registry [channel ]
57- except KeyError :
58+ except KeyError as e :
5859 raise ImproperlyConfigured (
59- f"No ajax_select LookupChannel named { channel !r} is registered." )
60+ f"No ajax_select LookupChannel named { channel !r} is registered."
61+ ) from e
6062
6163 if (type (lookup_spec ) is type ) and issubclass (lookup_spec , LookupChannel ):
6264 return lookup_spec ()
@@ -68,12 +70,12 @@ def get(self, channel):
6870 elif isinstance (lookup_spec , dict ):
6971 # 'channel' : dict(model='app.model', search_field='title' )
7072 # generate a simple channel dynamically
71- return self .make_channel (lookup_spec [' model' ], lookup_spec [' search_field' ])
73+ return self .make_channel (lookup_spec [" model" ], lookup_spec [" search_field" ])
7274 elif isinstance (lookup_spec , tuple ):
7375 # a tuple
7476 # 'channel' : ('app.module','LookupClass')
7577 # from app.module load LookupClass and instantiate
76- lookup_module = __import__ (lookup_spec [0 ], {}, {}, ['' ])
78+ lookup_module = __import__ (lookup_spec [0 ], {}, {}, ["" ])
7779 lookup_class = getattr (lookup_module , lookup_spec [1 ])
7880 return lookup_class ()
7981 else :
@@ -92,6 +94,7 @@ def make_channel(self, app_model, arg_search_field):
9294 LookupChannel
9395 """
9496 from ajax_select import LookupChannel
97+
9598 app_label , model_name = app_model .split ("." )
9699
97100 class MadeLookupChannel (LookupChannel ):
@@ -127,7 +130,7 @@ def format_item(self):
127130
128131 def _wrapper (lookup_class ):
129132 if not channel :
130- raise ValueError (' Lookup Channel must have a channel name' )
133+ raise ValueError (" Lookup Channel must have a channel name" )
131134
132135 registry .register ({channel : lookup_class })
133136
0 commit comments