<commit_before>from django.contrib import admin
from django.utils.html import escape
from django.utils.translation import ugettext_lazy as _

from djcelery.admin_utils import action, display_field, fixedwidth
from djcelery.utils import naturaldate

from scs.models import Broker, Node, Queue
from scs.supervisor import supervisor


@display_field(_("max/min concurrency"), "max_concurrency")
def maxmin_concurrency(node):
    return "%s / %s" % (node.max_concurrency, node.min_concurrency)


@display_field(_("created"), "created_at")
def created_at(node):
    return """<div title="%s">%s</div>""" % (
                escape(str(node.created_at)),
                escape(naturaldate(node.created_at)))


@display_field(_("status"), "is_enabled")
def status(node):
    enabled = "Enabled" if node.is_enabled else "Disabled"
    if node.alive():
        state, color = "ONLINE", "green"
    else:
        state, color = "OFFLINE", "red"
    return """<b>%s (<span style="color: %s;">%s</span>)</b>""" % (
            enabled, color, state)


class NodeAdmin(admin.ModelAdmin):
    detail_title = _("Instance detail")
    list_page_title = _("Instances")
    date_hierarchy = "created_at"
    fieldsets = (
            (None, {
                "fields": ("name", "max_concurrency", "min_concurrency",
                           "queues", "is_enabled"),
                "classes": ("extrapretty", ),
            }), )
    list_display = (fixedwidth("name", pt=10), maxmin_concurrency, status)
    read_only_fields = ("created_at", )
    list_filter = ("name", "max_concurrency", "min_concurrency", "queues")
    search_fields = ("name", "max_concurrency", "min_concurrency", "queues")
    actions = ["disable_nodes",
               "enable_nodes",
               "restart_nodes"]

    @action(_("Disable selected instances"))
    def disable_nodes(self, request, queryset):
        for node in queryset:
            node.disable()
        supervisor.verify(queryset).wait()<commit_msg>Adds broker to node listing in Admin<commit_after>from django.contrib import admin
from django.utils.html import escape
from django.utils.translation import ugettext_lazy as _

from djcelery.admin_utils import action, display_field, fixedwidth
from djcelery.utils import naturaldate

from scs.models import Broker, Node, Queue
from scs.supervisor import supervisor


@display_field(_("max/min concurrency"), "max_concurrency")
def maxmin_concurrency(node):
    return "%s / %s" % (node.max_concurrency, node.min_concurrency)


@display_field(_("created"), "created_at")
def created_at(node):
    return """<div title="%s">%s</div>""" % (
                escape(str(node.created_at)),
                escape(naturaldate(node.created_at)))


@display_field(_("status"), "is_enabled")
def status(node):
    enabled = "Enabled" if node.is_enabled else "Disabled"
    if node.alive():
        state, color = "ONLINE", "green"
    else:
        state, color = "OFFLINE", "red"
    return """<b>%s (<span style="color: %s;">%s</span>)</b>""" % (
            enabled, color, state)


class NodeAdmin(admin.ModelAdmin):
    detail_title = _("Instance detail")
    list_page_title = _("Instances")
    date_hierarchy = "created_at"
    fieldsets = (
            (None, {
                "fields": ("name", "max_concurrency", "min_concurrency",
                           "queues", "is_enabled", "_broker"),
                "classes": ("extrapretty", ),
            }), )
    list_display = (fixedwidth("name", pt=10), maxmin_concurrency,
                    status, "broker")
    read_only_fields = ("created_at", )
    list_filter = ("name", "max_concurrency", "min_concurrency", "queues")
    search_fields = ("name", "max_concurrency", "min_concurrency", "queues")
    actions = ["disable_nodes",
               "enable_nodes",
               "restart_nodes"]

    @action(_("Disable selected instances"))
    def disable_nodes(self, request, queryset):
        for node in queryset:
            node.disable()
        supervisor.verify(queryset).wait()
{'fraction_non_alphanumeric': 0.14349553128103276, 'fraction_numerical': 0.0009930486593843098, 'mean_word_length': 3.2277019937040925, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, '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': '6761043', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1215, 'n_words': 275}