Ejemplo n.º 1
0
    def get_taxon_parents(content_item):
        parent = (dig(content_item, "links", "parent_taxons", 0)
                  or dig(content_item, "links", "root_taxon", 0))

        if parent is None:
            return []

        return [parent] + get_taxon_parents(parent)
def content_dict_slicer(content_dict, base_fields=[], taxon_fields=[], ppo_fields=[]):
    result = slice(content_dict, base_fields)
    taxons = dig(content_dict, 'links', 'taxons')
    ppo = dig(content_dict, 'links', 'primary_publishing_organisation')

    if taxons:
        result['taxons'] = [slice(taxon, taxon_fields) for taxon in taxons]
    if ppo:
        result['primary_publishing_organisation'] = slice(ppo[0], ppo_fields)

    return result
def untagged_dict_slicer(content_dict, base_fields=[], ppo_fields=[]):
    result = slice(content_dict, base_fields)

    logo = dig(content_dict, 'links', 'organisations', 0, 'details', 'logo', 'formatted-title')
    ppo = dig(content_dict, 'links', 'primary_publishing_organisation')

    if logo:
        result['logo'] = logo
    if ppo:
        result['primary_publishing_organisation'] = slice(ppo[0], ppo_fields)

    return result
 def test_dig_deep_array(self):
     self.assertEqual(
         dig({"a": {
             "b": [1, {
                 'q': 'z'
             }, 3]
         }}, "a", "b", 1, 'q'), 'z')
Ejemplo n.º 5
0
 def taxon_linked_to_root(self, dict):
     if dict is None:
         return False
     links = dict.get("links")
     if "root_taxon" in links:
         return True
     return self.taxon_linked_to_root(dig(links, "parent_taxons", 0))
Ejemplo n.º 6
0
def get_taxons_and_parents_from_links(content_item):
    def get_taxon_parents(content_item):
        parent = (dig(content_item, "links", "parent_taxons", 0)
                  or dig(content_item, "links", "root_taxon", 0))

        if parent is None:
            return []

        return [parent] + get_taxon_parents(parent)

    taxons = dig(content_item, "links", "taxons") or []

    return [[taxon] + get_taxon_parents(taxon) for taxon in taxons]
def navigation_type(content_item):
    mainstream_tags = dig(content_item, 'links', 'mainstream_browse_pages') or []
    curated_items = dig(content_item, 'links', 'ordered_related_items') or []

    step_by_step = dig(content_item, 'links', 'part_of_step_navs') or []
    if len(step_by_step) != 1:
        step_by_step = None

    live_taxons = any(
        taxon.get('phase') == 'live'
        for taxon in dig(content_item, 'links', 'taxons') or []
    )

    if step_by_step:
        return 'step_by_step'
    elif mainstream_tags:
        return 'mainstream'
    elif curated_items:
        return 'curated'
    elif live_taxons:
        return 'taxon'
    else:
        return 'default'
Ejemplo n.º 8
0
def extract_related_organisations(content_item):
    organisations = set()

    primary_publishing_organisation = dig(
        content_item,
        "links",
        "primary_publishing_organisation",
        0,
    )

    if primary_publishing_organisation:
        organisations.add(primary_publishing_organisation["content_id"])

    organisation_items = dig(
        content_item,
        "links",
        "organisations",
    )

    if organisation_items:
        organisations.update(organisation_item["content_id"]
                             for organisation_item in organisation_items)

    return organisations
 def test_empty_dig(self):
     self.assertEqual(dig({}, "a", "b", "c"), None)
 def test_dig_array(self):
     self.assertEqual(dig({"a": {"b": [1, 2, 3]}}, "a", "b", 1), 2)
 def test_dig_none2(self):
     self.assertEqual(dig({"a": {"b": {"c": "d"}}}, "a", "q", "b"), None)
 def test_dig(self):
     self.assertEqual(dig({"a": {"b": {"c": "d"}}}, "a", "b", "c"), "d")
Ejemplo n.º 13
0
 def __number_of_taxons(content_item):
     taxons = dig(content_item, 'links', 'taxons') or []
     return len(
         [taxon for taxon in taxons if __query.taxon_linked_to_root(taxon)])
Ejemplo n.º 14
0
 def __filter_tagged(dict_in):
     return dig(dict_in, 'links', 'taxons') is None
Ejemplo n.º 15
0
 def level_one_taxons(self):
     taxons = dig(self.__get_content_dict('/'), "links", "level_one_taxons")
     return [slice(taxon, self.key_list) for taxon in taxons]
Ejemplo n.º 16
0
 def __child_taxons(taxon):
     return dig(taxon, 'links', 'child_taxons') or []
Ejemplo n.º 17
0
 def content_linked_to_root(self, content_dict):
     if dig(content_dict, "links", "root_taxon") is not None:
         return True
     taxons = dig(content_dict, "links", "taxons") or []
     return any(self.taxon_linked_to_root(taxon) for taxon in taxons)
Ejemplo n.º 18
0
 def child_taxons(self, base_path):
     root_content_dict = self.__get_content_dict(base_path)
     taxons = dig(root_content_dict, "links", "child_taxons") or []
     return self.__recursive_child_taxons(taxons, root_content_dict['content_id'])