Beispiel #1
0
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
Beispiel #2
0
def presentation_serializer(serializer):
	filing = serializer.filing
	date = filing.date
	company = filing.company
	nsmap = gen_nsmap(filing, 'Presentation')
	maker = ElementMaker(nsmap=nsmap)

	with xml_namespace(maker, None, 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',
			'xmlns': 'http://www.xbrl.org/2003/linkbase',
		})
		for chart in filing.charts:
			roleRef = maker.roleRef(**{
				'roleURI': convert_role_url(chart.role, filing),
				'xlink:type': 'simple',
				'xlink:href': '{0}#{1}'.format(
						serializer.document_name('Schema'),
						chart.role
					)
			})

			linkbase.append(roleRef)
			chart.bind(serializer)
			linkbase.append(chart_serializer(chart, filing, maker))
	
	return linkbase
Beispiel #3
0
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
Beispiel #4
0
def presentation_serializer(serializer):
    filing = serializer.filing
    date = filing.date
    company = filing.company
    nsmap = gen_nsmap(filing, 'Presentation')
    maker = ElementMaker(nsmap=nsmap)

    with xml_namespace(maker, None, 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',
                'xmlns': 'http://www.xbrl.org/2003/linkbase',
            })
        for chart in filing.charts:
            roleRef = maker.roleRef(
                **{
                    'roleURI':
                    convert_role_url(chart.role, filing),
                    'xlink:type':
                    'simple',
                    'xlink:href':
                    '{0}#{1}'.format(serializer.document_name('Schema'),
                                     chart.role)
                })

            linkbase.append(roleRef)
            chart.bind(serializer)
            linkbase.append(chart_serializer(chart, filing, maker))

    return linkbase
Beispiel #5
0
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
Beispiel #6
0
def schema_serializer(serializer):
	filing = serializer.filing
	date = filing.date
	company = filing.company
	nsmap = gen_nsmap(filing, 'Schema')
	maker = ElementMaker(namespace=nsmap['xsd'], nsmap=nsmap)
	targetNamespace = '{0}{1}'.format(filing.company.url, filing.date)
	schema = maker.schema({
		'targetNamespace': targetNamespace,
		'elementFormDefault': 'qualified',
	})

	#link bases
	annotation = maker.annotation()
	appinfo = maker.appinfo()
	bases = serializer.determine_files()
	bases.remove('Instance')
	bases.remove('Schema')
	roles = {
		'Presentation': "http://www.xbrl.org/2003/role/presentationLinkbaseRef",
		'Calculation': "http://www.xbrl.org/2003/role/calculationLinkbaseRef",
		'Label': "http://www.xbrl.org/2003/role/labelLinkbaseRef",
	}
	with xml_namespace(maker, 'link', auto_convert=True) as maker:
		for base in bases:
			appinfo.append(maker.linkbaseRef(**{
				'xlink:type': 'simple',
				'xlink:href': serializer.document_name(base),
				'xlink:role': roles[base],
				'xlink:arcrole': "http://www.w3.org/1999/xlink/properties/linkbase",
			}))

		for i, chart in enumerate(filing.charts):
			roleType = maker.roleType(**{
				'roleURI': convert_role_url(chart.role, filing),
				'id': chart.role
			})

			roleType.append(maker.definition('%04d - %s' % (10*(i+1), chart.role) ))
			roleType.append(maker.usedOn('link:presentationLink'))

			appinfo.append(roleType)
	
	annotation.append(appinfo)
	schema.append(annotation)

	#imports for the facts (probably have to derive this from facts)
	imports = {
		"http://www.xbrl.org/2003/instance": "http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd",
		"http://xbrl.us/us-types/2009-01-31": "http://taxonomies.xbrl.us/us-gaap/2009/elts/us-types-2009-01-31.xsd",
	}
	for namespace, schemaLocation in imports.items():
		#Terrible hack to get around import being a keyword
		schema.append(maker.__getattr__('import')({
			'namespace': namespace,
			'schemaLocation': schemaLocation,
		}))
	
	#Create a custom element for everything
	fact_table = {}
	for (fact, _), _, _ in filing.data_stream:
		fact_table[fact.label] = fact
	
	facts = fact_table.values()


	with xml_namespace(maker, 'xsd', auto_convert=True) as maker:
		#append facts for the chart abstract facts
		for chart in filing.charts:
			fact = chart.loc_fact
			schema.append(maker.element(**{
				'id': fact.label,
				'name': fact.label,
				'type': 'xbrli:stringItemType',
				'substitutionGroup': 'xbrli:item',
				'nillable': 'true',
				'abstract': 'true',
				'xbrli:periodType': 'duration',
			}))
		
		#append the rest of the facts we need to define
		for fact in facts:
			schema.append(maker.element(**{
				'id': fact.label,
				'name': fact.label,
				'nillable': 'true',
				'substitutionGroup': 'xbrli:item',
				'type': 'xbrli:monetaryItemType',
				'xbrli:periodType': fact.period,
			}))
	
	return schema