<commit_before>import permissions

from models import Level, Block, LevelBlock, LevelDecor, Decor, Theme, Character


##########
# Levels #
##########

def get_loadable_levels(user):
    if user.is_anonymous():
        return [], []

    owned_levels = user.userprofile.levels.iterator()
    shared_levels = (level for level in user.shared.iterator() if permissions.can_load_level(user, level))
    return owned_levels, shared_levels


def get_decor(level):
    """ Helper method parsing decor into a dictionary format 'sendable' to javascript. """
    decorData = []
    for ld in LevelDecor.objects.filter(level=level):
        decor = Decor.objects.get(name=ld.decorName, theme=level.theme)
        decorData.append({
            'x': int(ld.x),
            'y': int(ld.y),
            'decorName': str(ld.decorName),
            'width': int(decor.width),
            'height': int(decor.height),
            'url': str(decor.url),
        })

    return decorData


def set_decor(level, decor):
    """ Helper method creating LevelDecor objects given a list of decor in dictionary form."""
    LevelDecor.objects.filter(level=level).delete()

    level_decors = []
    for data in decor:
        level_decors.append(LevelDecor(
            level_id=level.id,
            x=data['x'],
            y=data['y'],
            decorName=data['decorName']
        ))
    LevelDecor.objects.bulk_create(level_decors)


def get_blocks(level):
    """ Helper method parsing blocks into a dictionary format 'sendable' to javascript. """
    levelBlocks = LevelBlock.objects.filter(level=level).order_by('type')
    return [{'type': lb.type.type, 'number': lb.number} for lb in levelBlocks]


def set_blocks(level, blocks):<commit_msg>#376 getting the z-index added to the JS object<commit_after>import permissions

from models import Level, Block, LevelBlock, LevelDecor, Decor, Theme, Character


##########
# Levels #
##########

def get_loadable_levels(user):
    if user.is_anonymous():
        return [], []

    owned_levels = user.userprofile.levels.iterator()
    shared_levels = (level for level in user.shared.iterator() if permissions.can_load_level(user, level))
    return owned_levels, shared_levels


def get_decor(level):
    """ Helper method parsing decor into a dictionary format 'sendable' to javascript. """
    decorData = []
    for ld in LevelDecor.objects.filter(level=level):
        decor = Decor.objects.get(name=ld.decorName, theme=level.theme)
        decorData.append({
            'x': int(ld.x),
            'y': int(ld.y),
            'z': int(decor.z_index),
            'decorName': str(ld.decorName),
            'width': int(decor.width),
            'height': int(decor.height),
            'url': str(decor.url),
        })

    return decorData


def set_decor(level, decor):
    """ Helper method creating LevelDecor objects given a list of decor in dictionary form."""
    LevelDecor.objects.filter(level=level).delete()

    level_decors = []
    for data in decor:
        level_decors.append(LevelDecor(
            level_id=level.id,
            x=data['x'],
            y=data['y'],
            decorName=data['decorName']
        ))
    LevelDecor.objects.bulk_create(level_decors)


def get_blocks(level):
    """ Helper method parsing blocks into a dictionary format 'sendable' to javascript. """
    levelBlocks = LevelBlock.objects.filter(level=level).order_by('type')
    return [{'type': lb.type.type, 'number': lb.number} for lb in levelBlocks]


def set_blocks(level, blocks):
{'fraction_non_alphanumeric': 0.1341083073433513, 'fraction_numerical': 0.0008505812305075135, 'mean_word_length': 3.022805017103763, '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': '6403771', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1034, 'n_words': 255}