[Zope3-Users] Problem viewing an object in the browser.
Jeffrey D Peterson
bgpete at gmail.com
Fri Jun 5 13:38:22 EDT 2009
I have an object:
#!/usr/bin/env python
from simplejson import dumps
from interfaces import ISerialNumberLog
from xmlrpc.spread.client import SpreadClient
from zope.publisher.browser import BrowserPage
from zope.interface import implements
class SerialNumberLog(SpreadClient):
implements(ISerialNumberLog)
@classmethod
def get(cls, serno, xml=False):
return cls().send(u'logEntryByVINMatchRight', serno=serno, xml=xml)
class SernoLogJSONView(BrowserPage):
def __call__(self, serno):
response = self.request.response
response.setHeader('Content-Type', 'application/json;
charset=UTF-8')
return dumps(self.context.get(serno, False))
class SernoLogXMLView(BrowserPage):
def __call__(self, serno):
response = self.request.response
response.setHeader('Content-Type', 'text/xml; charset=UTF-8')
return self.context.get(serno, True)
The object queries a DB and returns either a list of dictionaries
representing the records or a string of XML representing the same.
In the debug shell it works as I expect:
Welcome to the interactive debug prompt.
The 'root' variable contains the ZODB root folder.
The 'app' variable contains the Debugger, 'app.publish(path)' simulates a
request.
>>> from xmlrpc.API.sernolog.methods import SerialNumberLog as SNL
>>> sernolog = SNL()
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> from zope.component import getMultiAdapter
>>> view = getMultiAdapter((sernolog, request), name='sernolog.json')
>>> view('X00507')
'[{"builddate": "1999-09-28 00:00:00.00", "void": "0", "engineserno": null,
"sernolog_id": "88834", "model": "70080", "serno": "X00507"}]'
>>> view2 = getMultiAdapter((sernolog, request), name='sernolog.xml')
>>> view2('X00507')
u'<?xml version="1.0"
encoding="utf-8"?>\n<response><row><builddate>1999-09-28
00:00:00.00</builddate><void>0</void><engineserno></engineserno><sernolog_id
>88834</sernolog_id><model>70080</model><serno>X00507</serno></row></respons
e>'
>>>
But when I add a SerialNumberLog object to the ZMI, I can't see how to make
requests to it.
>>> root[u'serialnumberlog'] = sernolog
>>> root[u'sernolog.json'] = sernolog
>>> root[u'sernolog.xml'] = sernolog
>>> import transaction
>>> transaction.commit()
>>>
I click on those in the ZMI or if I browse to them at:
http://zopevm.crary.com:15080/serialnumberlog
http://zopevm.crary.com:15080/sernolog.json
http://zopevm.crary.com:15080/sernolog.xml
I get "The page that you are trying to access is not available"
What am I not doing?
Here is the configure.zcml from the package:
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="xmlrpc">
<interface
interface=".interfaces.ISerialNumberLog"
type="zope.app.content.interfaces.IContentType"
/>
<class class=".methods.SerialNumberLog">
<require
permission="zope.View"
interface=".interfaces.ISerialNumberLog"
/>
<require
permission="zope.ManageContent"
set_schema=".interfaces.ISerialNumberLog"
/>
</class>
<browser:page
for=".interfaces.ISerialNumberLog"
name="sernolog.json"
class=".methods.SernoLogJSONView"
permission="zope.View"
/>
<browser:page
for=".interfaces.ISerialNumberLog"
name="sernolog.xml"
class=".methods.SernoLogXMLView"
permission="zope.View"
/>
</configure>
And the main configure.zcml:
...
<!-- Add your own component registrations here -->
<include package=".spread" />
<include package=".API.sernolog" />
</configure>
Any help would be great, thanks!
Jeff Peterson
More information about the Zope3-users
mailing list