'Use this method to create users.
Default permissions on page and text plugin are added if creating a
non-superuser and `add_default_permissions` is set.
Set `permissions` parameter to an iterable of permission codes to add
custom permissios.'

def _create_user(self, username, is_staff=False, is_superuser=False, is_active=True, add_default_permissions=False, permissions=None):

    User = get_user_model()
    fields = dict(email=(username + '@django-cms.org'), last_login=now(), is_staff=is_staff, is_active=is_active, is_superuser=is_superuser)
    if (get_user_model().USERNAME_FIELD != 'email'):
        fields[get_user_model().USERNAME_FIELD] = username
    user = User(**fields)
    user.set_password(getattr(user, get_user_model().USERNAME_FIELD))
    user.save()
    if (is_staff and (not is_superuser) and add_default_permissions):
        user.user_permissions.add(Permission.objects.get(codename='add_text'))
        user.user_permissions.add(Permission.objects.get(codename='delete_text'))
        user.user_permissions.add(Permission.objects.get(codename='change_text'))
        user.user_permissions.add(Permission.objects.get(codename='publish_page'))
        user.user_permissions.add(Permission.objects.get(codename='add_page'))
        user.user_permissions.add(Permission.objects.get(codename='change_page'))
        user.user_permissions.add(Permission.objects.get(codename='delete_page'))
    if (is_staff and (not is_superuser) and permissions):
        for permission in permissions:
            user.user_permissions.add(Permission.objects.get(codename=permission))
    return user
