<commit_before>from django.contrib import admin
from resources.models import ResourceProperty, Page, Weblink, Resource,\
    ResourceTranslation
from mptt.admin import MPTTModelAdmin, FeinCMSModelAdmin
import datetime
from django.conf import settings

class ResourcePropertyInline(admin.TabularInline):
    model = ResourceProperty

class ResourceAdmin(FeinCMSModelAdmin):
    list_display = ('title', 
                    'title_link', 
                    'get_absolute_url',
                    'created', 
                    'modified', 
                    'is_published', 
                    'translation_pool',
                    'in_menu',
                    'language',
                    'author')
    list_filter = ('is_published', 'in_menu', 'author', 'language')
    inlines = (ResourcePropertyInline,)
    actions = ('make_published', 'make_unpublished', 'link')
    prepopulated_fields = {'slug': ('title',)}
    
    def __init__(self, *args, **kwargs): 
        super(ResourceAdmin, self).__init__(*args, **kwargs)
        self.list_display_links = (None, )
    
    def title_link(self,obj):
        return u'<a href="%s">%s</a>' % (obj.get_edit_link(),
                                         obj.content_type)
    title_link.allow_tags = True
    title_link.short_description = "Edit"
    
    def make_do(self, request, queryset, label, *args, **make):
        rows_updated = queryset.update(**make)
        if rows_updated == 1:
            message_bit = "1 resource was"
        else:
            message_bit = "%s resources were" % rows_updated
        self.message_user(request, "%s successfully %s." % (message_bit, label))
    
    def make_published(self, request, queryset):
        return self.make_do(request, queryset, "marked as published", 
                            is_published=True, published=datetime.datetime.now())
<commit_msg>Remove add permission for Resource admin, so no parent resources can be created<commit_after>from django.contrib import admin
from resources.models import ResourceProperty, Page, Weblink, Resource,\
    ResourceTranslation
from mptt.admin import MPTTModelAdmin, FeinCMSModelAdmin
import datetime
from django.conf import settings

class ResourcePropertyInline(admin.TabularInline):
    model = ResourceProperty

class ResourceAdmin(FeinCMSModelAdmin):
    list_display = ('title', 
                    'title_link', 
                    'get_absolute_url',
                    'created', 
                    'modified', 
                    'is_published', 
                    'translation_pool',
                    'in_menu',
                    'language',
                    'author')
    list_filter = ('is_published', 'in_menu', 'author', 'language')
    inlines = (ResourcePropertyInline,)
    actions = ('make_published', 'make_unpublished', 'link')
    prepopulated_fields = {'slug': ('title',)}
    
    def __init__(self, *args, **kwargs): 
        super(ResourceAdmin, self).__init__(*args, **kwargs)
        self.list_display_links = (None, )
    
    def has_add_permission(self, request):
        return False
    
    def title_link(self,obj):
        return u'<a href="%s">%s</a>' % (obj.get_edit_link(),
                                         obj.content_type)
    title_link.allow_tags = True
    title_link.short_description = "Edit"
    
    def make_do(self, request, queryset, label, *args, **make):
        rows_updated = queryset.update(**make)
        if rows_updated == 1:
            message_bit = "1 resource was"
        else:
            message_bit = "%s resources were" % rows_updated
        self.message_user(request, "%s successfully %s." % (message_bit, label))
    
    def make_published(self, request, queryset):
        return self.make_do(request, queryset, "marked as published", 
                            is_published=True, published=datetime.datetime.now())

{'fraction_non_alphanumeric': 0.10836550836550836, 'fraction_numerical': 0.0010296010296010295, 'mean_word_length': 2.318531169940222, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2312673', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1038, 'n_words': 245}