<commit_before>from os.path import basename

from website import settings

def serialize_addon_config(config, user):
    lookup = config.template_lookup

    return {
        'addon_short_name': config.short_name,
        'addon_full_name': config.full_name,
        'node_settings_template': lookup.get_template(basename(config.node_settings_template)),
        'user_settings_template': lookup.get_template(basename(config.user_settings_template)),
        'is_enabled': user.get_addon(config.short_name) is not None,
    }

def get_addons_by_config_type(config_type, user):
    addons = [addon for addon in settings.ADDONS_AVAILABLE if config_type in addon.configs]
    addon_settings = []
    for addon_config in sorted(addons, key=lambda cfg: cfg.full_name.lower()):
        # short_name = addon_config.short_name
        config = serialize_addon_config(addon_config, user)
        '''
        user_settings = user.get_addon(short_name)
        if user_settings:
            user_settings = user_settings.to_json(user)
        config.update({
            'user_settings': user_settings or {}
        })
        '''
        addon_settings.append(config)
    return addon_settings
<commit_msg>Add user_settings to serialized addon settings<commit_after>from os.path import basename

from website import settings

def serialize_addon_config(config, user):
    lookup = config.template_lookup

    user_addon = user.get_addon(config.short_name)
    ret = {
        'addon_short_name': config.short_name,
        'addon_full_name': config.full_name,
        'node_settings_template': lookup.get_template(basename(config.node_settings_template)),
        'user_settings_template': lookup.get_template(basename(config.user_settings_template)),
        'is_enabled': user_addon is not None,
    }
    ret.update(user_addon.to_json(user) if user_addon else {})
    return ret

def get_addons_by_config_type(config_type, user):
    addons = [addon for addon in settings.ADDONS_AVAILABLE if config_type in addon.configs]
    return [serialize_addon_config(addon_config, user) for addon_config in sorted(addons, key=lambda cfg: cfg.full_name.lower())]

{'fraction_non_alphanumeric': 0.08857808857808858, 'fraction_numerical': 0.0, 'mean_word_length': 3.9791183294663575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '749126', 'n_tokens_mistral': 674, 'n_tokens_neox': 670, 'n_words': 129}