<commit_before>from django.contrib import admin
from django import forms
from django.forms import ModelForm
from django.contrib.auth import admin as auth_admin
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin, FlatpageForm
from django.utils.safestring import mark_safe

from codemirror import CodeMirrorTextarea
from suit.admin import SortableModelAdmin


from .forms import UserChangeForm, UserCreationForm, UserLimitedChangeForm
from .filters import OpenRegistrationFilter
from .models import (
    Coach, Event, User, EventPage, EventPageContent, EventPageMenu, Postmortem,
    Sponsor, Story
)


class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'organizers', 'email', 'date', 'city', 'country',
                    'is_on_homepage', 'is_past_event', 'has_stats')
    list_filter = (OpenRegistrationFilter,)
    search_fields = ('city', 'country', 'name')
    filter_horizontal = ['team']

    def get_queryset(self, request):
        qs = super(EventAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(team=request.user)

    def is_past_event(self, obj):
        return not obj.is_upcoming()
    is_past_event.boolean = True

    def has_stats(self, obj):
        return Postmortem.objects.filter(event=obj).exists()
    has_stats.boolean = True

    def get_readonly_fields(self, request, obj=None):
        if obj and not request.user.is_superuser:
            return ('email', 'team')
        return self.readonly_fields


class EventPageAdmin(admin.ModelAdmin):
    list_display = ('title', 'event', 'is_live')
    search_fields = ('title', 'event__name', 'event__city', 'event__country')

    def get_queryset(self, request):
        qs = super(EventPageAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(event__team=request.user)

    def get_readonly_fields(self, request, obj=None):
        if obj and not request.user.is_superuser:
            # Don't let change objects for events that already happened
            if not obj.event.is_upcoming():
                return set([x.name for x in self.model._meta.fields])
        return self.readonly_fields


class ResizableCodeMirror(CodeMirrorTextarea):

    def __init__(self, **kwargs):
        super(ResizableCodeMirror, self).__init__(
            js_var_format='%s_editor', **kwargs)

    @property<commit_msg>New readonly fields in admin<commit_after>from django.contrib import admin
from django import forms
from django.forms import ModelForm
from django.contrib.auth import admin as auth_admin
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin, FlatpageForm
from django.utils.safestring import mark_safe

from codemirror import CodeMirrorTextarea
from suit.admin import SortableModelAdmin


from .forms import UserChangeForm, UserCreationForm, UserLimitedChangeForm
from .filters import OpenRegistrationFilter
from .models import (
    Coach, Event, User, EventPage, EventPageContent, EventPageMenu, Postmortem,
    Sponsor, Story
)


class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'organizers', 'email', 'date', 'city', 'country',
                    'is_on_homepage', 'is_past_event', 'has_stats')
    list_filter = (OpenRegistrationFilter,)
    search_fields = ('city', 'country', 'name')
    filter_horizontal = ['team']

    def get_queryset(self, request):
        qs = super(EventAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(team=request.user)

    def is_past_event(self, obj):
        return not obj.is_upcoming()
    is_past_event.boolean = True

    def has_stats(self, obj):
        return Postmortem.objects.filter(event=obj).exists()
    has_stats.boolean = True

    def get_readonly_fields(self, request, obj=None):
        if obj and not request.user.is_superuser:
            return ('email', 'team', 'is_deleted', 'is_on_homepage')
        return self.readonly_fields


class EventPageAdmin(admin.ModelAdmin):
    list_display = ('title', 'event', 'is_live')
    search_fields = ('title', 'event__name', 'event__city', 'event__country')

    def get_queryset(self, request):
        qs = super(EventPageAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(event__team=request.user)

    def get_readonly_fields(self, request, obj=None):
        if obj and not request.user.is_superuser:
            # Don't let change objects for events that already happened
            if not obj.event.is_upcoming():
                return set([x.name for x in self.model._meta.fields])
            else:
                return ('url', 'is_deleted')
        return self.readonly_fields


class ResizableCodeMirror(CodeMirrorTextarea):

    def __init__(self, **kwargs):
        super(ResizableCodeMirror, self).__init__(
            js_var_format='%s_editor', **kwargs)

    @property
{'fraction_non_alphanumeric': 0.09701492537313433, 'fraction_numerical': 0.0, 'mean_word_length': 3.5190771960958296, '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': '4958476', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1446, 'n_words': 377}