diff --git a/newsroom/wire/block_media/download_items.py b/newsroom/wire/block_media/download_items.py index c360205a..2d8d2778 100644 --- a/newsroom/wire/block_media/download_items.py +++ b/newsroom/wire/block_media/download_items.py @@ -66,12 +66,12 @@ def remove_editors_media(item, allowed_tags): if m and m.group(1): figure = comment.getnext() for elem in figure.iterchildren(): - if elem.tag in excluded_tags: - if 'data-disable-download' not in elem.attrib or elem.attrib['data-disable-download'] != 'true': - elem.attrib['data-disable-download'] = 'true' + if (elem.tag in excluded_tags + and ('data-disable-download' not in elem.attrib + or elem.attrib['data-disable-download'] != 'true')): + elem.attrib['data-disable-download'] = 'true' html_updated = True break - if not download_social_tag: social_media_embeds = root_elem.xpath('//div[@class="embed-block"]') for social_media_embed in social_media_embeds: diff --git a/newsroom/wire/block_media/filter_media.py b/newsroom/wire/block_media/filter_media.py index d7c9313c..2de6d29b 100644 --- a/newsroom/wire/block_media/filter_media.py +++ b/newsroom/wire/block_media/filter_media.py @@ -93,7 +93,8 @@ def get_allowed_tags(embedded_data): allowed_tags = { 'display_tags': [tag for tag, (display_key, _) in tag_mapping.items() if embedded_data.get(display_key, False)], - 'download_tags': [tag for tag, (_, download_key) in tag_mapping.items() if embedded_data.get(download_key, False)], + 'download_tags': [tag for tag, (_, download_key) in tag_mapping.items() + if embedded_data.get(download_key, False)], } return allowed_tags diff --git a/newsroom/wire/search.py b/newsroom/wire/search.py index a3905a15..68e105d3 100644 --- a/newsroom/wire/search.py +++ b/newsroom/wire/search.py @@ -543,18 +543,17 @@ def get_permitted_products(self): def permission_embeds_in_item(self, item, permitted_products): disable_download = [] for key, embed_item in item.get("associations", {}).items(): - if key.startswith("editor_") and embed_item and (embed_item.get('type', '')) in ['audio', 'video', 'picture']: - # get the list of products that the embedded item matched in Superdesk + if (key.startswith("editor_") and embed_item + and embed_item.get('type', '') in ['audio', 'video', 'picture']): embed_products = [p.get('code') for p in ((item.get('associations') or {}).get(key) or {}).get('products', [])] if not len(set(embed_products) & set(permitted_products)): disable_download.append(key) + if len(disable_download) == 0: logger.info("No embedded items require download disabling.") return - # logger.info( - # f"Disable download for the following embedded items:- {disable_download}- {item['body_html']}-{item['associations']}") root_elem = lxml_html.fromstring(item.get('body_html', '')) regex = r" EMBED START (?:Video|Audio|Image) {id: \"editor_([0-9]+)" @@ -567,8 +566,8 @@ def permission_embeds_in_item(self, item, permitted_products): for elem in figure.iterchildren(): if elem.tag in ['video', 'audio', 'img']: if "editor_" + m.group(1) in disable_download: - # elem.attrib['data-disable-download'] = 'true' - if 'data-disable-download' not in elem.attrib or elem.attrib['data-disable-download'] != 'true': + if 'data-disable-download' not in elem.attrib or \ + elem.attrib['data-disable-download'] != 'true': elem.attrib['data-disable-download'] = 'true' html_updated = True if elem.text and ' EMBED END ' in elem.text: