@@ -261,21 +261,28 @@ def options(self, request, pk=None):
261261
262262 # check if the optionset belongs to this catalog and if it has a provider
263263 project .catalog .prefetch_elements ()
264- if Question .objects .filter_by_catalog (project .catalog ).filter (optionsets = optionset ) and \
265- optionset .provider is not None :
264+ if (
265+ Question .objects .filter_by_catalog (project .catalog ).filter (optionsets = optionset )
266+ and optionset .has_plugins
267+ ):
266268 options = []
267- for option in optionset .provider .get_options (project , search = request .GET .get ('search' ),
268- user = request .user , site = request .site ):
269- if 'id' not in option :
270- raise RuntimeError (f"'id' is missing in options of '{ optionset .provider .class_name } '" )
271- elif 'text' not in option :
272- raise RuntimeError (f"'text' is missing in options of '{ optionset .provider .class_name } '" )
273- if 'text_and_help' not in option :
274- if 'help' in option :
275- option ['text_and_help' ] = '{text} [{help}]' .format (** option )
276- else :
277- option ['text_and_help' ] = '{text}' .format (** option )
278- options .append (option )
269+ for plugin in optionset .plugins .all ():
270+ provider = plugin .initialize_class ()
271+ if provider is None :
272+ continue # skip when plugin class initialization fails
273+
274+ for option in provider .get_options (project , search = request .GET .get ('search' ),
275+ user = request .user , site = request .site ):
276+ if 'id' not in option :
277+ raise RuntimeError (f"'id' is missing in options of '{ provider .class_name } '" )
278+ elif 'text' not in option :
279+ raise RuntimeError (f"'text' is missing in options of '{ provider .class_name } '" )
280+ if 'text_and_help' not in option :
281+ if 'help' in option :
282+ option ['text_and_help' ] = '{text} [{help}]' .format (** option )
283+ else :
284+ option ['text_and_help' ] = '{text}' .format (** option )
285+ options .append (option )
279286
280287 return Response (options )
281288
0 commit comments