<commit_before>from djangotoolbox.auth.models import UserPermissionList, GroupPermissionList, GroupList

def add_to(obj, list_cls, filter):
    obj_list, created = list_cls.objects.get_or_create(**filter)

    obj_list.fk_list.append(obj.id)
    obj_list.save()

def add_permission_to_user(perm, user):
    add_to(perm, UserPermissionList,  {'user': user }) 

def add_user_to_group(user, group):
    add_to(group, GroupList, {'user': user})
        
def add_permission_to_group(perm, group):
    add_to(perm, GroupPermissionList, {'group': group})

<commit_msg>add upadte_permissions_user function (accepts a list of permissions)<commit_after>from djangotoolbox.auth.models import UserPermissionList, GroupPermissionList, GroupList

def add_to(obj, list_cls, filter):
    obj_list, created = list_cls.objects.get_or_create(**filter)

    obj_list.fk_list.append(obj.id)
    obj_list.save()

def add_permission_to_user(perm, user):
    add_to(perm, UserPermissionList,  {'user': user }) 

def add_user_to_group(user, group):
    add_to(group, GroupList, {'user': user})
        
def add_permission_to_group(perm, group):
    add_to(perm, GroupPermissionList, {'group': group})

def update_permissions_user(perms, user):
    obj_list, created = UserPermissionList.objects.get_or_create(user=user)

    old_permissions = list(obj_list.permissions)
    
    for perm in old_permissions:
        try:
            perms.index(perm)
        except ValueError:
            obj_list.fk_list.remove(perm.id)
    
    for perm in perms      :
        try:
            old_permissions.index(perm)
        except ValueError:
            obj_list.fk_list.append(perm.id)
    
    obj_list.save()

{'fraction_non_alphanumeric': 0.10463733650416171, 'fraction_numerical': 0.0, 'mean_word_length': 3.9067055393586005, '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': '3191336', 'n_tokens_mistral': 566, 'n_tokens_neox': 559, 'n_words': 106}