<commit_before>from django.contrib import admin
from . import models
from .tasks import notify_project


class TokenAdmin(admin.ModelAdmin):
    """
    Handles global tokens, i.e. tokens that are not projec-specific.
    """
    model = models.Token
    fields = ['description', 'key']
    readonly_fields = ['key']

    def get_queryset(self, request):
        return super(TokenAdmin, self).get_queryset(request).filter(project=None)


class EnvironmentInline(admin.StackedInline):
    """
    Handles environments when editing a project.
    """
    model = models.Environment
    fields = ['slug', 'name', 'expected_test_runs']
    extra = 0


class TokenInline(admin.StackedInline):
    """
    Handles project-specific tokens inline when editing the project.
    """
    model = models.Token
    fields = ['description', 'key']
    readonly_fields = ['key']
    extra = 0


class SubscriptionInline(admin.StackedInline):
    model = models.Subscription
    fields = ['email']
    extra = 0


class AdminSubscriptionInline(admin.StackedInline):
    model = models.AdminSubscription
    fields = ['email']
    extra = 0


def force_notify_project(modeladmin, request, queryset):
    for project in queryset:
        notify_project.delay(project.pk)


force_notify_project.short_description = "Force sending email notification for selected projects"


class ProjectAdmin(admin.ModelAdmin):
    list_display = ['__str__', 'is_public', 'notification_strategy']
    inlines = [EnvironmentInline, TokenInline, SubscriptionInline, AdminSubscriptionInline]
    actions = [force_notify_project]


class ProjectStatusAdmin(admin.ModelAdmin):
    model = models.ProjectStatus


admin.site.register(models.Group)
admin.site.register(models.Project, ProjectAdmin)
admin.site.register(models.Token, TokenAdmin)
admin.site.register(models.ProjectStatus, ProjectStatusAdmin)
<commit_msg>core/admin: display ProjectStatus flags<commit_after>from django.contrib import admin
from . import models
from .tasks import notify_project


class TokenAdmin(admin.ModelAdmin):
    """
    Handles global tokens, i.e. tokens that are not projec-specific.
    """
    model = models.Token
    fields = ['description', 'key']
    readonly_fields = ['key']

    def get_queryset(self, request):
        return super(TokenAdmin, self).get_queryset(request).filter(project=None)


class EnvironmentInline(admin.StackedInline):
    """
    Handles environments when editing a project.
    """
    model = models.Environment
    fields = ['slug', 'name', 'expected_test_runs']
    extra = 0


class TokenInline(admin.StackedInline):
    """
    Handles project-specific tokens inline when editing the project.
    """
    model = models.Token
    fields = ['description', 'key']
    readonly_fields = ['key']
    extra = 0


class SubscriptionInline(admin.StackedInline):
    model = models.Subscription
    fields = ['email']
    extra = 0


class AdminSubscriptionInline(admin.StackedInline):
    model = models.AdminSubscription
    fields = ['email']
    extra = 0


def force_notify_project(modeladmin, request, queryset):
    for project in queryset:
        notify_project.delay(project.pk)


force_notify_project.short_description = "Force sending email notification for selected projects"


class ProjectAdmin(admin.ModelAdmin):
    list_display = ['__str__', 'is_public', 'notification_strategy']
    inlines = [EnvironmentInline, TokenInline, SubscriptionInline, AdminSubscriptionInline]
    actions = [force_notify_project]


class ProjectStatusAdmin(admin.ModelAdmin):
    model = models.ProjectStatus
    list_display = ['__str__', 'approved', 'notified']


admin.site.register(models.Group)
admin.site.register(models.Project, ProjectAdmin)
admin.site.register(models.Token, TokenAdmin)
admin.site.register(models.ProjectStatus, ProjectStatusAdmin)

{'fraction_non_alphanumeric': 0.1045632333767927, 'fraction_numerical': 0.0020860495436766623, 'mean_word_length': 4.2837465564738295, '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': '766651', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1081, 'n_words': 261}