<commit_before>from django.contrib import admin
from django.forms import ModelForm
from django.contrib.auth import admin as auth_admin

from suit_redactor.widgets import RedactorWidget
from suit.admin import SortableModelAdmin, SortableTabularInline

from .models import *
from .forms import UserChangeForm, UserCreationForm, UserLimitedChangeForm


class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'organizers', 'date', 'city', 'country', 'is_on_homepage')
    search_fields = ('city', 'country', 'name')

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


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).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 EventPageContentForm(ModelForm):
    class Meta:
        widgets = {
            'content': RedactorWidget(editor_options={'lang': 'en'})
        }<commit_msg>Added 'is_past_event' and 'has_stats' custom fields to EventAdmin<commit_after>from django.contrib import admin
from django.forms import ModelForm
from django.contrib.auth import admin as auth_admin

from suit_redactor.widgets import RedactorWidget
from suit.admin import SortableModelAdmin, SortableTabularInline

from .models import *
from .forms import UserChangeForm, UserCreationForm, UserLimitedChangeForm


class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'organizers', 'date', 'city', 'country', 'is_on_homepage', 'is_past_event', 'has_stats')
    search_fields = ('city', 'country', 'name')

    def get_queryset(self, request):
        qs = super(EventAdmin, self).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


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).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 EventPageContentForm(ModelForm):
    class Meta:
        widgets = {
            'content': RedactorWidget(editor_options={'lang': 'en'})
        }
{'fraction_non_alphanumeric': 0.10240963855421686, 'fraction_numerical': 0.0, 'mean_word_length': 3.4877734877734876, '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': '3338360', 'n_tokens_mistral': 1032, 'n_tokens_neox': 998, 'n_words': 258}