lazr-users team mailing list archive
-
lazr-users team
-
Mailing list archive
-
Message #00031
Re: Using lazr.restful with a zope3 app
On Jun 21, 2010, at 2:42 PM, Gustavo Rahal wrote:
> The problem was really the __repr__ of z3c.form. I fixed it and things worked fine. Will contact z3c.form owner for a permanent fix
Great.
> Now zope.app.publication and z3c.form need fixes...
>
> So, one step closer but still not there. At least now it seems i'm really on lazr.restful space. I'm having problems with the following:
>
> lazr/restful/_resource.py(1887)toDataForJSON()
> 1886 for link_name, publication in publications.items():
> -> 1887 data_for_json[link_name] = absoluteURL(publication,
> 1888 self.request)
>
> absoluteURL call fails with TypeError: There isn't enough context to get URL information
> Here is what the various objects look like:
>
> ipdb> publications
> Out[0]: {'systems_collection_link': <tp4.portal.restful.resources.SystemSet object at 0xaf14d6c>}
> ipdb> publication
> Out[0]: <tp4.portal.restful.resources.SystemSet object at 0xaf14d6c>
> ipdb> self.request
> Out[0]: <lazr.restful.simple.Request instance URL=http://localhost:8080/api/1.0>
>
> My RootResource is:
>
> class WebServiceRootResource(RootResource):
> """The root resource for a web service."""
>
> def _build_top_level_objects(self):
> systemset = SystemSet()
> systemset.systems = [
> System(systemset, "foo", "bar"),
> System(systemset, "1", "2")
> ]
> collections = dict(systems=(ISystem, systemset))
> return collections, {}
>
> Configuration:
>
> class WebServiceConfiguration(BaseWebServiceConfiguration):
> code_revision = '1'
> active_versions = ['1.0',]
> use_https = False
> last_version_with_mutator_named_operations = None
> view_permission = 'zope.Public'
> service_root_uri_prefix = "api/"
> hostname = "localhost"
> port = "8080"
>
>
> Thoughts?
It sounds like you need to define your own IAbsoluteURL implementation for the root object.
It might be sufficient to add this to your zcml:
<adapter factory="lazr.restful.simple.RootResourceAbsoluteURL" />
If you are curious what is going on here, see lazr/restful/docs/absoluteurl.txt
Gary
Follow ups
References