<commit_before>"""
Copied over from django.contrib.auth.management
"""
from django.dispatch import dispatcher
from django.db.models import get_models, signals

def _get_permission_codename(action, opts):
    return u'%s_%s' % (action, opts.object_name.lower())

def _get_all_permissions(opts):
    "Returns (codename, name) for all permissions in the given opts."
    return [ (_get_permission_codename('view', opts), u'Can view %s' % (opts.verbose_name_raw)), ]

def create_permissions(app, created_models, verbosity):
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.auth.models import Permission
    app_models = get_models(app)
    if not app_models:
        return
    for klass in app_models:
        ctype = ContentType.objects.get_for_model(klass)
        for codename, name in _get_all_permissions(klass._meta):
            p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
                defaults={'name': name, 'content_type': ctype})
            if created and verbosity >= 2:
                print "Adding permission '%s'" % p

dispatcher.connect(create_permissions, signal=signals.post_syncdb)
<commit_msg>Update signals for latest django<commit_after>"""
Copied over from django.contrib.auth.management
"""
from django.dispatch import dispatcher
from django.db.models import get_models, signals

def _get_permission_codename(action, opts):
    return u'%s_%s' % (action, opts.object_name.lower())

def _get_all_permissions(opts):
    "Returns (codename, name) for all permissions in the given opts."
    return [ (_get_permission_codename('view', opts), u'Can view %s' % (opts.verbose_name_raw)), ]

def create_permissions(app, created_models, verbosity, **kwargs):
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.auth.models import Permission
    app_models = get_models(app)
    if not app_models:
        return
    for klass in app_models:
        ctype = ContentType.objects.get_for_model(klass)
        for codename, name in _get_all_permissions(klass._meta):
            p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
                defaults={'name': name, 'content_type': ctype})
            if created and verbosity >= 2:
                print "Adding permission '%s'" % p

# TODO: check functionality - its new signals in django 1.0.x
signals.post_syncdb.connect(create_permissions)

{'fraction_non_alphanumeric': 0.10024252223120453, 'fraction_numerical': 0.0016168148746968471, 'mean_word_length': 3.9798792756539236, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5756462', 'n_tokens_mistral': 739, 'n_tokens_neox': 731, 'n_words': 191}