Implement WO_ACCEPTS

master
Harald Wolff 2018-03-09 16:09:10 +01:00
parent b32507cf63
commit 75bd56749e
4 changed files with 74 additions and 4 deletions

View File

@ -14,11 +14,16 @@ class TreeBrowser(WebObject,NoPersistence):
def __call__(self,request,o=None):
return self._browse(request,o)
def findClass(self,classpath):
return hserver.api.findClass(classpath)
def _addObject(self, request, o):
f = request.getForm()
if ("oname" in f) and ("oclass" in f):
oclass = getattr( hserver.api , f["oclass"].value() )
oclass = self.findClass(f["oclass"].value().split("."))
#getattr( hserver.api , f["oclass"].value() )
i = oclass()
print(">>>%s" % (o._aq_parent._aq_name,))

View File

@ -14,7 +14,7 @@
<div class="treenode">
<input type="text" name="oname"/><br/>
<select size="1" name="oclass">
<%iterate wo_cls getattr(self,"_browse").wo_types()%><option value="<%=wo_cls%>"><%=wo_cls%></option><%end%>
<%iterate wo_cls self.wo_accepts()%><option value="<%='{0}.{1}'.format(wo_cls.__module__,wo_cls.__name__)%>"><%=wo_cls.__name__%></option><%end%>
</select><br/>
<input type="submit" value="erstellen"/>
</div>

View File

@ -1,4 +1,28 @@
from hserver.api.webobject import WebObject,WebFolder,WebCallable
from hserver.api.webobject import WebObject,WebFolder,WebCallable,NavWebObject
from hserver.api.fileobject import FileObject
from hserver.api.simpleobject import SimpleObject
from objectbroker import Persistence,NoPersistence
import hserver.api
import sys
def ListKnownWebObjects():
r = []
exp = hserver.api.__dict__
for t in exp.values():
try:
if (issubclass(t,WebObject)):
r.append(t)
except:
pass
return r
def findClass(classpath):
modname = ".".join(classpath[:-1])
classname = classpath[-1]
mod = sys.modules[modname]
return getattr(mod,classname)

View File

@ -16,10 +16,20 @@ class WebCallable:
m(i,request, o=o)
else:
request.getContentFile().write("<html><head><title>No Content</title></head><body>Sorry, no content here!</body></html>")
class WebObject(WebCallable,Aquisition):
WO_Accepts = None
def wo_accepts(self):
woa = getattr(self,"WO_Accepts",None)
if woa is None:
if (self.__class__ == WebObject) or (self._aq_parent is None):
return hserver.api.ListKnownWebObjects()
else:
return self._aq_parent.wo_accepts()
return woa
def __init__(self):
self.__default = None
@ -106,3 +116,34 @@ class WebObject(WebCallable,Aquisition):
class WebFolder(WebObject, Persistence):
pass
class NavWebObject(WebObject):
def __init__(self,title = None):
WebObject.__init__(self)
self.title = title
def title(self):
t = getattr(self,"title",None)
if t is None:
return self.__aq_name
return t
def navigation(self,levels = 1):
nav = {}
nav["title"] = self.title
nav["children"] = {}
if (levels > 0):
for child in self.children():
if isinstance(self[child],NavWebObject):
nav["children"][child] = self[child].navigation(levels-1)
return nav