<commit_before>from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin

from kuma.core.urlresolvers import reverse
from jingo.helpers import urlparams
from .models import User, UserBan


class UserBanAdmin(admin.ModelAdmin):
    fields = ('user', 'by', 'reason', 'is_active')
    list_display = ('user', 'by', 'reason', 'is_active')
    list_editable = ('is_active',)
    list_filter = ('is_active',)
    raw_id_fields = ('user', 'by')
    search_fields = ('user__username', 'reason', 'by__username')

admin.site.register(UserBan, UserBanAdmin)


class UserAdmin(BaseUserAdmin):
    """
    Extends the admin view of users to show date_joined field
    add a filter on the field too
    """
    list_display = ('username', 'fullname', 'email',
                    'bio', 'website', 'revisions',
                    'date_joined', 'is_staff', 'is_active')
    list_filter = ('is_staff', 'is_superuser', 'is_active', 'date_joined')
    ordering = ('-date_joined',)
    search_fields = ('username', 'homepage', 'title', 'fullname',
                     'organization', 'location', 'bio', 'email', 'tags__name')

    def revisions(self, obj):
        """HTML link to user's revisions with count"""
        link = urlparams(reverse('dashboards.revisions'),
                         user=obj.username)
        count = obj.created_revisions.count()
        return ('<a href="%(link)s"><strong>%(count)s</strong></a>' %
                {'link': link, 'count': count})

    revisions.allow_tags = True

    def website(self, obj):
        """HTML link to user's website"""
        return ('<a href="%(url)s"><strong>%(url)s</strong></a>' %
                {'url': obj.website_url})

    website.allow_tags = True

admin.site.register(User, UserAdmin)
<commit_msg>[bug 1119551] Don't output empty website URLs<commit_after>from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin

from kuma.core.urlresolvers import reverse
from jingo.helpers import urlparams
from .models import User, UserBan


class UserBanAdmin(admin.ModelAdmin):
    fields = ('user', 'by', 'reason', 'is_active')
    list_display = ('user', 'by', 'reason', 'is_active')
    list_editable = ('is_active',)
    list_filter = ('is_active',)
    raw_id_fields = ('user', 'by')
    search_fields = ('user__username', 'reason', 'by__username')

admin.site.register(UserBan, UserBanAdmin)


class UserAdmin(BaseUserAdmin):
    """
    Extends the admin view of users to show date_joined field
    add a filter on the field too
    """
    list_display = ('username', 'fullname', 'email',
                    'bio', 'website', 'revisions',
                    'date_joined', 'is_staff', 'is_active')
    list_filter = ('is_staff', 'is_superuser', 'is_active', 'date_joined')
    ordering = ('-date_joined',)
    search_fields = ('username', 'homepage', 'title', 'fullname',
                     'organization', 'location', 'bio', 'email', 'tags__name')

    def revisions(self, obj):
        """HTML link to user's revisions with count"""
        link = urlparams(reverse('dashboards.revisions'),
                         user=obj.username)
        count = obj.created_revisions.count()
        return ('<a href="%(link)s"><strong>%(count)s</strong></a>' %
                {'link': link, 'count': count})

    revisions.allow_tags = True

    def website(self, obj):
        """HTML link to user's website"""
        if obj.website_url:
            return ('<a href="%(url)s"><strong>%(url)s</strong></a>' %
                    {'url': obj.website_url})
        return ""

    website.allow_tags = True

admin.site.register(User, UserAdmin)

{'fraction_non_alphanumeric': 0.15307232191408374, 'fraction_numerical': 0.0019032082653616096, 'mean_word_length': 3.1337078651685393, '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': '6112240', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1091, 'n_words': 279}