<commit_before>import json

from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from django.db.models import Prefetch
from django.utils.html import format_html
from django.utils.translation import ugettext

from olympia.addons.models import Addon
from olympia.amo.urlresolvers import reverse

from .models import ScannerResult, ScannerRule


class MatchesFilter(SimpleListFilter):
    title = ugettext('matches')
    parameter_name = 'has_matches'

    def lookups(self, request, model_admin):
        return (('all', 'All'), (None, ' With matched rules only'))

    def choices(self, cl):
        for lookup, title in self.lookup_choices:
            yield {
                'selected': self.value() == lookup,
                'query_string': cl.get_query_string(
                    {self.parameter_name: lookup}, []
                ),
                'display': title,
            }

    def queryset(self, request, queryset):
        if self.value() == 'all':
            return queryset
        return queryset.filter(has_matches=True)


@admin.register(ScannerResult)
class ScannerResultAdmin(admin.ModelAdmin):
    actions = None
    view_on_site = False

    list_display = (
        'id',
        'formatted_addon',
        'channel',
        'scanner',
        'formatted_matched_rules',
    )
    list_filter = ('scanner', MatchesFilter)
    list_select_related = ('version',)

    fields = (
        'id',
        'upload',
        'formatted_addon',
        'channel',
        'scanner',
        'formatted_results',
    )

    ordering = ('-created',)
<commit_msg>Display creation date in scanner result list (#12804)<commit_after>import json

from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from django.db.models import Prefetch
from django.utils.html import format_html
from django.utils.translation import ugettext

from olympia.addons.models import Addon
from olympia.amo.urlresolvers import reverse

from .models import ScannerResult, ScannerRule


class MatchesFilter(SimpleListFilter):
    title = ugettext('matches')
    parameter_name = 'has_matches'

    def lookups(self, request, model_admin):
        return (('all', 'All'), (None, ' With matched rules only'))

    def choices(self, cl):
        for lookup, title in self.lookup_choices:
            yield {
                'selected': self.value() == lookup,
                'query_string': cl.get_query_string(
                    {self.parameter_name: lookup}, []
                ),
                'display': title,
            }

    def queryset(self, request, queryset):
        if self.value() == 'all':
            return queryset
        return queryset.filter(has_matches=True)


@admin.register(ScannerResult)
class ScannerResultAdmin(admin.ModelAdmin):
    actions = None
    view_on_site = False

    list_display = (
        'id',
        'formatted_addon',
        'channel',
        'scanner',
        'formatted_matched_rules',
        'created',
    )
    list_filter = ('scanner', MatchesFilter)
    list_select_related = ('version',)

    fields = (
        'id',
        'upload',
        'formatted_addon',
        'channel',
        'scanner',
        'formatted_results',
    )

    ordering = ('-created',)

{'fraction_non_alphanumeric': 0.10558437595361611, 'fraction_numerical': 0.0015257857796765334, 'mean_word_length': 2.490947816826411, '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': '6693415', 'n_tokens_mistral': 951, 'n_tokens_neox': 922, 'n_words': 226}