<commit_before>from django.contrib import admin
from django.contrib.auth.models import User, Permission
from django.contrib.auth.admin import UserAdmin
from django.db.models import Q

from challenges.forms import PhaseRoundAdminForm
from challenges.models import (Challenge, Phase, Submission, ExternalLink,
                               Category, ExclusionFlag, JudgingCriterion,
                               JudgingAnswer, Judgement, JudgeAssignment,
                               PhaseCriterion, PhaseRound, SubmissionParent,
                               SubmissionVersion)
from badges.models import SubmissionBadge


class JudgeAwareUserAdmin(UserAdmin):
    
    def is_judge(self, user):
        judge_permission = Permission.objects.get(codename='judge_submission')
        judges = User.objects.filter(Q(user_permissions=judge_permission) |
                                     Q(groups__permissions=judge_permission))
        return user in judges
    
    # Enable the pretty tick boxes in the Django admin
    is_judge.boolean = True
    
    list_display = UserAdmin.list_display + ('is_judge',)


class PhaseInline(admin.TabularInline):
    
    model = Phase
    

class PhaseCriterionInline(admin.TabularInline):
    
    model = PhaseCriterion

class CategoryAdmin(admin.ModelAdmin):
    
    model = Category
    prepopulated_fields = {"slug": ("name",)}


class JudgeAssignmentInline(admin.StackedInline):
    
    model = JudgeAssignment
    max_num = 1


class ExclusionFlagInline(admin.StackedInline):
    model = ExclusionFlag
    extra = 1


class PhaseRoundInline(admin.TabularInline):
    model = PhaseRound
    form = PhaseRoundAdminForm
    extra = 1

class PhaseAdmin(admin.ModelAdmin):
    inlines = (PhaseCriterionInline, PhaseRoundInline)


class SubmissionBadgeInline(admin.TabularInline):
    model = SubmissionBadge


class SubmissionAdmin(admin.ModelAdmin):
    model = Submission
    list_display = ('title', 'created_by', 'category', 'phase',
                    'is_draft', 'is_winner', 'excluded', 'judge_assignment',
                    'judgement_count')
    list_filter = ('category', 'is_draft', 'is_winner', 'phase__name')
    list_select_related = True  # For the judgement fields
    inlines = (JudgeAssignmentInline, ExclusionFlagInline,
               SubmissionBadgeInline)

    def judge_assignment(self, submission):
        """Return the names of all judges assigned to this submission."""
        assignments = submission.judgeassignment_set.all()
        if not assignments:
            return 'No judge'
        else:
            return ', '.join(a.judge.display_name for a in assignments)
    
    def excluded(self, submission):
        return submission.exclusionflag_set.exists()
    
    excluded.boolean = True
    
    def judgement_count(self, submission):
        return submission.judgement_set.count()


class ChallengeAdmin(admin.ModelAdmin):<commit_msg>Added filter for the phase_rounds<commit_after>from django.contrib import admin
from django.contrib.auth.models import User, Permission
from django.contrib.auth.admin import UserAdmin
from django.db.models import Q

from challenges.forms import PhaseRoundAdminForm
from challenges.models import (Challenge, Phase, Submission, ExternalLink,
                               Category, ExclusionFlag, JudgingCriterion,
                               JudgingAnswer, Judgement, JudgeAssignment,
                               PhaseCriterion, PhaseRound, SubmissionParent,
                               SubmissionVersion)
from badges.models import SubmissionBadge


class JudgeAwareUserAdmin(UserAdmin):
    
    def is_judge(self, user):
        judge_permission = Permission.objects.get(codename='judge_submission')
        judges = User.objects.filter(Q(user_permissions=judge_permission) |
                                     Q(groups__permissions=judge_permission))
        return user in judges
    
    # Enable the pretty tick boxes in the Django admin
    is_judge.boolean = True
    
    list_display = UserAdmin.list_display + ('is_judge',)


class PhaseInline(admin.TabularInline):
    
    model = Phase
    

class PhaseCriterionInline(admin.TabularInline):
    
    model = PhaseCriterion

class CategoryAdmin(admin.ModelAdmin):
    
    model = Category
    prepopulated_fields = {"slug": ("name",)}


class JudgeAssignmentInline(admin.StackedInline):
    
    model = JudgeAssignment
    max_num = 1


class ExclusionFlagInline(admin.StackedInline):
    model = ExclusionFlag
    extra = 1


class PhaseRoundInline(admin.TabularInline):
    model = PhaseRound
    form = PhaseRoundAdminForm
    extra = 1

class PhaseAdmin(admin.ModelAdmin):
    inlines = (PhaseCriterionInline, PhaseRoundInline)


class SubmissionBadgeInline(admin.TabularInline):
    model = SubmissionBadge


class SubmissionAdmin(admin.ModelAdmin):
    model = Submission
    list_display = ('title', 'created_by', 'category', 'phase',
                    'is_draft', 'is_winner', 'excluded', 'judge_assignment',
                    'judgement_count')
    list_filter = ('category', 'is_draft', 'is_winner', 'phase__name',
                   'phase_round__name')
    list_select_related = True  # For the judgement fields
    inlines = (JudgeAssignmentInline, ExclusionFlagInline,
               SubmissionBadgeInline)

    def judge_assignment(self, submission):
        """Return the names of all judges assigned to this submission."""
        assignments = submission.judgeassignment_set.all()
        if not assignments:
            return 'No judge'
        else:
            return ', '.join(a.judge.display_name for a in assignments)
    
    def excluded(self, submission):
        return submission.exclusionflag_set.exists()
    
    excluded.boolean = True
    
    def judgement_count(self, submission):
        return submission.judgement_set.count()


class ChallengeAdmin(admin.ModelAdmin):
{'fraction_non_alphanumeric': 0.07896516739939127, 'fraction_numerical': 0.0010145417653026716, 'mean_word_length': 2.9042904290429044, 'pattern_counts': {'":': 2, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2452612', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1577, 'n_words': 374}