<commit_before>import csv

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.db.models import Count
from django.http import HttpResponse

from moderator.moderate.models import Event, MozillianProfile, Question, Vote

# Unregister User from admin to attach MozillianProfile
admin.site.unregister(User)


def export_questions_csv(modeladmin, request, queryset):
    """Export questions csv."""
    filename = "questions.csv"
    response = HttpResponse(mimetype="text/csv")
    response["Content-Disposition"] = 'attachment; filename="%s"' % filename

    writer = csv.writer(response)

    for e in queryset:
        writer.writerow([e.name])
        questions = e.questions.annotate(vote_count=Count("votes")).order_by(
            "-vote_count"
        )
        for q in questions:
            writer.writerow([q.question.encode("utf-8"), q.votes.count()])

    return response


class MozillianProfileInline(admin.StackedInline):
    model = MozillianProfile
    fk_name = "user"


class UserAdmin(UserAdmin):
    inlines = [MozillianProfileInline]
    list_display = (
        "username",
        "email",
        "first_name",
        "last_name",
        "is_nda_member",
        "is_staff",
    )
    search_fields = ["email", "first_name", "last_name"]

    def is_nda_member(self, obj):
        return obj.userprofile.is_nda_member

    is_nda_member.boolean = True


class QuestionInline(admin.StackedInline):
    model = Question
    fields = (
        "addressed",
        "question",
        "asked_by",
    )
    readonly_fields = (
        "question",
        "asked_by",
    )
    extra = 0


class EventAdmin(admin.ModelAdmin):
    inlines = [QuestionInline]
    list_display = (
        "name",
        "questions_count",
        "created_at",
        "archived",
        "is_nda",
    )
    actions = [export_questions_csv]
    list_filter = ["archived"]
    autocomplete_fields = ["moderators"]


class QuestionAdmin(admin.ModelAdmin):
    list_display = ("id", "asked_by", "event")


admin.site.register(User, UserAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(Question, QuestionAdmin)
admin.site.register(Vote)<commit_msg>Add more fields in list_display<commit_after>import csv

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.db.models import Count
from django.http import HttpResponse

from moderator.moderate.models import Event, MozillianProfile, Question, Vote

# Unregister User from admin to attach MozillianProfile
admin.site.unregister(User)


def export_questions_csv(modeladmin, request, queryset):
    """Export questions csv."""
    filename = "questions.csv"
    response = HttpResponse(mimetype="text/csv")
    response["Content-Disposition"] = 'attachment; filename="%s"' % filename

    writer = csv.writer(response)

    for e in queryset:
        writer.writerow([e.name])
        questions = e.questions.annotate(vote_count=Count("votes")).order_by(
            "-vote_count"
        )
        for q in questions:
            writer.writerow([q.question.encode("utf-8"), q.votes.count()])

    return response


class MozillianProfileInline(admin.StackedInline):
    model = MozillianProfile
    fk_name = "user"


class UserAdmin(UserAdmin):
    inlines = [MozillianProfileInline]
    list_display = (
        "username",
        "email",
        "first_name",
        "last_name",
        "is_nda_member",
        "is_staff",
    )
    search_fields = ["email", "first_name", "last_name"]

    def is_nda_member(self, obj):
        return obj.userprofile.is_nda_member

    is_nda_member.boolean = True


class QuestionInline(admin.StackedInline):
    model = Question
    fields = (
        "addressed",
        "question",
        "asked_by",
    )
    readonly_fields = (
        "question",
        "asked_by",
    )
    extra = 0


class EventAdmin(admin.ModelAdmin):
    inlines = [QuestionInline]
    list_display = (
        "name",
        "questions_count",
        "created_at",
        "archived",
        "is_nda",
    )
    actions = [export_questions_csv]
    list_filter = ["archived"]
    autocomplete_fields = ["moderators"]


class QuestionAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "asked_by",
        "event",
        "question",
        "is_anonymous",
    )


admin.site.register(User, UserAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(Question, QuestionAdmin)
admin.site.register(Vote)
{'fraction_non_alphanumeric': 0.11386893098192902, 'fraction_numerical': 0.0008708904855214457, 'mean_word_length': 3.0333625987708515, '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': '6930808', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1386, 'n_words': 285}