<commit_before>from django.contrib import admin

from bluebottle.surveys.models import Survey, Question, Response, Answer, AggregateAnswer


class QuestionAdminInline(admin.StackedInline):

    model = Question
    readonly_fields = ('type', )
    fields = readonly_fields + ('display', 'display_title',
                                'display_style',
                                'left_label', 'right_label',
                                'aggregation')

    extra = 0

    def sub_questions(self, obj):
        return [sub.title for sub in obj.subquestion_set.all()]

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False

    can_delete = False


class SurveyAdmin(admin.ModelAdmin):
    model = Survey
    readonly_fields = ('title', 'link', 'created', 'updated')
    fields = ('remote_id', 'last_synced') + readonly_fields
    list_display = ('title', 'created')
    inlines = [QuestionAdminInline]

    actions = ['synchronize_surveys']

    def synchronize_surveys(self, request, queryset):
        for survey in queryset:
            survey.synchronize()

admin.site.register(Survey, SurveyAdmin)


class AnswerAdminInline(admin.TabularInline):
    model = Answer<commit_msg>Show response count in survey admin<commit_after>from django.contrib import admin

from bluebottle.surveys.models import Survey, Question, Response, Answer, AggregateAnswer


class QuestionAdminInline(admin.StackedInline):

    model = Question
    readonly_fields = ('type', )
    fields = readonly_fields + ('display', 'display_title',
                                'display_style',
                                'left_label', 'right_label',
                                'aggregation')

    extra = 0

    def sub_questions(self, obj):
        return [sub.title for sub in obj.subquestion_set.all()]

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False

    can_delete = False


class SurveyAdmin(admin.ModelAdmin):
    model = Survey
    readonly_fields = ('title', 'link', 'created', 'updated')
    fields = ('remote_id', 'last_synced') + readonly_fields
    list_display = ('title', 'last_synced', 'response_count')

    inlines = [QuestionAdminInline]

    actions = ['synchronize_surveys']

    def response_count(self, obj):
        return obj.response_set.count()

    def synchronize_surveys(self, request, queryset):
        for survey in queryset:
            survey.synchronize()

admin.site.register(Survey, SurveyAdmin)


class AnswerAdminInline(admin.TabularInline):
    model = Answer
{'fraction_non_alphanumeric': 0.09981308411214954, 'fraction_numerical': 0.0007476635514018691, 'mean_word_length': 2.878260869565217, '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': '5033226', 'n_tokens_mistral': 762, 'n_tokens_neox': 741, 'n_words': 180}