<commit_before>from django.contrib import admin
from blogdor.models import Post
import datetime

class PostAdmin(admin.ModelAdmin):
    
    list_display = ('title','author','date_published','is_published','comments_enabled')
    list_display_links = ('title',)
    list_filter = ('author','is_published','comments_enabled')
    prepopulated_fields = {'slug': ('title',)}
    exclude = ('date_published','is_published',)
    search_fields = ('title','content')
    actions = ('publish_posts','recall_posts')
    
    def publish_posts(self, request, queryset):
        """
        Mark select posts as published and set date_published if it does not exist.
        """
        now = datetime.datetime.now()
        published_count = queryset.publish()
        s = published_count == 1 and 'posts' or 'post'
        self.message_user(request, "%i %s published" % (published_count, s))
    publish_posts.short_description = "Publish posts"
    
    def recall_posts(self, request, queryset):
        """
        Recall published posts, but leave date_published as is.
        """
        recalled_count = queryset.recall()
        s = recalled_count == 1 and 'posts' or 'post'
        self.message_user(request, "%i %s recalled" % (recalled_count, s))
    recall_posts.short_description = "Recall published posts"

admin.site.register(Post, PostAdmin)<commit_msg>add enable/disable comments to admin<commit_after>from django.contrib import admin
from blogdor.models import Post
import datetime

class PostAdmin(admin.ModelAdmin):
    
    list_display = ('title','author','date_published','is_published','comments_enabled')
    list_display_links = ('title',)
    list_filter = ('author','is_published','comments_enabled')
    prepopulated_fields = {'slug': ('title',)}
    exclude = ('date_published','is_published',)
    search_fields = ('title','content')
    actions = ('publish_posts','recall_posts','enable_comments','disable_comments')
    
    def publish_posts(self, request, queryset):
        """
        Mark select posts as published and set date_published if it does not exist.
        """
        now = datetime.datetime.now()
        count = queryset.publish()
        self.message_user(request, "%i post(s) published" % count)
    publish_posts.short_description = "Publish posts"
    
    def recall_posts(self, request, queryset):
        """
        Recall published posts, but leave date_published as is.
        """
        count = queryset.recall()
        self.message_user(request, "%i post(s) recalled" % count)
    recall_posts.short_description = "Recall published posts"
    
    def enable_comments(self, request, queryset):
        count = queryset.update(comments_enabled=True)
        self.message_user(request, "Comments enabled on %i post(s)" % count)
    enable_comments.short_description = "Enable comments"

    def disable_comments(self, request, queryset):
        count = queryset.update(comments_enabled=False)
        self.message_user(request, "Comments disabled on %i post(s)" % count)
    disable_comments.short_description = "Disable comments"

admin.site.register(Post, PostAdmin)
{'fraction_non_alphanumeric': 0.11932181701855406, 'fraction_numerical': 0.0006397952655150352, 'mean_word_length': 3.7093373493975905, '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': '5126798', 'n_tokens_mistral': 873, 'n_tokens_neox': 865, 'n_words': 213}