Commit d5ec22cc authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] add some minor changes

- set minOccurs "0" if item_optional is True

- prepare table tag before going through list-type item

- use item_title instead of item_name if item_title is set
parent 2024a155
......@@ -500,16 +500,24 @@ class StatsHttpd:
complextype = xml.etree.ElementTree.Element("complexType")
complextype.append(alltag)
elem = xml.etree.ElementTree.Element(
"element", { "name" : stats_spec["item_name"] })
"element", attrib={ "name" : stats_spec["item_name"],
"minOccurs": "0" \
if stats_spec["item_optional"] \
else "1",
"maxOccurs": "unbounded" })
elem.append(complextype)
xsd_elem.append(elem)
elif stats_spec['item_type'] == 'list':
alltag = xml.etree.ElementTree.Element("all")
alltag = xml.etree.ElementTree.Element("sequence")
stats_spec2xsd(stats_spec['list_item_spec'], alltag)
complextype = xml.etree.ElementTree.Element("complexType")
complextype.append(alltag)
elem = xml.etree.ElementTree.Element(
"element", { "name" : stats_spec["item_name"] })
"element", attrib={ "name" : stats_spec["item_name"],
"minOccurs": "0" \
if stats_spec["item_optional"] \
else "1",
"maxOccurs": "1" })
elem.append(complextype)
xsd_elem.append(elem)
else:
......@@ -520,7 +528,9 @@ class StatsHttpd:
'type' : stats_spec["item_type"] \
if stats_spec["item_type"].lower() != 'real' \
else 'float',
'minOccurs' : "1",
'minOccurs' : "0" \
if stats_spec["item_optional"] \
else "1",
'maxOccurs' : "1"
}
)
......@@ -621,7 +631,6 @@ class StatsHttpd:
xsl_elem.append(table)
# assumed stats_spec
else:
tr = xml.etree.ElementTree.Element("tr")
td = xml.etree.ElementTree.Element(
"td",
attrib={ "class" : "title",
......@@ -630,23 +639,34 @@ class StatsHttpd:
else "" })
a = xml.etree.ElementTree.Element(
"a", attrib={ "href": urllib.parse.quote(path + "/" + stats_spec["item_name"]) })
a.text = stats_spec["item_name"]
a.text = stats_spec[ "item_title" if "item_title" in stats_spec else "item_name" ]
td.append(a)
tr.append(td)
xsl_elem.append(td)
td = xml.etree.ElementTree.Element("td")
if stats_spec['item_type'] == 'map':
stats_spec2xsl(stats_spec['map_item_spec'], tr,
stats_spec2xsl(stats_spec['map_item_spec'], td,
path + "/" + stats_spec["item_name"])
elif stats_spec['item_type'] == 'list':
table = xml.etree.ElementTree.Element("table")
tr = xml.etree.ElementTree.Element("tr")
th = xml.etree.ElementTree.Element("th")
th.text = "Item Names"
tr.append(th)
th = xml.etree.ElementTree.Element("th")
th.text = "Item Values"
tr.append(th)
table.append(tr)
tr = xml.etree.ElementTree.Element("tr")
stats_spec2xsl(stats_spec['list_item_spec'], tr,
path + "/" + stats_spec["item_name"])
table.append(tr)
td.append(table)
else:
td = xml.etree.ElementTree.Element("td")
xsl_valueof = xml.etree.ElementTree.Element(
"xsl:value-of",
attrib={'select': stats_spec["item_name"]})
td.append(xsl_valueof)
tr.append(td)
xsl_elem.append(tr)
xsl_elem.append(td)
# multiple stats_specs
elif type(stats_spec) is list:
table = xml.etree.ElementTree.Element("table")
......@@ -659,7 +679,9 @@ class StatsHttpd:
tr.append(th)
table.append(tr)
for item_spec in stats_spec:
stats_spec2xsl(item_spec, table, path)
tr = xml.etree.ElementTree.Element("tr")
stats_spec2xsl(item_spec, tr, path)
table.append(tr)
xsl_elem.append(table)
return None
......
......@@ -755,7 +755,7 @@ class TestStatsHttpd(unittest.TestCase):
}
xsl_body1 = self.stats_httpd.open_template(
stats_httpd.XSL_TEMPLATE_LOCATION).substitute(
xsl_string='<xsl:template match="bind10:statistics"><table><tr><th>Module Names</th><th>Module Items</th></tr><xsl:for-each select="Dummy"><tr><td><a href="./Dummy">Dummy</a></td><td><table><tr><th>Item Names</th><th>Item Values</th></tr><tr><td class="title" title="foo is bar"><a href="./Dummy/foo">foo</a></td><td><xsl:value-of select="foo" /></td></tr></table></td></tr></xsl:for-each></table></xsl:template>',
xsl_string='<xsl:template match="bind10:statistics"><table><tr><th>Module Names</th><th>Module Items</th></tr><xsl:for-each select="Dummy"><tr><td><a href="./Dummy">Dummy</a></td><td><table><tr><th>Item Names</th><th>Item Values</th></tr><tr><td class="title" title="foo is bar"><a href="./Dummy/foo">Foo</a></td><td><xsl:value-of select="foo" /></td></tr></table></td></tr></xsl:for-each></table></xsl:template>',
xsd_namespace=stats_httpd.XSD_NAMESPACE)
xsl_body2 = self.stats_httpd.xsl_handler()
self.assertEqual(type(xsl_body1), str)
......
......@@ -556,7 +556,9 @@ class TestStats(unittest.TestCase):
"item_name": "zonename",
"item_type": "string",
"item_optional": False,
"item_default": ""
"item_default": "",
"item_title": "Zonename",
"item_description": "Zonename"
},
{
"item_name": "queries.udp",
......@@ -617,7 +619,9 @@ class TestStats(unittest.TestCase):
"item_name": "zonename",
"item_type": "string",
"item_optional": False,
"item_default": ""
"item_default": "",
"item_title": "Zonename",
"item_description": "Zonename"
},
{
"item_name": "queries.udp",
......
......@@ -261,7 +261,9 @@ class MockAuth:
"item_name": "zonename",
"item_type": "string",
"item_optional": false,
"item_default": ""
"item_default": "",
"item_title": "Zonename",
"item_description": "Zonename"
},
{
"item_name": "queries.udp",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment