<commit_before>from django.contrib import admin
from advertisements.models import Advertisement, Provider, Click
from django.db.models import Count


class AdvertisementAdmin(admin.ModelAdmin):
    list_display = ('provider', 'ad_type', 'image_thumbnail', 'created', 'enabled', 'total_views')
    date_hierarchy = 'created'
    list_filter = ('ad_type', 'enabled', 'created')

    def total_views(self, obj):
        return obj.click_set.count()
    total_views.admin_order_field = 'clicks'

    def image_thumbnail(self, obj):

        width = 125
        if obj.ad_type == Advertisement.TOP_AD:
            width = 300

        return '<img src="{0}" width="{1}" />'.format(obj.image.url, width)
    image_thumbnail.allow_tags = True

    def queryset(self, request):
        q = super(AdvertisementAdmin, self).queryset(request)
        q = q.annotate(clicks=Count('click'))
        return q

    def make_enabled(self, request, queryset):
        updated_count = queryset.update(enabled=True)
        if updated_count == 1:
            message_beginning = '1 advertisement was'
        else:
            message_beginning = '{0} advertisements were'.format(updated_count)
        self.message_user(request, "{0} successfully enabled.".format(message_beginning))

    make_enabled.short_description = 'Enable the selected advertisements'

    def make_disabled(self, request, queryset):
        updated_count = queryset.update(enabled=False)
        if updated_count == 1:
            message_beginning = '1 advertisement was'
        else:
            message_beginning = '{0} advertisements were'.format(updated_count)
        self.message_user(request, "{0} successfully disabled.".format(message_beginning))

    make_disabled.short_description = 'Disable the selected advertisements'

    actions = [make_enabled, make_disabled]

admin.site.register(Provider)
admin.site.register(Advertisement, AdvertisementAdmin)<commit_msg>Renamed views to clicks<commit_after>from django.contrib import admin
from advertisements.models import Advertisement, Provider, Click
from django.db.models import Count


class AdvertisementAdmin(admin.ModelAdmin):
    list_display = ('provider', 'ad_type', 'image_thumbnail', 'created', 'enabled', 'total_clicks')
    date_hierarchy = 'created'
    list_filter = ('ad_type', 'enabled', 'created')

    def total_clicks(self, obj):
        return obj.click_set.count()
    total_clicks.admin_order_field = 'clicks'

    def image_thumbnail(self, obj):

        width = 125
        if obj.ad_type == Advertisement.TOP_AD:
            width = 300

        return '<img src="{0}" width="{1}" />'.format(obj.image.url, width)
    image_thumbnail.allow_tags = True

    def queryset(self, request):
        q = super(AdvertisementAdmin, self).queryset(request)
        q = q.annotate(clicks=Count('click'))
        return q

    def make_enabled(self, request, queryset):
        updated_count = queryset.update(enabled=True)
        if updated_count == 1:
            message_beginning = '1 advertisement was'
        else:
            message_beginning = '{0} advertisements were'.format(updated_count)
        self.message_user(request, "{0} successfully enabled.".format(message_beginning))

    make_enabled.short_description = 'Enable the selected advertisements'

    def make_disabled(self, request, queryset):
        updated_count = queryset.update(enabled=False)
        if updated_count == 1:
            message_beginning = '1 advertisement was'
        else:
            message_beginning = '{0} advertisements were'.format(updated_count)
        self.message_user(request, "{0} successfully disabled.".format(message_beginning))

    make_disabled.short_description = 'Disable the selected advertisements'

    actions = [make_enabled, make_disabled]

admin.site.register(Provider)
admin.site.register(Advertisement, AdvertisementAdmin)
{'fraction_non_alphanumeric': 0.10718886884823499, 'fraction_numerical': 0.008245297603710384, 'mean_word_length': 3.577830188679245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1514522', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1060, 'n_words': 250}