<commit_before>""" Django admin pages for organization models """
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from organizations.models import (Organization, OrganizationCourse)


@admin.register(Organization)
class OrganizationAdmin(admin.ModelAdmin):
    """ Admin for the Organization model. """
    actions = ['activate_selected', 'deactivate_selected']
    list_display = ('name', 'short_name', 'logo', 'active',)
    list_filter = ('active',)
    ordering = ('name', 'short_name',)
    readonly_fields = ('created',)

    def get_actions(self, request):
        actions = super(OrganizationAdmin, self).get_actions(request)

        # Remove the delete action.
        del actions['delete_selected']

        return actions

    def activate_selected(self, request, queryset):
        """ Activate the selected entries. """
        queryset.update(active=True)
        count = queryset.count()

        if count == 1:
            message = _('1 organization entry was successfully activated')
        else:
            message = _('{count} organization entries were successfully activated')
            message.format(count=count)  # pylint: disable=no-member

        self.message_user(request, message)

    def deactivate_selected(self, request, queryset):
        """ Deactivate the selected entries. """
        queryset.update(active=False)
        count = queryset.count()

        if count == 1:
            message = _('1 organization entry was successfully deactivated')
        else:
            message = _('{count} organization entries were successfully deactivated')
            message.format(count=count)  # pylint: disable=no-member

        self.message_user(request, message)

    deactivate_selected.short_description = _('Deactivate selected entries')
    activate_selected.short_description = _('Activate selected entries')


@admin.register(OrganizationCourse)
class OrganizationCourseAdmin(admin.ModelAdmin):
    """ Admin for the CourseOrganization model. """
    list_display = ('course_id', 'organization', 'active')

    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        # Only display active Organizations.
        if db_field.name == 'organization':
            kwargs['queryset'] = Organization.objects.filter(active=True)

        return super(OrganizationCourseAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)<commit_msg>Added search to the admin list views<commit_after>""" Django admin pages for organization models """
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from organizations.models import (Organization, OrganizationCourse)


@admin.register(Organization)
class OrganizationAdmin(admin.ModelAdmin):
    """ Admin for the Organization model. """
    actions = ['activate_selected', 'deactivate_selected']
    list_display = ('name', 'short_name', 'logo', 'active',)
    list_filter = ('active',)
    ordering = ('name', 'short_name',)
    readonly_fields = ('created',)
    search_fields = ('name', 'short_name',)

    def get_actions(self, request):
        actions = super(OrganizationAdmin, self).get_actions(request)

        # Remove the delete action.
        del actions['delete_selected']

        return actions

    def activate_selected(self, request, queryset):
        """ Activate the selected entries. """
        queryset.update(active=True)
        count = queryset.count()

        if count == 1:
            message = _('1 organization entry was successfully activated')
        else:
            message = _('{count} organization entries were successfully activated')
            message.format(count=count)  # pylint: disable=no-member

        self.message_user(request, message)

    def deactivate_selected(self, request, queryset):
        """ Deactivate the selected entries. """
        queryset.update(active=False)
        count = queryset.count()

        if count == 1:
            message = _('1 organization entry was successfully deactivated')
        else:
            message = _('{count} organization entries were successfully deactivated')
            message.format(count=count)  # pylint: disable=no-member

        self.message_user(request, message)

    deactivate_selected.short_description = _('Deactivate selected entries')
    activate_selected.short_description = _('Activate selected entries')


@admin.register(OrganizationCourse)
class OrganizationCourseAdmin(admin.ModelAdmin):
    """ Admin for the CourseOrganization model. """
    list_display = ('course_id', 'organization', 'active')
    search_fields = ('course_id', 'organization__name', 'organization__short_name',)

    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        # Only display active Organizations.
        if db_field.name == 'organization':
            kwargs['queryset'] = Organization.objects.filter(active=True)

        return super(OrganizationCourseAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
{'fraction_non_alphanumeric': 0.1081882911392405, 'fraction_numerical': 0.0015822784810126582, 'mean_word_length': 3.588929219600726, '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': '2845511', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1270, 'n_words': 342}