<commit_before>from __future__ import absolute_import, unicode_literals

from django import template
from django.db import models
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _


register = template.Library()


@register.filter
def model_details(instance, fields=None):
    """
    Returns a stream of ``verbose_name``, ``value`` pairs for the specified
    model instance::

        <table>
        {% for verbose_name, value in object|model_details %}
            <tr>
                <th>{{ verbose_name }}</th>
                <td>{{ value }}</td>
            </tr>
        {% endfor %}
        </table>
    """

    if not fields:
        _fields = instance._meta.fields
    else:
        _fields = [
            instance._meta.get_field_by_name(f)[0]
            for f in fields.split(',')]

    for f in _fields:
        if f.auto_created:
            continue

        if isinstance(f, models.ForeignKey):
            fk = getattr(instance, f.name)
            if hasattr(fk, 'get_absolute_url'):
                try:
                    value = mark_safe('<a href="%s">%s</a>' % (
                        fk.get_absolute_url(),
                        fk))
                except:  # Whatever.
                    value = fk
            else:
                value = fk

        elif f.choices:
            value = getattr(instance, 'get_%s_display' % f.name)()

        elif isinstance(f, (models.BooleanField, models.NullBooleanField)):
            value = getattr(instance, f.name)
            value = {
                True: _('yes'),<commit_msg>Fix some code for recent Django versions<commit_after>from __future__ import absolute_import, unicode_literals

from django import template
from django.db import models
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _


register = template.Library()


@register.filter
def model_details(instance, fields=None):
    """
    Returns a stream of ``verbose_name``, ``value`` pairs for the specified
    model instance::

        <table>
        {% for verbose_name, value in object|model_details %}
            <tr>
                <th>{{ verbose_name }}</th>
                <td>{{ value }}</td>
            </tr>
        {% endfor %}
        </table>
    """

    if not fields:
        _fields = instance._meta.fields
    else:
        _fields = [
            instance._meta.get_field(f)
            for f in fields.split(',')]

    for f in _fields:
        if f.auto_created:
            continue

        if isinstance(f, models.ForeignKey):
            fk = getattr(instance, f.name)
            if hasattr(fk, 'get_absolute_url'):
                try:
                    value = mark_safe('<a href="%s">%s</a>' % (
                        fk.get_absolute_url(),
                        fk))
                except:  # Whatever.
                    value = fk
            else:
                value = fk

        elif f.choices:
            value = getattr(instance, 'get_%s_display' % f.name)()

        elif isinstance(f, (models.BooleanField, models.NullBooleanField)):
            value = getattr(instance, f.name)
            value = {
                True: _('yes'),
{'fraction_non_alphanumeric': 0.10946196660482375, 'fraction_numerical': 0.00030921459492888067, 'mean_word_length': 1.6891105569409808, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5093400', 'n_tokens_mistral': 936, 'n_tokens_neox': 880, 'n_words': 231}