<commit_before>from django.core.management.base import AppCommand
from django.utils.text import capfirst

MODULE_TEMPLATE = '''    {%% if perms.%(app)s.%(addperm)s or perms.%(app)s.%(changeperm)s %%}
    <tr>
        <th>{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/">{%% endif %%}%(name)s{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</th>
        <td class="x50">{%% if perms.%(app)s.%(addperm)s %%}<a href="%(app)s/%(mod)s/add/" class="addlink">{%% endif %%}Add{%% if perms.%(app)s.%(addperm)s %%}</a>{%% endif %%}</td>
        <td class="x75">{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/" class="changelink">{%% endif %%}Change{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</td>
    </tr>
    {%% endif %%}'''

class Command(AppCommand):
    help = 'Prints the admin-index template snippet for the given app name(s).'

    def handle_app(self, app, **options):
        from django.db.models import get_models
        output = []
        app_models = get_models(app)
        app_label = app_models[0]._meta.app_label
        output.append('{%% if perms.%s %%}' % app_label)
        output.append('<div class="module"><h2>%s</h2><table>' % app_label.title())
        for model in app_models:
            if model._meta.admin:
                output.append(MODULE_TEMPLATE % {
                    'app': app_label,
                    'mod': model._meta.module_name,
                    'name': capfirst(model._meta.verbose_name_plural),
                    'addperm': model._meta.get_add_permission(),
                    'changeperm': model._meta.get_change_permission(),
                })
        output.append('</table></div>')
        output.append('{% endif %}')
        return '\n'.join(output)
<commit_msg>Fixed #5286 -- Fixed non-HTML output bug in adminindex command. Thanks, <EMAIL> and piranha<commit_after>from django.core.management.base import AppCommand
from django.utils.encoding import force_unicode
from django.utils.text import capfirst

MODULE_TEMPLATE = '''    {%% if perms.%(app)s.%(addperm)s or perms.%(app)s.%(changeperm)s %%}
    <tr>
        <th>{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/">{%% endif %%}%(name)s{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</th>
        <td class="x50">{%% if perms.%(app)s.%(addperm)s %%}<a href="%(app)s/%(mod)s/add/" class="addlink">{%% endif %%}Add{%% if perms.%(app)s.%(addperm)s %%}</a>{%% endif %%}</td>
        <td class="x75">{%% if perms.%(app)s.%(changeperm)s %%}<a href="%(app)s/%(mod)s/" class="changelink">{%% endif %%}Change{%% if perms.%(app)s.%(changeperm)s %%}</a>{%% endif %%}</td>
    </tr>
    {%% endif %%}'''

class Command(AppCommand):
    help = 'Prints the admin-index template snippet for the given app name(s).'

    def handle_app(self, app, **options):
        from django.db.models import get_models
        output = []
        app_models = get_models(app)
        app_label = app_models[0]._meta.app_label
        output.append('{%% if perms.%s %%}' % app_label)
        output.append('<div class="module"><h2>%s</h2><table>' % app_label.title())
        for model in app_models:
            if model._meta.admin:
                output.append(MODULE_TEMPLATE % {
                    'app': app_label,
                    'mod': model._meta.module_name,
                    'name': force_unicode(capfirst(model._meta.verbose_name_plural)),
                    'addperm': model._meta.get_add_permission(),
                    'changeperm': model._meta.get_change_permission(),
                })
        output.append('</table></div>')
        output.append('{% endif %}')
        return '\n'.join(output)

{'fraction_non_alphanumeric': 0.21078298564074777, 'fraction_numerical': 0.004876727174207532, 'mean_word_length': 2.8619246861924688, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, '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': '3097675', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1232, 'n_words': 238}