Skip to content

Commit 605ed2c

Browse files
committed
Added label to Concept class #10
This change has not yet been sufficiently tested!
1 parent bdc0abd commit 605ed2c

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

xbrl/linkbase.py

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def parse_linkbase(linkbase_path: str, linkbase_type: LinkbaseType) -> Linkbase:
487487
locator_href = loc.attrib[XLINK_NS + 'href']
488488
if not locator_href.startswith('http'):
489489
# resolve the path
490+
# todo, try to get the URL here, instead of the path!!!
490491
locator_href = resolve_uri(linkbase_path, locator_href)
491492
locator_map[loc_label] = Locator(locator_href, loc_label)
492493

xbrl/taxonomy.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from xbrl import XbrlParseException, TaxonomyNotFound
1616
from xbrl.cache import HttpCache
1717
from xbrl.helper.uri_resolver import resolve_uri
18-
from xbrl.linkbase import Linkbase, ExtendedLink, LinkbaseType, parse_linkbase, parse_linkbase_url
18+
from xbrl.linkbase import Linkbase, ExtendedLink, LinkbaseType, parse_linkbase, parse_linkbase_url, Label
1919

2020
logger = logging.getLogger(__name__)
2121

@@ -90,6 +90,7 @@ def __init__(self, xml_id: str, schema_url: str, name: str) -> None:
9090
self.nillable: bool or None = None
9191
self.period_type: str or None = None
9292
self.balance: str or None = None
93+
self.labels: [Label] = []
9394

9495
def __str__(self) -> str:
9596
return self.name
@@ -161,19 +162,19 @@ def __init__(self, schema_url: str, namespace: str):
161162
def __str__(self) -> str:
162163
return self.namespace
163164

164-
def get_taxonomy(self, namespace: str):
165+
def get_taxonomy(self, url: str):
165166
"""
166167
Returns the taxonomy with the given namespace (if it is the current taxonomy, or if it is imported)
167168
If the taxonomy cannot be found, the function will return None
168-
:param namespace:
169+
:param url: can either be the namespace or the schema url
169170
:return either a TaxonomySchema obj or None
170171
:return:
171172
"""
172-
if self.namespace == namespace:
173+
if self.namespace == url or self.schema_url == url:
173174
return self
174175

175176
for imported_tax in self.imports:
176-
result = imported_tax.get_taxonomy(namespace)
177+
result = imported_tax.get_taxonomy(url)
177178
if result is not None:
178179
return result
179180
return None
@@ -327,4 +328,18 @@ def parse_taxonomy(schema_path: str, cache: HttpCache, schema_url: str or None =
327328
elr.calculation_link = extended_cal_link
328329
break
329330

331+
for label_linkbase in taxonomy.lab_linkbases:
332+
for extended_link in label_linkbase.extended_links:
333+
for root_locator in extended_link.root_locators:
334+
# find the taxonomy the locator is referring to
335+
schema_url, concept_id = root_locator.href.split('#')
336+
c_taxonomy: TaxonomySchema = taxonomy.get_taxonomy(schema_url)
337+
if c_taxonomy is None:
338+
continue
339+
concept: Concept = c_taxonomy.concepts[concept_id]
340+
341+
for children in root_locator.children:
342+
concept.labels = children.labels
343+
344+
330345
return taxonomy

0 commit comments

Comments
 (0)