def create_form_fields(plugins_param = ''):
    """
    Generator of form fields in desired grouping.
    
    Takes Plugin model queryset or produces own from all plugins.
    
    Makes:
    - getting all plugins queryset if not given
    - getting used plugins types and cleaning them to disable repeating of them
    - grouping fields for PluginSelectorForm 
    
    Returns kwargs dictionary with form fields to populate form.
    """
    # getting all plugins queryset if not given
    if plugins_param == '':
        plugins = Plugin.objects.all()
    else:
        plugins = plugins_param
    # init
    all_plugins_types = []
    plugin_types_clean = []
    plugins_done = []
    kwargs = {}
    # getting used plugins types and cleaning them to disable repeating of them
    for plugin in plugins:
        plugin_temp = plugin.get_plugin()
        plugin_temp.pk = plugin.pk
        plugins_done.append(plugin_temp)
        all_plugins_types.append(plugin_temp.plugin_type)
        # appending all unique types to types list
        if not (plugin_temp.plugin_type in plugin_types_clean):
            plugin_types_clean.append(plugin_temp.plugin_type)
    
    # grouping fields for PluginSelectorForm
    for plugin_type in plugin_types_clean:
        plugins_temp_list = []
        for plugin in plugins_done:
            if plugin.plugin_type == plugin_type:
                #add plugin to current plugins list
                plugins_temp_list.append(plugin.pk)
        #saving plugins list to main dict
        kwargs[plugin_type] = forms.ModelMultipleChoiceField(plugins.filter(pk__in = plugins_temp_list))
    return kwargs
dataset/ETHPy150Open adlibre/Adlibre-DMS/adlibre_dms/apps/dms_plugins/representator.py/create_form_fields/original