On 14 Jun 2005, at 20:24, CP Hennessy wrote:
Anahide Tchertchian wrote:
CP Hennessy wrote:
 I've a class which has several fields, some of these
fields are filled from a database and some are filled
in by the user. I'm trying to figure out what is the
correct way in CPS to do this.

My user enters a clientId and "Add" which causes data
to be retrieved from a database for a few fields. The
user should be presented with a form where the relevant
fields are populated from the database info and where
several other fields should be entered by the user
before the new object is created.

I'm currently basing my new class on CPSDocument and
I'd really like to know what I need to change to get
the behaviour mentioned above. If anyone can point me
at a simple example, then it would be even better.

It looks like you could achieve the same behaviour by defining default
expressions on the fields that are supposed to be populated from your
database. Maybe you just have to define a way to access this database in
your application, but it does not have to be on your document class.

Thanks for the hint Anahide.
I've tried to use it but have one problem. Using the following :
  'default_expr': 'python:portal.REQUEST.widget__name',

in the schema works to initialize the data in the form. This expression is
used when populating the creation form AND when the object is actually
being created.

However the problem with this approach is that if this data is for a field that should be readonly (i.e. the data coming from the database should not
be changed), then there is no field widget__name :(

What is the correct approach for this ?
To create a new "create_form" for my class ?

Another way would be to
- have a schema+layout asking the initial information, and render it and parse it without underlying object using the renderLayout method of the layouts tool. It uses a MappingStorageAdapter to fill a mapping (dict) instead of an object. - then with this info get what you need from the database, and start the creation of a normal object using renderCreateObjectDetatailed with a pre-filled request but validate=0.

Florent

--
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]


_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel

Reply via email to