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.

The interface.NOVALUE is a marker for *value not set yet*.
This means that the value wasn't setup if you have NOVALUE.
It has nothing to do with default value, None or missing value
form a field. It's just a internal marker for *no value setup till now*.
This NOVLAUE marker is responsible that a value get converted
or not.
The data converter is responsible to return a default value.

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.

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

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.

Any hints about that?

> Best Regards,
> Hermann
> --
> GPG key ID: 299893C7 (on keyservers)
> FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
> _______________________________________________
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users

Zope3-users mailing list

Reply via email to