> Hi Herman, Stephan
>> Betreff: [Zope3-Users] z3c.form: Data Manager - getting value
>> via dm.query() instead of dm.get()
>> Hi,
>> I'm developing a z3c.form based form, which should store it's
>> form values in the session. To accomplish that, the form
>> needs to retrieve it's values from the session.
>> My idea was to simply store the form data in the button
>> handler method into the session as a dictionary. z3c.form
>> then offers the "getContent()"
>> method, which would simply retrieve the dictionary from the session.
>> The problem is, that if the dictionary does not contain all
>> fields, an error is raised. The reason for this error lies in
>> line 97 in
>> z3c.form.widget: The value is retrieved via the get()
>> function (which does a dict.get()) and thus fails.
>> The solution for this problem would be to replace the
>> datamanager.get() by datamanager.query(), as this would
>> return the default field value.
> No the datamanager doesn't know the default value. Or at least
> the data manger is not responsible for that part.

Hmmm, that makes sense, but in my use case I need a datamanger that
returns "None / NOVALUE / whatever_that_indicates_that_there_is_no_value".

> The data converter is responsible to return a default value.

I see, so there would a possibility to let the datamanager return NOVALUE
and let the data converter return None, I assume?

> This means the data converter convert values from the form
> and the (applyChanges) within the data manager stores them if
> different. And only if they are different.

In my case, I have a dictionary that may - not yet - provide the value.

>> However, this may break other projects, therefore I would suggest to:
>> - Introduce some form option such as "ContextQuery=True/False"
>> - Either use dm.get() or .query() regarding to this option
>> What's your opinion on this? Would this be a decent solution?
> This means it's important to setup any field in the data manager
> and the values for them. There is no support for widget which
> didn't get setup it's value correct.
> But,
> as far as I can see there is a problem with the interface.
> the *query* method isn't declared in the IDataManager interface
> at all and the *get* method provides a default value like:
> The ``get`` method is defined as:
> def get(default=NOVALUE):
>     """Get the value.
>     If no value can be found, return the default value.
>     """

Ah, I see - so that would denote, that the get() method would return
NOVALUE as default? This would also solve my problem.

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.

Many thanks for help!

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