<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin
from django.apps import apps

import plugin.models as models


def plugin_update(queryset, new_status: bool):
    """general function for bulk changing plugins"""
    for model in queryset:
        model.active = new_status
        model.save(no_reload=True)

    app = apps.get_app_config('plugin')
    app.reload_plugins()


@admin.action(description='Activate plugin(s)')
def plugin_activate(modeladmin, request, queryset):
    """activate a set of plugins"""
    plugin_update(queryset, True)


@admin.action(description='Deactivate plugin(s)')
def plugin_deactivate(modeladmin, request, queryset):
    """deactivate a set of plugins"""
    plugin_update(queryset, False)


class PluginConfigAdmin(admin.ModelAdmin):
    """Custom admin with restricted id fields"""
    readonly_fields = ["key", "name", ]
    list_display = ['key', 'name', 'active', ]
    actions = [plugin_activate, plugin_deactivate, ]


admin.site.register(models.PluginConfig, PluginConfigAdmin)<commit_msg>check if you the plugins really need to be reloaded<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin
from django.apps import apps

import plugin.models as models


def plugin_update(queryset, new_status: bool):
    """general function for bulk changing plugins"""
    apps_changed = False

    # run through all plugins in the queryset as the save method needs to be overridden
    for model in queryset:
        if model.active is not new_status:
            model.active = new_status
            apps_changed = True
        model.save(no_reload=True)

    # reload plugins if they changed
    if apps_changed:
        app = apps.get_app_config('plugin')
        app.reload_plugins()


@admin.action(description='Activate plugin(s)')
def plugin_activate(modeladmin, request, queryset):
    """activate a set of plugins"""
    plugin_update(queryset, True)


@admin.action(description='Deactivate plugin(s)')
def plugin_deactivate(modeladmin, request, queryset):
    """deactivate a set of plugins"""
    plugin_update(queryset, False)


class PluginConfigAdmin(admin.ModelAdmin):
    """Custom admin with restricted id fields"""
    readonly_fields = ["key", "name", ]
    list_display = ['key', 'name', 'active', ]
    actions = [plugin_activate, plugin_deactivate, ]


admin.site.register(models.PluginConfig, PluginConfigAdmin)
{'fraction_non_alphanumeric': 0.10727199678585778, 'fraction_numerical': 0.0008035355564483728, 'mean_word_length': 4.264270613107822, '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': '6404918', 'n_tokens_mistral': 715, 'n_tokens_neox': 692, 'n_words': 209}