def paragraphs_links_and_images(self, in_para_list): ''' assign_paragraphs - append the paragraph values needed with the keys that are expected ''' kwargs = { 'para_slugs': [], 'group_slugs': [], 'input_key': 'para_display', 'create_modal_links': not self.is_modal } link_helper = ParaLinkHelper(**kwargs) out_para_list = [] for para in in_para_list: data = link_helper.links_from_indicators( para['text'], self.input_data['slug_to_lookup_link']) para['text'] = data['text'] para = para_helpers.add_image_information(para) out_para_list.append(self.paragraph(para)) return out_para_list
def unique_slug_lists(self, para_text): ''' unique_slug_lists extracts the slugs from the paragraph using the link indicators, thus ensuring that the resulting array of slugs used for lookup is unique :param para_text: text from one paragraph that is being retrieved :type para: str :return: list of slugs used for looking up data needed for internal links :rtype: list of strings ''' kwargs = { 'para_slugs': self.para_slugs, 'group_slugs': self.group_slugs, 'input_key': 'db_retriever' } link_helper = ParaLinkHelper(**kwargs) data = link_helper.links_from_indicators(para_text, {}) self.para_slugs = data['para_slugs'] self.group_slugs = data['group_slugs']
def replace_slugs_in_paragraph_links(indicators, existing_slug, new_slug, updating=False): ''' replace_slugs_in_paragraph_links is a convenience method that finds the paragraphs to update when slugs are updated. The process starts by running the above method: update_slugs_field_and_links Read the update_slugs_field_and_links comments for some caveats :param indicators: link indicators to know the type of links and records for the slugs (constants/para_lookup.py) :type indicators: dict :param existing_slug: slug value you will be replacing :type existing_slug: str :param new_slug: new slug value :type new_slug: str :param updating: defaults to False - only does db update it True :type updating: bool, optional ''' kwargs = { 'input_key': 'slug_update', 'slug_data': { 'existing_slug': existing_slug, 'new_slug': new_slug } } link_helper = ParaLinkHelper(**kwargs) paragraphs_to_update = paragraph_slug_replacement(indicators, link_helper) updater = ParaDbMethods(updating) for para in paragraphs_to_update: find_dict = {'id': para.id} create_dict = {'id': para.id, 'text': para.text} updater.find_and_update_record(Paragraph, find_dict, create_dict)
def test_wrong_input_key_throws_value_error(): kwargs = {'input_key': 'random'} with pytest.raises(ValueError): ParaLinkHelper(**kwargs)
def link_helper_slug_update(): kwargs = key_word_args.KWARGS_LINK_HELPER_SLUG_UPDATE link_helper = ParaLinkHelper(**kwargs) return link_helper
def link_helper_db_retriever(): kwargs = key_word_args.KWARGS_LINK_HELPER_DB_RETRIEVER link_helper = ParaLinkHelper(**kwargs) return link_helper
def link_helper_page_para_display(): kwargs = key_word_args.KWARGS_LINK_HELPER_PARA_DISPLAY kwargs['create_modal_links'] = False link_helper = ParaLinkHelper(**kwargs) return link_helper