Beispiel #1
0
def append_file_as_asset_content(repo,
                                 asset_id,
                                 file_name,
                                 file_data,
                                 basics=None):
    asset_content_type_list = get_asset_content_records(repo)

    acfc = repo.get_asset_content_form_for_create(asset_id,
                                                  asset_content_type_list)
    acfc.set_genus_type(get_asset_content_genus_type(file_name))

    try:
        acfc.add_display_name(utilities.create_display_text(file_name))
    except AttributeError:
        acfc.display_name = file_name

    data = DataInputStream(file_data)
    data.name = file_name

    acfc.set_data(data)

    if basics is not None:
        acfc = utilities.set_form_basics(acfc, basics)

    ac = repo.create_asset_content(acfc)

    # really stupid, but set the data again, because for filesystem impl
    # the ID above will be off by one-ish -- we need it to match the
    # AssetContent ID, so re-set it.
    # have to set it above so that the filesystem adapter kicks in on update
    data.seek(0)
    acfu = repo.get_asset_content_form_for_update(ac.ident)
    acfu.set_data(data)
    repo.update_asset_content(acfu)
    return repo.get_asset(asset_id), ac
Beispiel #2
0
def append_vtt_file_as_asset_content(repo,
                                     asset_id,
                                     file_name,
                                     file_data,
                                     locale='en'):
    asset_content_type_list = get_asset_content_records(repo)
    asset_content_type_list.append(VTT_ASSET_CONTENT_RECORD_TYPE)

    acfc = repo.get_asset_content_form_for_create(asset_id,
                                                  asset_content_type_list)
    acfc.set_genus_type(VTT_ASSET_CONTENT_GENUS_TYPE)

    try:
        acfc.add_display_name(utilities.create_display_text(file_name))
    except AttributeError:
        acfc.display_name = file_name

    data = DataInputStream(file_data)
    data.name = file_name

    locale = utilities.convert_two_digit_lang_code_to_locale_object(
        locale).language_type

    acfc.add_vtt_file(data, locale)
    repo.create_asset_content(acfc)
Beispiel #3
0
def add_vtt_file_to_asset(repo, asset_id, file_name, file_data, locale='en'):
    asset_contents = repo.get_asset_contents_by_genus_type_for_asset(
        VTT_ASSET_CONTENT_GENUS_TYPE, asset_id)
    if asset_contents.available() > 0:
        data = DataInputStream(file_data)
        data.name = file_name
        locale = utilities.convert_two_digit_lang_code_to_locale_object(
            locale).language_type
        asset_content = asset_contents.next()
        form = repo.get_asset_content_form_for_update(asset_content.ident)
        if locale in form._my_map['fileIds']:
            form.edit_vtt_file(data, locale)
        else:
            form.add_vtt_file(data, locale)
        repo.update_asset_content(form)
    else:
        append_vtt_file_as_asset_content(repo, asset_id, file_name, file_data,
                                         locale)
def replace_asset_main_content(repo, asset_id, file_name, file_data):
    """search for all non-alt / non-description / non-VTT / non-transcript
    asset contents and pick the first one. Assume that is the main content"""
    asset = repo.get_asset(asset_id)

    asset_contents = asset.get_asset_contents()
    if asset_contents.available() > 0:
        # filter on genusTypeId...grab first non-accessibility one
        for asset_content in asset_contents:
            if asset_content.genus_type in [ALT_TEXT_ASSET_CONTENT_GENUS_TYPE,
                                            MEDIA_DESCRIPTION_ASSET_CONTENT_GENUS_TYPE,
                                            TRANSCRIPT_ASSET_CONTENT_GENUS_TYPE,
                                            VTT_ASSET_CONTENT_GENUS_TYPE]:
                continue

            form = repo.get_asset_content_form_for_update(asset_content.ident)
            data = DataInputStream(file_data)
            data.name = file_name
            form.set_data(data)
            repo.update_asset_content(form)
            break