<commit_before>from django.contrib import admin
from django.contrib.auth.admin import (
    UserAdmin as AuthUserAdmin,
    GroupAdmin,
)
from django.contrib.auth.models import User, Group

from pontoon.base import models


AGGREGATED_STATS_FIELDS = (
    'total_strings',
    'approved_strings',
    'translated_strings',
    'fuzzy_strings',
)


class UserProfileInline(admin.StackedInline):
    model = models.UserProfile
    max_num = 1
    can_delete = False
    fields = ('quality_checks', 'force_suggestions',)
    verbose_name_plural = 'Settings'


class UserAdmin(AuthUserAdmin):
    search_fields = ['email', 'first_name']
    list_display = ('email', 'first_name', 'last_login', 'date_joined')
    list_filter = ('is_staff', 'is_superuser')
    inlines = (UserProfileInline,)


class ExternalResourceInline(admin.TabularInline):
    model = models.ExternalResource
    extra = 0
    verbose_name_plural = 'External Resources'


class ExternalLocaleResourceInline(ExternalResourceInline):
    fields = ('locale', 'name', 'url',)


class LocaleAdmin(admin.ModelAdmin):
    search_fields = ['name', 'code']
    list_display = ('pk', 'name', 'code', 'script', 'direction', 'population',
                    'cldr_plurals', 'nplurals', 'plural_rule')
    exclude = ('translators_group', 'managers_group')
    readonly_fields = AGGREGATED_STATS_FIELDS + ('latest_translation',)
    inlines = (ExternalLocaleResourceInline,)


class ExternalProjectResourceInline(ExternalResourceInline):
    fields = ('project', 'name', 'url',)


class ProjectLocaleInline(admin.TabularInline):
    model = models.ProjectLocale
    extra = 0
    verbose_name_plural = 'Locales'
    fields = ('locale',)


class RepositoryInline(admin.TabularInline):
    model = models.Repository
    extra = 0
    verbose_name_plural = 'Repositories'
    fields = ('type', 'url', 'branch', 'website', 'permalink_prefix', 'last_synced_revisions', 'source_repo',)


class SubpageInline(admin.TabularInline):
    model = models.Subpage
    extra = 0
    verbose_name_plural = 'Subpages'
    fields = ('project', 'name', 'url', 'resources',)
    raw_id_fields = ('resources',)


class ProjectAdmin(admin.ModelAdmin):
    search_fields = ['name', 'slug']
    list_display = ('name', 'slug', 'deadline', 'priority', 'contact_person', 'pk', 'disabled')

    def contact_person(self, obj):
        return obj.contact.name_or_email if obj.contact else '-'

    fieldsets = (
        (None, {
            'fields': (
                'name', 'slug', 'info', 'deadline', 'priority',
                'contact', 'langpack_url', 'can_be_requested', 'disabled'),
        }),
        ('WEBSITE', {
            'fields': ('url', 'width', 'links'),
        }),
    )
    readonly_fields = AGGREGATED_STATS_FIELDS + ('latest_translation',)
    inlines = (
        SubpageInline, ProjectLocaleInline,
        RepositoryInline, ExternalProjectResourceInline
    )


class ResourceAdmin(admin.ModelAdmin):<commit_msg>Project admin sorting<commit_after>from django.contrib import admin
from django.contrib.auth.admin import (
    UserAdmin as AuthUserAdmin,
    GroupAdmin,
)
from django.contrib.auth.models import User, Group

from pontoon.base import models


AGGREGATED_STATS_FIELDS = (
    'total_strings',
    'approved_strings',
    'translated_strings',
    'fuzzy_strings',
)


class UserProfileInline(admin.StackedInline):
    model = models.UserProfile
    max_num = 1
    can_delete = False
    fields = ('quality_checks', 'force_suggestions',)
    verbose_name_plural = 'Settings'


class UserAdmin(AuthUserAdmin):
    search_fields = ['email', 'first_name']
    list_display = ('email', 'first_name', 'last_login', 'date_joined')
    list_filter = ('is_staff', 'is_superuser')
    inlines = (UserProfileInline,)


class ExternalResourceInline(admin.TabularInline):
    model = models.ExternalResource
    extra = 0
    verbose_name_plural = 'External Resources'


class ExternalLocaleResourceInline(ExternalResourceInline):
    fields = ('locale', 'name', 'url',)


class LocaleAdmin(admin.ModelAdmin):
    search_fields = ['name', 'code']
    list_display = ('pk', 'name', 'code', 'script', 'direction', 'population',
                    'cldr_plurals', 'nplurals', 'plural_rule')
    exclude = ('translators_group', 'managers_group')
    readonly_fields = AGGREGATED_STATS_FIELDS + ('latest_translation',)
    inlines = (ExternalLocaleResourceInline,)


class ExternalProjectResourceInline(ExternalResourceInline):
    fields = ('project', 'name', 'url',)


class ProjectLocaleInline(admin.TabularInline):
    model = models.ProjectLocale
    extra = 0
    verbose_name_plural = 'Locales'
    fields = ('locale',)


class RepositoryInline(admin.TabularInline):
    model = models.Repository
    extra = 0
    verbose_name_plural = 'Repositories'
    fields = ('type', 'url', 'branch', 'website', 'permalink_prefix', 'last_synced_revisions', 'source_repo',)


class SubpageInline(admin.TabularInline):
    model = models.Subpage
    extra = 0
    verbose_name_plural = 'Subpages'
    fields = ('project', 'name', 'url', 'resources',)
    raw_id_fields = ('resources',)


class ProjectAdmin(admin.ModelAdmin):
    search_fields = ['name', 'slug']
    list_display = ('name', 'slug', 'deadline', 'priority', 'contact_person', 'pk', 'enabled')
    ordering = ('disabled',)

    def contact_person(self, obj):
        return obj.contact.name_or_email if obj.contact else '-'
    contact_person.admin_order_field = 'contact__first_name'

    def enabled(self, obj):
        return not obj.disabled
    enabled.boolean = True
    enabled.admin_order_field = 'disabled'

    fieldsets = (
        (None, {
            'fields': (
                'name', 'slug', 'info', 'deadline', 'priority',
                'contact', 'langpack_url', 'can_be_requested', 'disabled'),
        }),
        ('WEBSITE', {
            'fields': ('url', 'width', 'links'),
        }),
    )
    readonly_fields = AGGREGATED_STATS_FIELDS + ('latest_translation',)
    inlines = (
        SubpageInline, ProjectLocaleInline,
        RepositoryInline, ExternalProjectResourceInline
    )


class ResourceAdmin(admin.ModelAdmin):
{'fraction_non_alphanumeric': 0.13133116883116883, 'fraction_numerical': 0.0016233766233766235, 'mean_word_length': 3.858832807570978, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2447126', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1889, 'n_words': 387}