[Zope3-Users] Access to request in content object and object path in doctests

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Thu Jan 25 02:44:43 EST 2007


> 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)

My content_object gets data from RDBMS and stores
data into RDBMS. So I want to be able to call something like:
content_object/@@editview?row_id=1
to get and set data for row with row_id = 1 in RDBMS or
content_object/@@delview?row_id=2
to remove data from RDBMS etc.

Simply, I don't have x content objects that are
mappings of x rows in RDBMS, but I have one
object to do CRUD operations on every row in database.

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?

>>             >>> root = rootFolder()
>>             >>> root['my_object'] = my_object = MyObject()
>>             >>> getPath(my_object)
>>             '/my_object'
>>     
Hm... My doctest:

  >>> from zope.app.folder import rootFolder 
  >>> from zope.traversing.api import getPath
  >>> root = rootFolder()
  >>> root['test_content'] = test_content = DBCrudContent()
  >>> getPath(test_content)

and I get:

File "dbcrudbase.txt", line 83, in dbcrudbase.txt
Failed example:
    getPath(root['test_content'])
Exception raised:
    Traceback (most recent call last):
      File
"/home/downloads/Zope/Zope-3.3.0/build/lib.linux-i686-2.4/zope/testing/doctest.py",
line 1256, in __run
        compileflags, 1) in test.globs
      File "<doctest dbcrudbase.txt[16]>", line 1, in ?
        getPath(root['test_content'])
      File
"/home/downloads/Zope/Zope-3.3.0/build/lib.linux-i686-2.4/zope/traversing/api.py",
line 62, in getPath
        return IPhysicallyLocatable(obj).getPath()
    TypeError: ('Could not adapt',
<dbcrudbase.tests.dbcrudbasetest.DBCrudContent object at 0xb7442b6c>,
<InterfaceClass zope.traversing.interfaces.IPhysicallyLocatable>)

Ehm...? Ideas?

-- 
Maciej Wisniowski



More information about the Zope3-users mailing list