diff --git a/sdoapp.py b/sdoapp.py
index 36736bd63f..f7d332b518 100755
--- a/sdoapp.py
+++ b/sdoapp.py
@@ -58,6 +58,8 @@
ENABLE_CORS = True
ENABLE_HOSTED_EXTENSIONS = True
+EXTENSION_SUFFIX = "*"
+
ENABLED_EXTENSIONS = [ 'admin', 'auto', 'bib' ]
ALL_LAYERS = [ 'core', 'admin', 'auto', 'bib' ]
@@ -92,15 +94,16 @@ def __str__(self):
class TypeHierarchyTree:
- def __init__(self):
+ def __init__(self, prefix=""):
self.txt = ""
self.visited = {}
+ self.prefix = prefix
def emit(self, s):
self.txt += s + "\n"
def toHTML(self):
- return '
' % self.txt
+ return '%s' % (self.prefix, self.txt)
def toJSON(self):
return self.txt
@@ -110,14 +113,28 @@ def traverseForHTML(self, node, depth = 1, hashorslash="/", layers='core'):
"""Generate a hierarchical tree view of the types. hashorslash is used for relative link prefixing."""
# log.debug("traverseForHTML: node=%s hashorslash=%s" % ( node.id, hashorslash ))
+ log.info("DEPTH %s" % depth)
+
+
+ urlprefix = ""
+ home = node.getHomeLayer()
+
+ if home in ENABLED_EXTENSIONS and home != getHostExt():
+ urlprefix = makeUrl(home)
+
+ extclass = ""
+ extflag = ""
+ if home != "core" and home != "":
+ extclass = "class=\"ext-%s\"" % home
+ extflag = EXTENSION_SUFFIX
# we are a supertype of some kind
- if len(node.GetImmediateSubtypes(layers=layers)) > 0:
+ if len(node.GetImmediateSubtypes(layers=layers)) > 0:
# and we haven't been here before
if node.id not in self.visited:
self.visited[node.id] = True # remember our visit
- self.emit( ' %s%s' % (" " * 4 * depth, node.id, hashorslash, node.id, node.id) )
+ self.emit( ' %s%s%s' % (" " * 4 * depth, node.id, extclass, urlprefix, hashorslash, node.id, node.id, extflag) )
self.emit(' %s' % (" " * 4 * depth))
# handle our subtypes
@@ -126,13 +143,13 @@ def traverseForHTML(self, node, depth = 1, hashorslash="/", layers='core'):
self.emit( ' %s
' % (" " * 4 * depth))
else:
# we are a supertype but we visited this type before, e.g. saw Restaurant via Place then via Organization
- seen = ' * ' % node.id
- self.emit( ' %s%s%s' % (" " * 4 * depth, node.id, hashorslash, node.id, node.id, seen) )
+ seen = ' + ' % node.id
+ self.emit( ' %s%s%s%s' % (" " * 4 * depth, node.id, extclass, urlprefix, hashorslash, node.id, node.id, extflag, seen) )
# leaf nodes
if len(node.GetImmediateSubtypes(layers=layers)) == 0:
if node.id not in self.visited:
- self.emit( '%s%s%s' % (" " * depth, node.id, hashorslash, node.id, node.id, "" ))
+ self.emit( '%s%s%s%s' % (" " * depth, node.id, extclass, urlprefix, hashorslash, node.id, node.id, extflag, "" ))
#else:
#self.visited[node.id] = True # never...
# we tolerate "VideoGame" appearing under both Game and SoftwareApplication
@@ -389,19 +406,19 @@ def ml(self, node, label='', title='', prop='', hashorslash='/'):
urlprefix = ""
home = node.getHomeLayer()
- if home in ENABLED_EXTENSIONS and home != host_ext:
+ if home in ENABLED_EXTENSIONS and home != getHostExt():
port = ""
if myport != "80":
port = ":%s" % myport
- urlprefix = self.makeUrl(home)
+ urlprefix = makeUrl(home)
extclass = ""
extflag = ""
if home != "core" and home != "":
extclass = "class=\"ext-%s\" " % home
- extflag = "*"
+ extflag = EXTENSION_SUFFIX
- return "%s%s" % (extclass, urlprefix, hashorslash, node.id, prop, title, label, extflag)
+ return "%s%s" % (extclass, urlprefix, hashorslash, node.id, prop, title, label, extflag)
def makeLinksFromArray(self, nodearray, tooltip=''):
"""Make a comma separate list of links via ml() function.
@@ -859,7 +876,7 @@ def handleHomepage(self, node):
'myhost': myhost,
'myport': myport,
'mybasehost': mybasehost,
- 'host_ext': host_ext,
+ 'host_ext': getHostExt(),
'debugging': debugging
}
page = template.render(template_values)
@@ -935,7 +952,7 @@ def emitExactTermPage(self, node, layers="core"):
target = node.id
- s = "extension shown: %s [x]
\n" % (ll, ll, self.makeUrl("",target))
+ s = "extension shown: %s [x]
\n" % (ll, ll, makeUrl("",target))
self.write(s)
cached = self.GetCachedText(node, layers)
@@ -1096,10 +1113,10 @@ def setupExtensionLayerlist(self, node):
layerlist = [ "core"]
# 3. Use host_ext if set, e.g. 'bib' from bib.schema.org
- if host_ext != None:
- log.debug("Host: %s host_ext: %s" % ( self.request.host , host_ext ) )
- log.info("Host: %s host_ext: %s" % ( self.request.host , host_ext ) )
- extlist.append(host_ext)
+ if getHostExt() != None:
+ log.debug("Host: %s host_ext: %s" % ( self.request.host , getHostExt() ) )
+ log.info("Host: %s host_ext: %s" % ( self.request.host , getHostExt() ) )
+ extlist.append(getHostExt())
# Report domain-requested extensions
for x in extlist:
@@ -1143,17 +1160,50 @@ def handleFullHierarchyPage(self, node, layerlist='core'):
return True
else:
template = JINJA_ENVIRONMENT.get_template('full.tpl')
+
+ extlist=""
+ count=0
+ for i in layerlist:
+ if i != "core":
+ sep = ""
+ if count > 0:
+ sep = ", "
+ extlist += "plus '%s'%s" % (i, sep)
+
+ count += 1
+ local_button = ""
+ local_label = "Core %s extension vocabularies
" % extlist
+ if count == 0:
+ local_button = "Core vocabulary"
+ elif count == 1:
+ local_button = "Core %s extension" % extlist
+ else:
+ local_button = "Core %s extensions" % extlist
+
uThing = Unit.GetUnit("Thing")
uDataType = Unit.GetUnit("DataType")
- mainroot = TypeHierarchyTree()
+ mainroot = TypeHierarchyTree(local_label)
mainroot.traverseForHTML(uThing, layers=layerlist)
thing_tree = mainroot.toHTML()
+ fullmainroot = TypeHierarchyTree("Core plus all extension vocabularies
")
+ fullmainroot.traverseForHTML(uThing, layers=ALL_LAYERS)
+ full_thing_tree = fullmainroot.toHTML()
+
dtroot = TypeHierarchyTree()
dtroot.traverseForHTML(uDataType, layers=layerlist)
datatype_tree = dtroot.toHTML()
- page = template.render({ 'thing_tree': thing_tree, 'datatype_tree': datatype_tree })
+
+
+
+ full_button = "Core plus all extensions"
+
+ page = template.render({ 'thing_tree': thing_tree,
+ 'full_thing_tree': full_thing_tree,
+ 'datatype_tree': datatype_tree,
+ 'local_button': local_button,
+ 'full_button': full_button})
self.response.out.write( page )
log.debug("Serving fresh FullTreePage.")
@@ -1205,7 +1255,7 @@ def handleExactTermPage(self, node, layers='core'):
self.response.out.write("Schema.org Extensions
\nThe term '%s' is not in the schema.org core, but is described by the following extension(s):
\n\n" % schema_node.id)
for x in all_terms[schema_node.id]:
x = x.replace("#","")
- self.response.out.write("- %s
" % (self.makeUrl(x,schema_node.id), x) )
+ self.response.out.write("- %s
" % (makeUrl(x,schema_node.id), x) )
return True
return False
@@ -1427,33 +1477,7 @@ def setupHostinfo(self, node, test=""):
debugging = False
if "localhost" in hostString or "sdo-ganymede.appspot.com" in hostString:
debugging = True
-
- def getHostExt(self):
- return host_ext
-
- def getBaseHost(self):
- return mybasehost
-
- def getHostPort(self):
- return myport
-
- def makeUrl(self,ext="",path=""):
- port = ""
- sub = ""
- p = ""
- if(self.getHostPort() != "80"):
- port = ":%s" % self.getHostPort()
- if ext != "core" and ext != "":
- sub = "%s." % ext
- if path != "":
- if path.startswith("/"):
- p = path
- else:
- p = "/%s" % path
-
- url = "http://%s%s%s%s" % (sub,self.getBaseHost(),port,p)
- return url
-
+
def get(self, node):
@@ -1549,6 +1573,31 @@ def get(self, node):
log.info("Error handling 404.")
return
+def getHostExt():
+ return host_ext
+
+def getBaseHost():
+ return mybasehost
+
+def getHostPort():
+ return myport
+
+def makeUrl(ext="",path=""):
+ port = ""
+ sub = ""
+ p = ""
+ if(getHostPort() != "80"):
+ port = ":%s" % getHostPort()
+ if ext != "core" and ext != "":
+ sub = "%s." % ext
+ if path != "":
+ if path.startswith("/"):
+ p = path
+ else:
+ p = "/%s" % path
+
+ url = "http://%s%s%s%s" % (sub,getBaseHost(),port,p)
+ return url
#log.info("STARTING UP... reading schemas.")
read_schemas(loadExtensions=ENABLE_HOSTED_EXTENSIONS)