Re: [Zope3-Users] Generate edit form from user setting
On 8/22/06, Florian Lindner <[EMAIL PROTECTED]> wrote: I also thought about that. But if I write an adapter from PreferenceGroup to IUserSettings to all that the adapter would do is to assign values the values from the PreferenceGroup to IUserSettings. Ok it's more generic but at the end the same like assigned the values to the request itself. As long as the adapter is trivial, it can be handled with __getattr__ and __setattr__ instead of a bunch of individual properties. That also allows you to deal with evolution of the IUserSettings schema more conveniently. Another thing this buys you is that you're only dealing with application-level values; the widget implementations become completely irrelevant. Many widgets use more than one control these days; that's something you don't need to deal with this way. Is it okay to change self.context in the __init__ method of the view class with a PreferenceGroup object? (I just didn't know it it's not confusing the something in the ComponentArchitecture...) Sounds possible, but fragile. It should also be possible to pre-populate the form's adapters dictionary (self.adapters). -Fred -- Fred L. Drake, Jr. "Every sin is the result of a collaboration." --Lucius Annaeus Seneca ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Generate edit form from user setting
Am Donnerstag, 17. August 2006 23:04 schrieb Fred Drake: > On 8/17/06, Florian Lindner <[EMAIL PROTECTED]> wrote: > > I have a zope.app.preference.preference.PreferenceGroup based on an > > IUserSettings interface for which I want to generate an edit form. > > I've tried to do it with a class based on EditForm but that does not > > worked for me since the EditFrom changes the self.context object. If I > > simply replace self.context by the object I got from UserPreferences it > > complains about PreferenceGroup being not adaptable to IUserSettings (and > > it's right about that). > > Sounds like you want to create an adapter. The adapter is what's used > for getting/setting values. I also thought about that. But if I write an adapter from PreferenceGroup to IUserSettings to all that the adapter would do is to assign values the values from the PreferenceGroup to IUserSettings. Ok it's more generic but at the end the same like assigned the values to the request itself. Is it okay to change self.context in the __init__ method of the view class with a PreferenceGroup object? (I just didn't know it it's not confusing the something in the ComponentArchitecture...) > > > Of course I need to initialize the from with the values from the the > > PreferenceGroup object. Is there a better way than modifying the request > > like request.form['form.max_size'] for each field? I couldn't find one in > > the documentation but I'm almost sure there is a more elegant solution > > (since it's Zope!). > > Did you look at the get_rendered argument to > zope.formlib.form.FormField? Though I suspect the adapter I suggested > above would do the trick. Mmmhh, that's also one call for each field. I think I'll try it with the adapter. Regards, Florian ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Generate edit form from user setting
On 8/17/06, Florian Lindner <[EMAIL PROTECTED]> wrote: I have a zope.app.preference.preference.PreferenceGroup based on an IUserSettings interface for which I want to generate an edit form. I've tried to do it with a class based on EditForm but that does not worked for me since the EditFrom changes the self.context object. If I simply replace self.context by the object I got from UserPreferences it complains about PreferenceGroup being not adaptable to IUserSettings (and it's right about that). Sounds like you want to create an adapter. The adapter is what's used for getting/setting values. Of course I need to initialize the from with the values from the the PreferenceGroup object. Is there a better way than modifying the request like request.form['form.max_size'] for each field? I couldn't find one in the documentation but I'm almost sure there is a more elegant solution (since it's Zope!). Did you look at the get_rendered argument to zope.formlib.form.FormField? Though I suspect the adapter I suggested above would do the trick. -Fred -- Fred L. Drake, Jr. "Every sin is the result of a collaboration." --Lucius Annaeus Seneca ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Generate edit form from user setting
Hello, I have a zope.app.preference.preference.PreferenceGroup based on an IUserSettings interface for which I want to generate an edit form. I've tried to do it with a class based on EditForm but that does not worked for me since the EditFrom changes the self.context object. If I simply replace self.context by the object I got from UserPreferences it complains about PreferenceGroup being not adaptable to IUserSettings (and it's right about that). class UserSettings(form.Form): form_fields = form.Fields(IUserSettings, render_context = False) @form.action("Change") def handle_change_action(self, action, formData): pass Of course I need to initialize the from with the values from the the PreferenceGroup object. Is there a better way than modifying the request like request.form['form.max_size'] for each field? I couldn't find one in the documentation but I'm almost sure there is a more elegant solution (since it's Zope!). Thanks, Florian ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users