On Thu, Jan 25, 2007 at 08:44:43AM +0100, Maciej Wisniowski wrote: > > Yes. You're not supposed to do that. Views work with requests, not > > content objects. > > > > If you told us what you want to achieve, we could help you find a way to > > do it that works with Zope 3 rather than against it. > > > I'am creating form (CRUD) based on formlib, but this > is supposed to work with relational database. > Design is simple: > content_object -> view(based on formlib.form) ... > content_object is responsible for calling sql statements > so it needs data from the request. Possibly I have to pass > them (or the whole request) from the view?
Yes. Formlib conveniently gives you a dict of field names mapped to field values. You can pass that dict to your content object. Or you can use Python's ** syntaxt to convert that dict to keyword arguments, if your schema field names match argument names: @form.action("Save changes") def handle_save(self, action, data): self.context.update_row(**data) I would advise against passing the request to the content object. Formlib gives you validation and data type conversion; if you use the request directly, you'll lose that. On Thu, Jan 25, 2007 at 09:18:22AM +0100, Maciej Wisniowski wrote: > > > <InterfaceClass zope.traversing.interfaces.IPhysicallyLocatable>) > > > > Ehm...? Ideas? > OK, I forgot about: > setup.setUpTraversal() Yes. > Now it works with: > > >>> from zope.app.folder import rootFolder > >>> from zope.traversing.api import getPath > >>> root = rootFolder() > >>> root['test_content'] = DBCrudContent() > >>> test_content = root['test_content'] > >>> getPath(root['test_content']) > /test_content > > but unfortuantelly when my object is trying to get > path to itself like: > > class DBCrudContent(): ... > I get error: ... > TypeError: Not enough context to determine location root Your class does not implement IContained, and therefore when you add it to a folder, the folder does not set its __name__ and __parent__ attributes. At the very least you should say that it implements ILocation, if you want to call getPath on it. If you decide that IContained is not what you want, you'll have to set up the __name__ and __parent__ attributes by yourself > >>> context = DBCrudContent() > >>> context.__parent__ = rootFolder() > >>> context.__name__ = 'mycontent' > >>> context.my_location() > '/mycontent' HTH, Marius Gedminas -- We did it for smallpox, we'll also win over on ISO 8859-1 ... ;-) -- Markus Kuhn after eradicating one more ISO 8859-1 file from his disk
signature.asc
Description: Digital signature
_______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users