def chart_serializer(chart, filing, maker): with xml_namespace(maker, None, auto_convert=True) as maker: role = convert_role_url(chart.role, filing) link = maker.presentationLink(**{ 'xlink:type': 'extended', 'xlink:role': role, }) link.append(make_loc(chart.loc_fact, maker)) for order, (n_parent, n_child) in enumerate(chart.walk_tree()): if n_parent is None: n_parent = (chart.loc_fact, None) n_child, n_parent = n_child[0], n_parent[0] link.append(make_loc(n_child, maker)) link.append(make_presentationArc(n_child, n_parent, order, maker)) return link # Facts should be able to create their own locs # presentationArcs are derived from data in the chart #<loc # xlink:type="locator" # xlink:href="http://taxonomies.xbrl.us/us-gaap/2009/non-gaap/dei-2009-01-31.xsd#dei_DocumentPeriodEndDate" # xlink:label="DocumentPeriodEndDate" # xlink:title="DocumentPeriodEndDate" #/> # Presentationarcs go from label to label
def chart_serializer(chart, filing, maker): with xml_namespace(maker, None, auto_convert=True) as maker: role = convert_role_url(chart.role, filing) link = maker.calculationLink(**{ 'xlink:type': 'extended', 'xlink:role': role, }) for calc_fact in chart.calculation_facts: link.append(make_loc(calc_fact, maker)) for order, (fact, weight) in enumerate(calc_fact.calc_items): link.append(make_loc(fact, maker)) link.append(make_calculationArc(fact, calc_fact, order+1, weight, maker)) return link
def label_serializer(serializer): filing = serializer.filing date = filing.date company = filing.company nsmap = gen_nsmap(filing, 'Label') maker = ElementMaker(nsmap=nsmap) with xml_namespace(maker, 'link', auto_convert=True) as maker: linkbase = maker.linkbase( **{ #find out about this 'xsi:schemaLocation': 'http://www.xbrl.org/2003/linkbase http://www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd' }) labellink = maker.labelLink( **{ 'xlink:type': 'extended', 'xlink:role': 'http://www.xbrl.org/2003/role/link', }) locs = set([]) for (fact, unit), context, data in filing.data_stream: if fact.href not in locs: labellink.append(make_loc(fact, maker, namespace='link')) locs.add(fact.href) facts = set([]) for (fact, unit), context, data in filing.data_stream: if (fact, unit) in facts: continue facts.add((fact, unit)) utitle = 'label_{0}_{1}'.format(fact.title, uid()) labellink.append(make_label(fact, maker, utitle, namespace='link')) labellink.append( make_labelArc(fact, maker, utitle, namespace='link')) linkbase.append(labellink) return linkbase
def label_serializer(serializer): filing = serializer.filing date = filing.date company = filing.company nsmap = gen_nsmap(filing, 'Label') maker = ElementMaker(nsmap=nsmap) with xml_namespace(maker, 'link', auto_convert=True) as maker: linkbase = maker.linkbase(**{ #find out about this 'xsi:schemaLocation': 'http://www.xbrl.org/2003/linkbase http://www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd' }) labellink = maker.labelLink(**{ 'xlink:type': 'extended', 'xlink:role': 'http://www.xbrl.org/2003/role/link', }) locs = set([]) for (fact, unit), context, data in filing.data_stream: if fact.href not in locs: labellink.append(make_loc(fact, maker, namespace='link')) locs.add(fact.href) facts = set([]) for (fact, unit), context, data in filing.data_stream: if (fact, unit) in facts: continue facts.add((fact, unit)) utitle = 'label_{0}_{1}'.format(fact.title, uid()) labellink.append(make_label(fact, maker, utitle, namespace='link')) labellink.append(make_labelArc(fact, maker, utitle, namespace='link')) linkbase.append(labellink) return linkbase