<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin

from .models import Document, DocumentError


def reprocess(modeladmin, request, queryset):
    for doc in queryset:
        doc.reprocess(force=True)

reprocess.short_description = "Reprocess selected documents"


def autotag(modeladmin, request, queryset):
    for doc in queryset:
        doc.tag_from_name()

autotag.short_description = "Auto-tag selected documents"


def repair(modeladmin, request, queryset):
    for doc in queryset:
        doc.repair()

repair.short_description = "Repair selected documents"


@admin.register(Document)
class DocumentAdmin(admin.ModelAdmin):
    readonly_fields = ('size', 'pages', 'original', 'pdf', 'md5', 'state',)
    filter_horizontal = ('tags',)

    list_display = ('id', 'name', 'pages', 'views', 'downloads', 'hidden', 'state', 'created', 'user', 'file_type')
    list_filter = ('state', 'created', 'edited', 'file_type')
    search_fields = ('md5', 'name')

    actions = (reprocess, autotag, repair)

    fieldsets = (
        (None, {
            'fields': (
                'name',
                ('course', 'user'),
                ('pages', 'state'),
                'hidden',
                'tags',
                'description',
            )
        }),
        ('Extra', {
            'fields': (
                ('file_type', 'md5'),
                ('original', 'pdf'),
                ('views', 'downloads')
            )
        })
    )


@admin.register(DocumentError)
class DocumentErrorAdmin(admin.ModelAdmin):
    list_display = ('exception', 'document', 'task_id')<commit_msg>[add] Vote to Document admin as inline<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin

from .models import Document, DocumentError, Vote


def reprocess(modeladmin, request, queryset):
    for doc in queryset:
        doc.reprocess(force=True)


reprocess.short_description = "Reprocess selected documents"


def autotag(modeladmin, request, queryset):
    for doc in queryset:
        doc.tag_from_name()


autotag.short_description = "Auto-tag selected documents"


def repair(modeladmin, request, queryset):
    for doc in queryset:
        doc.repair()


repair.short_description = "Repair selected documents"


class VoteInline(admin.StackedInline):
    """Inline in a tab to easily add shipments from an existing order."""
    readonly_fields = ["when"]
    extra = 1
    model = Vote

    fieldsets = (
        (None, {
            "fields": (
                ("user", "vote_type", "when"),
            ),
        }),
    )


@admin.register(Document)
class DocumentAdmin(admin.ModelAdmin):
    readonly_fields = ('size', 'pages', 'original', 'pdf', 'md5', 'state',)
    filter_horizontal = ('tags',)

    list_display = ('id', 'name', 'pages', 'views', 'downloads', 'hidden', 'state', 'created', 'user', 'file_type')
    list_filter = ('state', 'created', 'edited', 'file_type')
    search_fields = ('md5', 'name')
    inlines = [VoteInline]

    actions = (reprocess, autotag, repair)

    fieldsets = (
        (None, {
            'fields': (
                'name',
                ('course', 'user'),
                ('pages', 'state'),
                'hidden',
                'tags',
                'description',
            )
        }),
        ('Extra', {
            'fields': (
                ('file_type', 'md5'),
                ('original', 'pdf'),
                ('views', 'downloads'),
            )
        })
    )


@admin.register(DocumentError)
class DocumentErrorAdmin(admin.ModelAdmin):
    list_display = ('exception', 'document', 'task_id')
{'fraction_non_alphanumeric': 0.1464796331265174, 'fraction_numerical': 0.0024278392230914487, 'mean_word_length': 2.4365152919369786, 'pattern_counts': {'":': 1, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '762882', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1060, 'n_words': 266}