<commit_before>from __future__ import unicode_literals
from django.contrib import admin

from myhpom.models.state import State
from myhpom.models.state_requirement import StateRequirement
from myhpom.models.state_requirement_link import StateRequirementLink
from myhpom.models.document import AdvanceDirective, DocumentUrl
from myhpom.models.cloudfactory import CloudFactoryDocumentRun

from django.utils.safestring import mark_safe


class StateRequirementLinkAdmin(admin.TabularInline):
    model = StateRequirementLink


class StateRequirementAdmin(admin.ModelAdmin):
    model = StateRequirement
    inlines = [StateRequirementLinkAdmin]


class StateRequirementInlineAdmin(admin.TabularInline):
    model = StateRequirement
    fields = ('text', 'admin_link')
    readonly_fields = ('admin_link',)


class StateAdmin(admin.ModelAdmin):
    model = State
    inlines = [StateRequirementInlineAdmin]


class DocumentUrlInlineAdmin(admin.StackedInline):
    model = DocumentUrl
    fields = ('url_as_link', 'expiration', 'cloud_factory_runs')
    readonly_fields = ('url_as_link', 'cloud_factory_runs')
    extra = 0

    def url_as_link(self, obj):
        return mark_safe(
            '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>' % (obj.url, obj.url)
        )

    def cloud_factory_runs(self, obj):
        return mark_safe(
            '<ul>'
            + ''.join(
                # Is there a better way to get a URL in the mmh-admin? I don't find a resolver.
                '<li><a href="/mmh-admin/myhpom/cloudfactorydocumentrun/%d">%s</a></li>'
                % (cf_run.id, cf_run)
                for cf_run in obj.cloudfactorydocumentrun_set.all()
            )
            + '</ul>'
        )


class AdvanceDirectiveAdmin(admin.ModelAdmin):
    model = AdvanceDirective
    inlines = [DocumentUrlInlineAdmin]


class CloudFactoryDocumentRunAdmin(admin.ModelAdmin):
    model = CloudFactoryDocumentRun
    fields = (
        ('document_url', 'inserted_at', 'document_host'),<commit_msg>[mh-252] use reverse to get admin url to CloudFactoryDocumentRun - change<commit_after>from __future__ import unicode_literals
from django.contrib import admin
from django.core.urlresolvers import reverse
from myhpom.models.state import State
from myhpom.models.state_requirement import StateRequirement
from myhpom.models.state_requirement_link import StateRequirementLink
from myhpom.models.document import AdvanceDirective, DocumentUrl
from myhpom.models.cloudfactory import CloudFactoryDocumentRun

from django.utils.safestring import mark_safe


class StateRequirementLinkAdmin(admin.TabularInline):
    model = StateRequirementLink


class StateRequirementAdmin(admin.ModelAdmin):
    model = StateRequirement
    inlines = [StateRequirementLinkAdmin]


class StateRequirementInlineAdmin(admin.TabularInline):
    model = StateRequirement
    fields = ('text', 'admin_link')
    readonly_fields = ('admin_link',)


class StateAdmin(admin.ModelAdmin):
    model = State
    inlines = [StateRequirementInlineAdmin]


class DocumentUrlInlineAdmin(admin.StackedInline):
    model = DocumentUrl
    fields = ('url_as_link', 'expiration', 'cloud_factory_runs')
    readonly_fields = ('url_as_link', 'cloud_factory_runs')
    extra = 0

    def url_as_link(self, obj):
        return mark_safe(
            '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>' % (obj.url, obj.url)
        )

    def cloud_factory_runs(self, obj):
        return mark_safe(
            '<ul>'
            + ''.join(
                # Is there a better way to get a URL in the mmh-admin? I don't find a resolver.
                '<li><a href="%s">%s</a></li>'
                % (reverse("admin:myhpom_cloudfactorydocumentrun_change", args=[cf_run.id]), cf_run)
                for cf_run in obj.cloudfactorydocumentrun_set.all()
            )
            + '</ul>'
        )


class AdvanceDirectiveAdmin(admin.ModelAdmin):
    model = AdvanceDirective
    inlines = [DocumentUrlInlineAdmin]


class CloudFactoryDocumentRunAdmin(admin.ModelAdmin):
    model = CloudFactoryDocumentRun
    fields = (
        ('document_url', 'inserted_at', 'document_host'),
{'fraction_non_alphanumeric': 0.09637976504435387, 'fraction_numerical': 0.0011987532965715656, 'mean_word_length': 3.6150442477876106, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '604328', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1223, 'n_words': 273}