<commit_before># coding: utf-8
from ckeditor.widgets import CKEditorWidget

from django.contrib import admin
from django.db.models import Count
from django import forms

from places.models import Region, Country, Area, Place
from scheduler.models import Need, Topics, Location


# @admin.register(Organization)
# class OrganizationAdmin(admin.ModelAdmin):
#     list_display = ('name', )
#     search_fields = ('name', 'description')


class NeedAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        return super(NeedAdmin, self).get_queryset(request) \
            .annotate(volunteer_count=Count('helpers')) \
            .prefetch_related('helpers',
                              'helpers__user')

    def get_volunteer_count(self, obj):
        return obj.volunteer_count

    def get_volunteer_names(self, obj):
        def _format_username(user):
            full_name = user.get_full_name()
            if full_name:
                return u'{} ("{}")'.format(full_name, user.username)
            return u'"{}"'.format(user.username)

        return u", ".join(_format_username(volunteer.user) for volunteer in
                          obj.helpers.all())

    list_display = (
        'id', 'topic', 'starting_time', 'ending_time', 'slots',
        'get_volunteer_count', 'get_volunteer_names'
    )

    search_fields = ('id', 'topic__title',)
    list_filter = ('location',)


admin.site.register(Need, NeedAdmin)


class TopicsAdminForm(forms.ModelForm):
    description = forms.CharField(widget=CKEditorWidget())


class TopicsAdmin(admin.ModelAdmin):
    list_display = ('title', 'id')
    search_fields = ('id',)
    form = TopicsAdminForm


admin.site.register(Topics, TopicsAdmin)


@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        return Location.objects.select_related('place',
                                               'place__area',
                                               'place__area__region',
                                               'place__area__region__country')
<commit_msg>Make topics admin more usable<commit_after># coding: utf-8
from ckeditor.widgets import CKEditorWidget

from django.contrib import admin
from django.db.models import Count
from django import forms

from places.models import Region, Country, Area, Place
from scheduler.models import Need, Topics, Location


# @admin.register(Organization)
# class OrganizationAdmin(admin.ModelAdmin):
#     list_display = ('name', )
#     search_fields = ('name', 'description')


class NeedAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        return super(NeedAdmin, self).get_queryset(request) \
            .annotate(volunteer_count=Count('helpers')) \
            .prefetch_related('helpers',
                              'helpers__user')

    def get_volunteer_count(self, obj):
        return obj.volunteer_count

    def get_volunteer_names(self, obj):
        def _format_username(user):
            full_name = user.get_full_name()
            if full_name:
                return u'{} ("{}")'.format(full_name, user.username)
            return u'"{}"'.format(user.username)

        return u", ".join(_format_username(volunteer.user) for volunteer in
                          obj.helpers.all())

    list_display = (
        'id', 'topic', 'starting_time', 'ending_time', 'slots',
        'get_volunteer_count', 'get_volunteer_names'
    )

    search_fields = ('id', 'topic__title',)
    list_filter = ('location',)


admin.site.register(Need, NeedAdmin)


class TopicsAdminForm(forms.ModelForm):
    description = forms.CharField(widget=CKEditorWidget())


class TopicsAdmin(admin.ModelAdmin):
    list_display = ('title', 'workplace', 'description')
    list_editable = ('workplace', )
    search_fields = ('id',)
    form = TopicsAdminForm


admin.site.register(Topics, TopicsAdmin)


@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        return Location.objects.select_related('place',
                                               'place__area',
                                               'place__area__region',
                                               'place__area__region__country')

{'fraction_non_alphanumeric': 0.11223055295220244, 'fraction_numerical': 0.00046860356138706655, 'mean_word_length': 2.6362862010221466, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2179905', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1178, 'n_words': 245}