<commit_before>from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from guardian.admin import GuardedModelAdmin
from userena.models import UserenaSignup

from .models import Hauptpunkt, Unterpunkt, ScholariumProfile, Mitwirkende

# Register your models here.


class ProfileAdmin(admin.ModelAdmin):
    list_filter = ('stufe', 'land')
    search_fields = ['user__email']


admin.site.register(ScholariumProfile, ProfileAdmin)


class UnterpunktInline(admin.TabularInline):
    model = Unterpunkt
    fields = ('bezeichnung', 'slug')
    extra = 1


class HauptpunktAdmin(admin.ModelAdmin):
    inlines = [UnterpunktInline]


admin.site.register(Hauptpunkt, HauptpunktAdmin)
admin.site.register(Unterpunkt)
admin.site.register(Mitwirkende)


# von userena.admin kopiert und angepasst
<commit_msg>Grundgeruest/admin: add custom ListFilter for 'stufe'<commit_after>from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from guardian.admin import GuardedModelAdmin
from userena.models import UserenaSignup

from .models import Hauptpunkt, Unterpunkt, ScholariumProfile, Mitwirkende

# Register your models here.


class StufenPlusUnterstuetzerListFilter(admin.SimpleListFilter):
    """
    This filter extends the common list_filter = ('stufe') by the option
    "Unterstützer (alle)", i.e. stufe > 0.
    """
    title = 'Stufe'
    parameter_name = 'stufe'

    extended_stufe_choices = ScholariumProfile.stufe_choices.copy()
    extended_stufe_choices.insert(1, ('unterstuetzer', 'Unterstützer (alle)'))

    def lookups(self, request, model_admin):
        return self.extended_stufe_choices

    def queryset(self, request, queryset):
        if self.value() == 'unterstuetzer':
            return queryset.filter(stufe__gte=1)
        else:
            for stufe_nr, stufe_name in self.extended_stufe_choices:
                if self.value() == str(stufe_nr):
                    return queryset.filter(stufe__exact=stufe_nr)


class ProfileAdmin(admin.ModelAdmin):
    list_filter = (StufenPlusUnterstuetzerListFilter, 'land')
    search_fields = ['user__email']


admin.site.register(ScholariumProfile, ProfileAdmin)


class UnterpunktInline(admin.TabularInline):
    model = Unterpunkt
    fields = ('bezeichnung', 'slug')
    extra = 1


class HauptpunktAdmin(admin.ModelAdmin):
    inlines = [UnterpunktInline]


admin.site.register(Hauptpunkt, HauptpunktAdmin)
admin.site.register(Unterpunkt)
admin.site.register(Mitwirkende)


# von userena.admin kopiert und angepasst

{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.001901863826550019, 'mean_word_length': 4.583864118895966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3997795', 'n_tokens_mistral': 863, 'n_tokens_neox': 849, 'n_words': 182}