<commit_before>from django.contrib.auth.models import User, Group
from ztreeauth.models import LocalUser
from ztree.component.factories import create_node_factory

import logging
logger = logging.getLogger('ztreeauth')


def local_user_factory(request, local_user_content_type, **kwargs):
    logger.info('creating local user "%s" at %s with groups %s' % (kwargs['username'], (request.tree_context.node and request.tree_context.node.absolute_path), kwargs['groups']))

    user = User(username=kwargs['username'])
    user.set_password(kwargs['<PASSWORD>'])
    user.save()

    # create LocalUser
    local_user = LocalUser(user=user)
    local_user.save()

    # set auth groups for local_user
    for group_name in kwargs['groups']:
        grp = Group.objects.get(name=group_name)
        local_user.groups.add(grp)

    if hasattr(request, 'user'):
        username = request.user.username
    else:<commit_msg>Fix package path issue caused by previous refactoring commit.<commit_after>from django.contrib.auth.models import User, Group
from ztreeauth.models import LocalUser
from ztreecrud.component.factories import create_node_factory

import logging
logger = logging.getLogger('ztreeauth')


def local_user_factory(request, local_user_content_type, **kwargs):
    logger.info('creating local user "%s" at %s with groups %s' % (kwargs['username'], (request.tree_context.node and request.tree_context.node.absolute_path), kwargs['groups']))

    user = User(username=kwargs['username'])
    user.set_password(kwargs['<PASSWORD>'])
    user.save()

    # create LocalUser
    local_user = LocalUser(user=user)
    local_user.save()

    # set auth groups for local_user
    for group_name in kwargs['groups']:
        grp = Group.objects.get(name=group_name)
        local_user.groups.add(grp)

    if hasattr(request, 'user'):
        username = request.user.username
    else:
{'fraction_non_alphanumeric': 0.11411889596602973, 'fraction_numerical': 0.0, 'mean_word_length': 4.511695906432749, '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': '5428549', 'n_tokens_mistral': 563, 'n_tokens_neox': 558, 'n_words': 131}