Example #1
0
def append_text_as_asset_content(repo, asset_id, text, display_name,
                                 genus_type):
    asset_content_type_list = get_asset_content_records(repo)

    if genus_type == 'alt-text':
        genus_type = ALT_TEXT_ASSET_CONTENT_GENUS_TYPE
        asset_content_type_list.append(ALT_TEXT_ASSET_CONTENT_RECORD_TYPE)
    elif genus_type == 'mediaDescription':
        genus_type = MEDIA_DESCRIPTION_ASSET_CONTENT_GENUS_TYPE
        asset_content_type_list.append(
            MEDIA_DESCRIPTION_ASSET_CONTENT_RECORD_TYPE)

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

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

    if genus_type == ALT_TEXT_ASSET_CONTENT_GENUS_TYPE:
        acfc.add_alt_text(utilities.create_display_text(text))
    elif genus_type == MEDIA_DESCRIPTION_ASSET_CONTENT_GENUS_TYPE:
        acfc.add_media_description(utilities.create_display_text(text))

    ac = repo.create_asset_content(acfc)

    return repo.get_asset(asset_id), ac
Example #2
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
Example #3
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)
Example #4
0
def add_alt_text_to_asset(repo, asset_id, text):
    asset_contents = repo.get_asset_contents_by_genus_type_for_asset(
        ALT_TEXT_ASSET_CONTENT_GENUS_TYPE, asset_id)
    if asset_contents.available() > 0:
        asset_content = asset_contents.next()
        form = repo.get_asset_content_form_for_update(asset_content.ident)
        form.add_alt_text(utilities.create_display_text(text))
        repo.update_asset_content(form)
    else:
        append_text_as_asset_content(repo, asset_id, text, 'Alt text',
                                     'alt-text')
Example #5
0
def add_media_description_to_asset(repo, asset_id, media_description):
    asset_contents = repo.get_asset_contents_by_genus_type_for_asset(
        MEDIA_DESCRIPTION_ASSET_CONTENT_GENUS_TYPE, asset_id)
    if asset_contents.available() > 0:
        asset_content = asset_contents.next()
        form = repo.get_asset_content_form_for_update(asset_content.ident)
        form.add_media_description(
            utilities.create_display_text(media_description))
        repo.update_asset_content(form)
    else:
        append_text_as_asset_content(repo, asset_id, media_description,
                                     'Description', 'mediaDescription')
Example #6
0
    def PUT(self, repository_id, asset_id, content_id):
        """ replace the asset content data ... keep the same name (ugh),
        but hacking this in for the Onyx workflow for CLIx.

        They want to author in Onyx with high-res images but then replace
        them with the right-sized images via a script. So we'll enable
        this endpoint and let the script find / replace the right
        asset content.
        """
        try:
            x = web.input(inputFile={})
            rm = rutils.get_repository_manager()
            als = rm.get_asset_lookup_session(proxy=rm._proxy)
            als.use_federated_repository_view()
            asset = als.get_asset(utilities.clean_id(asset_id))
            asset_content = rutils.get_asset_content_by_id(
                asset, utilities.clean_id(content_id))

            repository = rm.get_repository(utilities.clean_id(repository_id))
            repository.use_isolated_repository_view()
            form = repository.get_asset_content_form_for_update(
                asset_content.ident)

            try:
                input_file = x['inputFile'].file
            except AttributeError:
                pass  # no file included
            else:
                file_name = x['inputFile'].filename

                data = DataInputStream(input_file)
                data.name = file_name

                # default, but can be over-ridden by user params
                form.set_genus_type(
                    rutils.get_asset_content_genus_type(file_name))

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

                form.set_data(data)

            params = self.data()
            form = utilities.set_form_basics(form, params)

            repository.update_asset_content(form)
            return utilities.convert_dl_object(
                repository.get_asset(asset.ident))
        except Exception as ex:
            utilities.handle_exceptions(ex)