开发者

python: comparing attributes values in form before and after submit

I fill a form fields (in pygtk) from a class instance that contains its attributes with their values. Once the form is submitted, I get this instance updated with new values.

What is the best way to determine if the开发者_如何学Python form has returned different values (ie: been modified) ? Do I have to make a copy of the object instance before updating it, or return a copy at submit time - then compare each value afterward (seems heavy to me).

Thanks


You will need to have a copy of the data before and after the form has been submitted. The default __eq__ operator will compare all attributes on of class, so you can probably use before_form == after_form to see if anything has changed. If you need to know what has changed then you will have to iterate over each attribute.

An alternative is to hook into the onchange events of the fields in the form and set a dirty flag if any of them are triggered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜