<commit_before>from django.contrib import admin

from .models import Topology, Node, Link
from .base import TimeStampedEditableAdmin


class TopologyAdmin(TimeStampedEditableAdmin):
    list_display = ('label', 'parser', 'link_url', 'created', 'modified')
    readonly_fields = ['protocol', 'version', 'revision', 'metric']
    list_filter = ('parser',)

    def link_url(self, obj):  # pragma nocover
        return '<a href="{0}" target="_blank">{0}</a>'.format(obj.url)
    link_url.allow_tags = True


class NodeAdmin(TimeStampedEditableAdmin):
    list_display = ('name', 'topology', 'addresses')
    list_filter = ('topology',)
    search_fields = ('addresses', 'label', 'properties')


class LinkAdmin(TimeStampedEditableAdmin):
    raw_id_fields = ('source', 'target')
    list_display = ('__str__', 'topology', 'status', 'cost', 'cost_text')
    list_filter = ('status', 'topology')
    search_fields = ('source__addresses', 'target__addresses', 'properties',)


admin.site.register(Topology, TopologyAdmin)
admin.site.register(Node, NodeAdmin)
admin.site.register(Link, LinkAdmin)<commit_msg>[Link Admin] Search also in node labels<commit_after>from django.contrib import admin

from .models import Topology, Node, Link
from .base import TimeStampedEditableAdmin


class TopologyAdmin(TimeStampedEditableAdmin):
    list_display = ('label', 'parser', 'link_url', 'created', 'modified')
    readonly_fields = ['protocol', 'version', 'revision', 'metric']
    list_filter = ('parser',)

    def link_url(self, obj):  # pragma nocover
        return '<a href="{0}" target="_blank">{0}</a>'.format(obj.url)
    link_url.allow_tags = True


class NodeAdmin(TimeStampedEditableAdmin):
    list_display = ('name', 'topology', 'addresses')
    list_filter = ('topology',)
    search_fields = ('addresses', 'label', 'properties')


class LinkAdmin(TimeStampedEditableAdmin):
    raw_id_fields = ('source', 'target')
    list_display = ('__str__', 'topology', 'status', 'cost', 'cost_text')
    list_filter = ('status', 'topology')
    search_fields = (
        'source__label',
        'target__label',
        'source__addresses',
        'target__addresses',
        'properties',
    )


admin.site.register(Topology, TopologyAdmin)
admin.site.register(Node, NodeAdmin)
admin.site.register(Link, LinkAdmin)
{'fraction_non_alphanumeric': 0.15064935064935064, 'fraction_numerical': 0.0017316017316017316, 'mean_word_length': 4.940874035989717, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6584901', 'n_tokens_mistral': 726, 'n_tokens_neox': 709, 'n_words': 159}