> Hi Herman
>> Betreff: Re: AW: [Zope3-Users] z3c.form: Data Manager -
>> getting value via dm.query() instead of dm.get()
> [...]
>> But I would nevertheless suggest to implement some kind of
>> "switch" that decides if an error is raised or NOVALUE is
>> returned in case a value is missing in the underlying object.
> I don't understand that.
> Why whould you like to store a default value if a value
> is missing. That's just a write access for storing
> what default returns anyway.

Hmmm, perhaps I have to explain my case better:

Normally, z3c.forms are used to edit/display content objects, which is
e.g. a "person object" with attributes such as "name, etc.", which are
then mapped to fields/widgets. In case the underlying data object is a
dictionary, this dictionary has to provide all key/value pairs as
specified in the field.fields().

In my case, I'm creating a search form. This search form does not store
any data into a content object, it just calls a specific search function.
However, the values in the search form should be remembered, so that if
the user comes back to the form, it is already prefilled. Therefore, I
simply store the "data" dictionary of the button handler into the session
and (mis)use this object as content object:

def getContent():
    return session.get('searchformkey', {})

def handle_search(self, action):
    data, errors = self.extractData()
    if errors:
        self.searched = None
        self.status = self.formErrorsMessage
    self.session['searchformkey'] = data

So, it may happen, that not all fields are filled out, therefore key/value
pairs may be missing. If that happens, the widget routine throws an error.
If I manage to overcome this error (e.g. by replacing the get() through
query() routine in z3c.form.widget), my form works.

Maybe, there's a better way to accomplish the above, but I could not think
of one...

Best Regards,

GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7

Zope3-users mailing list

Reply via email to