<commit_before>from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.template.loader import render_to_string
from django.urls import reverse
from hc.accounts.models import Profile
from hc.api.models import Channel, Check


@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):

    class Media:
        css = {
            'all': ('css/admin/profiles.css',)
        }

    list_display = ("id", "users", "reports_allowed", "next_report_date",
                    "ping_log_limit")
    search_fields = ["id", "user__email"]
    list_filter = ("reports_allowed", "team_access_allowed",
                   "next_report_date")

    def users(self, obj):
        if obj.member_set.count() == 0:
            return obj.user.email
        else:
            return render_to_string("admin/profile_list_team.html", {
                "profile": obj
            })

    users.allow_tags = True


class HcUserAdmin(UserAdmin):
    actions = ["send_report"]
    list_display = ('id', 'email', 'date_joined', 'involvement',
                    'is_staff', 'checks')

    ordering = ["-id"]

    def involvement(self, user):
        result = ""
        num_checks = Check.objects.filter(user=user).count()
        num_channels = Channel.objects.filter(user=user).count()

        if num_checks == 0:
            result += "0 checks, "<commit_msg>Profile admin improvements<commit_after>from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.template.loader import render_to_string
from django.urls import reverse
from hc.accounts.models import Profile
from hc.api.models import Channel, Check


class Fieldset:
    name = None
    fields = []

    @classmethod
    def tuple(cls):
        return (cls.name, {"fields": cls.fields})


class ProfileFieldset(Fieldset):
    name = "User Profile"
    fields = ("email", "api_key", "current_team", "reports_allowed",
              "next_report_date", "token")


class TeamFieldset(Fieldset):
    name = "Team"
    fields = ("team_name", "team_access_allowed", "check_limit",
              "ping_log_limit")


@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):

    class Media:
        css = {
            'all': ('css/admin/profiles.css',)
        }

    readonly_fields = ("user", "email")
    raw_id_fields = ("current_team", )
    list_select_related = ("user", )
    list_display = ("id", "users", "checks", "team_access_allowed",
                    "reports_allowed", "ping_log_limit")
    search_fields = ["id", "user__email"]
    list_filter = ("team_access_allowed", "reports_allowed",
                   "check_limit", "next_report_date")

    fieldsets = (ProfileFieldset.tuple(), TeamFieldset.tuple())

    def users(self, obj):
        if obj.member_set.count() == 0:
            return obj.user.email
        else:
            return render_to_string("admin/profile_list_team.html", {
                "profile": obj
            })

    def checks(self, obj):
        current = Check.objects.filter(user=obj.user).count()
        text = "%d of %d" % (current, obj.check_limit)
        url = reverse("hc-switch-team", args=[obj.user.username])
        return "<a href='%s'>%s</a>" % (url, text)

    def email(self, obj):
        return obj.user.email

    users.allow_tags = True
    checks.allow_tags = True


class HcUserAdmin(UserAdmin):
    actions = ["send_report"]
    list_display = ('id', 'email', 'date_joined', 'involvement',
                    'is_staff', 'checks')

    list_filter = ("last_login", "date_joined", "is_staff", "is_active")

    ordering = ["-id"]

    def involvement(self, user):
        result = ""
        num_checks = Check.objects.filter(user=user).count()
        num_channels = Channel.objects.filter(user=user).count()

        if num_checks == 0:
            result += "0 checks, "
{'fraction_non_alphanumeric': 0.13171225937183384, 'fraction_numerical': 0.001519756838905775, 'mean_word_length': 2.743127962085308, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, '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': '2056235', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1159, 'n_words': 262}