Skip to content

Commit

Permalink
Added label to Concept class #10
Browse files Browse the repository at this point in the history
This change has not yet been sufficiently tested!
  • Loading branch information
manusimidt committed Jul 2, 2021
1 parent bdc0abd commit 605ed2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions xbrl/linkbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ def parse_linkbase(linkbase_path: str, linkbase_type: LinkbaseType) -> Linkbase:
locator_href = loc.attrib[XLINK_NS + 'href']
if not locator_href.startswith('http'):
# resolve the path
# todo, try to get the URL here, instead of the path!!!
locator_href = resolve_uri(linkbase_path, locator_href)
locator_map[loc_label] = Locator(locator_href, loc_label)

Expand Down
25 changes: 20 additions & 5 deletions xbrl/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from xbrl import XbrlParseException, TaxonomyNotFound
from xbrl.cache import HttpCache
from xbrl.helper.uri_resolver import resolve_uri
from xbrl.linkbase import Linkbase, ExtendedLink, LinkbaseType, parse_linkbase, parse_linkbase_url
from xbrl.linkbase import Linkbase, ExtendedLink, LinkbaseType, parse_linkbase, parse_linkbase_url, Label

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -90,6 +90,7 @@ def __init__(self, xml_id: str, schema_url: str, name: str) -> None:
self.nillable: bool or None = None
self.period_type: str or None = None
self.balance: str or None = None
self.labels: [Label] = []

def __str__(self) -> str:
return self.name
Expand Down Expand Up @@ -161,19 +162,19 @@ def __init__(self, schema_url: str, namespace: str):
def __str__(self) -> str:
return self.namespace

def get_taxonomy(self, namespace: str):
def get_taxonomy(self, url: str):
"""
Returns the taxonomy with the given namespace (if it is the current taxonomy, or if it is imported)
If the taxonomy cannot be found, the function will return None
:param namespace:
:param url: can either be the namespace or the schema url
:return either a TaxonomySchema obj or None
:return:
"""
if self.namespace == namespace:
if self.namespace == url or self.schema_url == url:
return self

for imported_tax in self.imports:
result = imported_tax.get_taxonomy(namespace)
result = imported_tax.get_taxonomy(url)
if result is not None:
return result
return None
Expand Down Expand Up @@ -327,4 +328,18 @@ def parse_taxonomy(schema_path: str, cache: HttpCache, schema_url: str or None =
elr.calculation_link = extended_cal_link
break

for label_linkbase in taxonomy.lab_linkbases:
for extended_link in label_linkbase.extended_links:
for root_locator in extended_link.root_locators:
# find the taxonomy the locator is referring to
schema_url, concept_id = root_locator.href.split('#')
c_taxonomy: TaxonomySchema = taxonomy.get_taxonomy(schema_url)
if c_taxonomy is None:
continue
concept: Concept = c_taxonomy.concepts[concept_id]

for children in root_locator.children:
concept.labels = children.labels


return taxonomy

0 comments on commit 605ed2c

Please sign in to comment.