<commit_before>from django import template
from django.template import Library
from django.utils import six
from django.utils.html import escape
from django.utils.safestring import mark_safe

from xadmin.util import static, vendor as util_vendor

register = Library()


@register.simple_tag(takes_context=True)
def username_field(context):
    """Get the userame based on the variable [USERNAME_FIELD]"""
    return getattr(context['original'], context['original'].USERNAME_FIELD)


@register.simple_tag(takes_context=True)
def view_block(context, block_name, *args, **kwargs):
    if 'admin_view' not in context:
        return ""

    admin_view = context['admin_view']
    nodes = []
    method_name = 'block_%s' % block_name.replace('-', '_')
    for view in [admin_view] + admin_view.plugins:
        if hasattr(view, method_name) and callable(getattr(view, method_name)):
            block_func = getattr(view, method_name)
            result = block_func(context, nodes, *args, **kwargs)
            if result and isinstance(result, str):
                nodes.append(result)
    if nodes:
        return mark_safe(''.join(nodes))<commit_msg>Priority to view blocks.<commit_after>from django import template
from django.template import Library
from django.utils import six
from django.utils.html import escape
from django.utils.safestring import mark_safe

from xadmin.util import static, vendor as util_vendor

register = Library()


@register.simple_tag(takes_context=True)
def username_field(context):
    """Get the userame based on the variable [USERNAME_FIELD]"""
    return getattr(context['original'], context['original'].USERNAME_FIELD)


@register.simple_tag(takes_context=True)
def view_block(context, block_name, *args, **kwargs):
    if 'admin_view' not in context:
        return ""

    admin_view = context['admin_view']
    nodes = []
    method_name = 'block_%s' % block_name.replace('-', '_')

    block_funcs = []
    for view in [admin_view] + admin_view.plugins:
        block_func = getattr(view, method_name, None)
        if block_func and callable(block_func):
            block_funcs.append((getattr(view, "priority", 10), block_func))
    for _, block_func in sorted(block_funcs, key=lambda x: x[0],
                                reverse=True):
        result = block_func(context, nodes, *args, **kwargs)
        if result and isinstance(result, str):
            nodes.append(result)

    if nodes:
        return mark_safe(''.join(nodes))
{'fraction_non_alphanumeric': 0.10976594027441484, 'fraction_numerical': 0.0012106537530266344, 'mean_word_length': 3.7764932562620426, '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': '5197657', 'n_tokens_mistral': 733, 'n_tokens_neox': 720, 'n_words': 194}