:records and value assignment in Python Script
Struggling with the ":records" form construct... I have a "writers" object that contains fname and lname text fields. It looks like this: [fname: "Chris", lname: "McDonough", fname: "John", lname: "Malkovich"] I need to add a new text field, auth, and I need to compute and assign it's value during the form processing. Adding new field was not that difficult: I just changed the form and added <input type="hidden" name="auth" value="">. I don't know how I would add a new field using Python... but it is not important right now. But how can I change the value? I tried this inside Python Script: for w in writers: print w.auth # this is OK. w.auth="x" # this fails with "attribute-less object (assign or del)". -- Milos Prudek
Milos Prudek wrote:
Struggling with the ":records" form construct... [snip] But how can I change the value? I tried this inside Python Script:
You can enable writing of record attributes by adding this line to the "record" class in $ZOPE/lib/python/ZPublisher/HTTPRequest.py: _guarded_writes = 1 (make sure it's indented the same as the body of the class). Cheers, Evan @ 4-am & Zope
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Evan Simpson
Milos Prudek wrote:
But how can I change the value? I tried this inside Python Script:
You can enable writing of record attributes by adding this line to the "record" class in $ZOPE/lib/python/ZPublisher/HTTPRequest.py:
_guarded_writes = 1
(make sure it's indented the same as the body of the class).
Is there a reason this isn't the default? I ran into the same problem where I had a fairly large list of records. I ended up having to copy the whole thing just to change a few elements. _______________________ Ron Bickers Logic Etc, Inc.
Dne pondělí 06 srpen 2001 16:12 jste napsal(a):
Milos Prudek wrote:
Struggling with the ":records" form construct...
[snip]
But how can I change the value? I tried this inside Python Script:
You can enable writing of record attributes by adding this line to the "record" class in $ZOPE/lib/python/ZPublisher/HTTPRequest.py:
_guarded_writes = 1
(make sure it's indented the same as the body of the class).
An easy patch... but I rather do not patch at all... I may be forced to work with unpatched Zope release. I think I'll convert :records to a list of tuples... IMHO :records usefulness is quite limited because it is not mutable and because it hinders iteration over <dtml-in>dtml-call APythonScript></dtml-in> unless you pass it as a parameter. But I am very inexperienced Zoper. AFAIK :records are useful in the web form itself to gather data.. and you can feed :records into ZSQL directly for data rows insertion... and that's about it. If you need more, you should convert :records into some standard Python data structure that you can flexibly work with. Please correct me if I'm wrong. -- Milos Prudek
participants (3)
-
Evan Simpson -
Milos Prudek -
Ron Bickers