Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
On Wednesday 06 June 2007 11:11, Hermann Himmelbauer wrote: > I'm currently studying your doctests in z3c.form and I have to say, they > are really nice to read and understandable! Thanks! Great! I am glad you like it. > I'm through with forms.txt and found some minor issues, so I attached a > modified version, moreover I outlined codelines which I did not understand, > so maybe these could be more verbose. I have applied the changes and added an explanatory note at one of your question places, since they basically both were the same. > Moreover I wanted to know if you had a look at my ORM-problem I sent you > some days ago - probably you did not find time to write a demo for it, > however, I would be glad to know if you think that my case can be handled > via z3c.form. The problem you sent has really very little to do with ORM, but a complex object setup. I attempted to address all your needs in the new "Address Book" demo. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
Hi Stephan. First of all, thank you for the change to the wizard. On the points below, despite the code structure, the resulting groups are good for making logical separations. It provides another alternative for making these. It also provides a simple means to tuck some fields away as well. Zope code is certainly easier on the eyes :-) and to also to read doc tests. This makes it much more easily understood. Demos simply make design patterns clear for folks. This is where I feel that this can make the difference between recognizing package functionality and actually deploying the package in the way it was designed. Looks like I missed the other buttons so I am happy they are there. Many thanks for your effort on this excellent package. Regards, David Stephan Richter wrote: On Wednesday 30 May 2007 15:07, David Pratt wrote: class Admin: fields = ( (None, {'fields': ('question',)}), ('Date information', {'fields': ('pub_date',)}), ) This is s lame! We have this great OO language and they do such simple C-like structures. I also disagree with their motivations for totally auto-generated forms. They say that admin interfaces are usually just simple forms. In my opinion this is bad UI design. In fact, I found admin interfaces often the biggest challenge, because people do not think them through, but users then complain if the admin UI is not efficient. class Admin: fields = ( (None, {'fields': ('question',)}), ('Date information', {'fields': ('pub_date',), 'classes': 'collapse'}), ) This is just flat-out lame. I could never use django and be happy. I very much like the suggestion of defining groups on the field manager. What you are suggesting is intuitive. In the django code, the group can be named, which provides an optional title for the field set for the form. Additionally, a class is passed in so you can use it for with some js to be initially collapsed when rendered. Similarly, these optional parameters would be useful to pass on. Yeah, except that we will do that sensibly using a class. Then we can do as much as we want to with a group. values() seems logical for iterating over groups for the widget manager. I guess some thought on how the group (field set) itself may be integrated into a widget so a bit of js can be used to collapse and expand it would be the otherpart. I am not willing to change the widget manager API. This is silly, since very few use cases require groups. I think an extension to the widget manager API would be appropriate. So, I would create this iface: class IGroupsWidgetManager(IWidgetManager): groups = zope.interface.Attribute('Group Mapping') Then groups is an ordered mapping from name to group. A group in return is just an extended widget manager: class IGroupWidgetManager(IWidgetManager): title = zope.schema.TextLine(u'Ttile of the group used for the legend.') css = zope.schema.TextLine(u'CSS class set of the fieldset.') ... Now I am just thinking about the best way to define the groups in the fields manager. Specifically, whether I am going to extend the existing implementations or write new ones. Probably write new ones, since I am pretty happy with the current API. Unrelated to this is another small addition for the demo. This is to show a form with a couple of additional useful form buttons (another nice feature integrated in django forms) Save and add another Save and continue editing I did that already. The message demo shows "Apply" and "Apply and View", the former is the same as "Save and continue editing". The "Save and add another" case I demonstrate in the spreadsheet/table demo. I also have a comment in the code what to do different, when wanting to add just one entry. Regards, Stephan ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
Am Donnerstag, 31. Mai 2007 13:10 schrieb Maciej Wisniowski: > > I also still struggle with this issue. In my case, I have the following > > scenarios: > > > > I currently try to solve these issues with a self-made Form class, which > > descends from form.Form. In case you are interested, here is my docstring > > which somehow explains the basic idea: > > Thanks for the code. I'm using old (?) way with SQLScripts not > with ORM's so may case is a bit different. I've also created my > own library that extends formlib: 'dbformlib' (available at google code) > for such things. > > I'm not sure why do you have to clone fields, possibly because of > ORM specifics? The thing is that I add/change various attributes of the schema fields. If I reference them directly, then I change the interfaces themselves, which I don't want to, therefore I clone them first. In case you are interested, I can send you my code, too. > Idea of widget_template_files is very interesting. Well, that was a suggestion from someone else on this list, so it's not my invention... Best Regards, Hermann -- [EMAIL PROTECTED] 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
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
> I also still struggle with this issue. In my case, I have the following > scenarios: > > I currently try to solve these issues with a self-made Form class, which > descends from form.Form. In case you are interested, here is my docstring > which somehow explains the basic idea: > Thanks for the code. I'm using old (?) way with SQLScripts not with ORM's so may case is a bit different. I've also created my own library that extends formlib: 'dbformlib' (available at google code) for such things. I'm not sure why do you have to clone fields, possibly because of ORM specifics? Idea of widget_template_files is very interesting. I need to see docs and code for z3c.form now :) -- Maciej Wisniowski ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
Am Donnerstag, 31. Mai 2007 10:16 schrieb Stephan Richter: > On Thursday 31 May 2007 03:48, Hermann Himmelbauer wrote: > > Anyway, in my case a decent ORM-integration with Zope3 forms is still a > > key issue to me. > > If you provide me with a simple "hello world"-like example of the ORM stuff > you are using, then I will give it a try to write a demo for z3c.form. Thanks a lot, I attached a simple data structure to this mail and a description how the form should look like. This example covers all aspects I am currently struggling with and which I somehow solved with my class (however, I could still not solve the multi-widget/list issue with the phone numbers in the example). Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 orm_example.py Description: application/python ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
On Thursday 31 May 2007 03:48, Hermann Himmelbauer wrote: > Anyway, in my case a decent ORM-integration with Zope3 forms is still a key > issue to me. If you provide me with a simple "hello world"-like example of the ORM stuff you are using, then I will give it a try to write a demo for z3c.form. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
Am Donnerstag, 31. Mai 2007 08:09 schrieb Maciej Wisniowski: > >> It would be very interesting to see RDBMS interaction. Formlib for > >> example is not trivial to use with RDBMS especially because of a lack > >> of documentation and because everything seems to be written with ZODB > >> objects in mind. > > > > It works together with a mapper like SQLAlchemy (and z3c.zalchemy). > > > > IMHO, it is not formlib's task to do mappings like that. > > Not sure what mappings you're talking about. I just want to > know how can I get some data from somewhere (it may be a > file, RDBMS or other external source) and display it in a form, > then edit this data etc. Formlib default forms (EditForm, AddForm) > assume that it works with content objects and I just want to call > SQLScript to get data for my form and to commit it back to RDBMS. > Not so difficult but there are no docs and no demos for this with > formlib. Thats why I'd like to know how to do such things > with z3c.form. I also still struggle with this issue. In my case, I have the following scenarios: - Some ORM-object attributes directly map to fields, but these attributes may be in referenced ORM-objects - Sometimes I want to map the first referenced ORM-object (which is represented as the first list entry) to a field. However, any field which is displayed is somewhere already described as an interface schema field for an ORM object, which I of course want to reuse. Moreover I want to write minimal HTML-code as possible, but auto-generating fields does not work for me. I currently try to solve these issues with a self-made Form class, which descends from form.Form. In case you are interested, here is my docstring which somehow explains the basic idea: snip - """ A generic form class for rendering forms based on object data The class has the following key attributes: - widget_template_files: A sequence of widget template files that can be used in widgets to display a form field in a specific way - schema_fields: - template: Same as the template attribute in form.Form, this specifies the template that should be used for rendering the page - schema_fields: a sequence of schema fields that can be copied from interfaces via the function "cloneField", e.g. cloneField(IFoo['bar']). When schema fields are created via the cloneField function, additional attributes can be set on the fields. The programmer has to make sure, that the names of the schema fields are distinct, hence in case schema fields have the same name, the __name__ attribute has to be set to a distinct name. Default values for fields can be automatically fetched and updated. How the mapping between the form fields and the data object is implemented, can either implicitly or explicitly defined. 1) Explicit declaration: - If the schema field has the attribute "obj_attr", the specified attribute is used for reading/updating data. If the attribute does not exist, an error is raised - If the schema field has the attribute "obj_getter" or/and "obj_setter", the data object is queried for a matching method, which are used for getting/setting values. 2) Implicit declaration: - If data object has methods beginning with "set_" and/or "get_" and match the "__name__" attribute of the schema field, these methods are automatically used for getting/setting values. The precedence is as follows: 1) explicit getter/setter 2) implicit getter/setter 3) obj_attr """ -- snip --- An example would look like this (cloneField does basically only a copy.deepcopy of the interface): --- snip --- schema_fields = ( cloneField(IFp['name1'], obj_attr = 'fp.name1'), cloneField(IFp['name2'], obj_attr = 'fp.name2'), cloneField(IFp['titel'], obj_attr = 'fp.titel')) template = ViewPageTemplateFile('fpform.pt') widget_template_files = ('widget_div.pt', 'widget_span.pt') - snip - "widget_div.pt" has the common Zope3-HTML form code like this: - snip - Label Error - snip - And "fpform.pt" is then very tidy: snip snip - My class has still various limitations, however, maybe Stephan Richters new form class offers some solutions but I until now I could not find time to have a look at it. Anyway, in my case a decent ORM-integration with Zope3 forms is still a key issue to me. Best Regards, Hermann -- [EMAIL PROTECTED] 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://ma
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
On Thursday 31 May 2007 02:25, Nikolay Kim wrote: > > Not sure what mappings you're talking about. I just want to > > know how can I get some data from somewhere (it may be a > > file, RDBMS or other external source) and display it in a form, > > then edit this data etc. Formlib default forms (EditForm, AddForm) > > assume that it works with content objects and I just want to call > > SQLScript to get data for my form and to commit it back to RDBMS. > > Not so difficult but there are no docs and no demos for this with > > formlib. Thats why I'd like to know how to do such things > > with z3c.form. > > you should redefine getContent method on your form, inside getContent > you can get data from anywhere and return it in dict. Yes, this is correct. You can also have other data structures. All you have to do is to develop and register a new data manager. By default there are two data managers registered: one for instances and one for dicts. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
> > It works together with a mapper like SQLAlchemy (and z3c.zalchemy). > > > > IMHO, it is not formlib's task to do mappings like that. > > > Not sure what mappings you're talking about. I just want to > know how can I get some data from somewhere (it may be a > file, RDBMS or other external source) and display it in a form, > then edit this data etc. Formlib default forms (EditForm, AddForm) > assume that it works with content objects and I just want to call > SQLScript to get data for my form and to commit it back to RDBMS. > Not so difficult but there are no docs and no demos for this with > formlib. Thats why I'd like to know how to do such things > with z3c.form. you should redefine getContent method on your form, inside getContent you can get data from anywhere and return it in dict. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
>> It would be very interesting to see RDBMS interaction. Formlib for >> example is not trivial to use with RDBMS especially because of a lack >> of documentation and because everything seems to be written with ZODB >> objects in mind. >> > > It works together with a mapper like SQLAlchemy (and z3c.zalchemy). > > IMHO, it is not formlib's task to do mappings like that. > Not sure what mappings you're talking about. I just want to know how can I get some data from somewhere (it may be a file, RDBMS or other external source) and display it in a form, then edit this data etc. Formlib default forms (EditForm, AddForm) assume that it works with content objects and I just want to call SQLScript to get data for my form and to commit it back to RDBMS. Not so difficult but there are no docs and no demos for this with formlib. Thats why I'd like to know how to do such things with z3c.form. -- Maciej Wisniowski ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
On Wednesday 30 May 2007 15:07, David Pratt wrote: > class Admin: > fields = ( > (None, {'fields': ('question',)}), > ('Date information', {'fields': ('pub_date',)}), > ) This is s lame! We have this great OO language and they do such simple C-like structures. I also disagree with their motivations for totally auto-generated forms. They say that admin interfaces are usually just simple forms. In my opinion this is bad UI design. In fact, I found admin interfaces often the biggest challenge, because people do not think them through, but users then complain if the admin UI is not efficient. > class Admin: > fields = ( > (None, {'fields': ('question',)}), > ('Date information', {'fields': ('pub_date',), 'classes': > 'collapse'}), > ) This is just flat-out lame. I could never use django and be happy. > I very much like the suggestion of defining groups on the field manager. > What you are suggesting is intuitive. In the django code, the group can > be named, which provides an optional title for the field set for the > form. Additionally, a class is passed in so you can use it for with some > js to be initially collapsed when rendered. Similarly, these optional > parameters would be useful to pass on. Yeah, except that we will do that sensibly using a class. Then we can do as much as we want to with a group. > values() seems logical for iterating over groups for the widget manager. > I guess some thought on how the group (field set) itself may be > integrated into a widget so a bit of js can be used to collapse and > expand it would be the otherpart. I am not willing to change the widget manager API. This is silly, since very few use cases require groups. I think an extension to the widget manager API would be appropriate. So, I would create this iface: class IGroupsWidgetManager(IWidgetManager): groups = zope.interface.Attribute('Group Mapping') Then groups is an ordered mapping from name to group. A group in return is just an extended widget manager: class IGroupWidgetManager(IWidgetManager): title = zope.schema.TextLine(u'Ttile of the group used for the legend.') css = zope.schema.TextLine(u'CSS class set of the fieldset.') ... Now I am just thinking about the best way to define the groups in the fields manager. Specifically, whether I am going to extend the existing implementations or write new ones. Probably write new ones, since I am pretty happy with the current API. > Unrelated to this is another small addition for the demo. This is to > show a form with a couple of additional useful form buttons (another > nice feature integrated in django forms) > > Save and add another > Save and continue editing I did that already. The message demo shows "Apply" and "Apply and View", the former is the same as "Save and continue editing". The "Save and add another" case I demonstrate in the spreadsheet/table demo. I also have a comment in the code what to do different, when wanting to add just one entry. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
Am Mittwoch, den 30.05.2007, 18:12 +0200 schrieb Maciej Wisniowski: > > Thanks. BTW, I am still looking for 1-2 demos to write but I am out of > > ideas. > > Do have anything related to forms that you would like to see demoed? > It would be very interesting to see RDBMS interaction. Formlib for > example is not trivial to use with RDBMS especially because of a lack > of documentation and because everything seems to be written with ZODB > objects in mind. It works together with a mapper like SQLAlchemy (and z3c.zalchemy). IMHO, it is not formlib's task to do mappings like that. Christian -- gocept gmbh & co. kg - forsterstraße 29 - 06112 halle/saale - germany www.gocept.com - [EMAIL PROTECTED] - phone +49 345 122 9889 7 - fax +49 345 122 9889 1 - zope and plone consulting and development signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
Hi Stephan. Thanks for your reply. For #2, the following excerpt from django's documentation located here: http://www.djangoproject.com/documentation/tutorial02/ And speaking of forms with dozens of fields, you might want to split the form up into fieldsets: class Admin: fields = ( (None, {'fields': ('question',)}), ('Date information', {'fields': ('pub_date',)}), ) The first element of each tuple in fields is the title of the fieldset. Here’s what our form looks like now: ... image You can assign arbitrary HTML classes to each fieldset. Django provides a "collapse" class that displays a particular fieldset initially collapsed. This is useful when you have a long form that contains a number of fields that aren’t commonly used: class Admin: fields = ( (None, {'fields': ('question',)}), ('Date information', {'fields': ('pub_date',), 'classes': 'collapse'}), ) ... image I haven't thought of the best way of implementing this at this point since I am just coming up to speed with your package. I very much like the suggestion of defining groups on the field manager. What you are suggesting is intuitive. In the django code, the group can be named, which provides an optional title for the field set for the form. Additionally, a class is passed in so you can use it for with some js to be initially collapsed when rendered. Similarly, these optional parameters would be useful to pass on. values() seems logical for iterating over groups for the widget manager. I guess some thought on how the group (field set) itself may be integrated into a widget so a bit of js can be used to collapse and expand it would be the otherpart. Unrelated to this is another small addition for the demo. This is to show a form with a couple of additional useful form buttons (another nice feature integrated in django forms) Save and add another Save and continue editing Regards, David Stephan Richter wrote: On Wednesday 30 May 2007 11:06, David Pratt wrote: 1) An iteration of the wizard that will not allow show submit button or allow submit until the end of all steps. I have implemented this feature. The "Finish" button will now only show up when all required fields are filled out. You can update your z3c.formdemo checkout or download version 1.1.0. 2) A demo to show how fields can be grouped. Something like Django forms with grouping would be really nice. My two standard answers for this are usually: 1. Use sub-forms. That's what they are for. 2. Grouping fields does not make much sense, since in projects you want to lay out widgets/fields manually anyways. However, the first answer does not seem to fit your use case well and the second is a bummer for beginners. So, how would *you* like to see grouping of fields working? There are several options here. For one, one could claim that interfaces already group fields, so I could use them to define groups: >>> fields = field.Fields(interfaces.IPerson) >>> fields.groups[IPerson].title = u'Person' Another option would be to define groups on the fields manager: >>> fields = field.Fields(interfaces.IPerson, group='person') >>> fields.groups['person'].title = u'Person' We could also reuse the prefex: >>> fields = field.Fields(interfaces.IPerson, prefix='person') >>> fields.groups['person'].title = u'Person' Some other approaches could include making multiple "field.Fields" instances or have different "field.Field" implementations, similar to buttons. The next question would then be how to iterate through the groups in the widget manager. Would this be okay? >>> widgets.groups['person'].values() [...] Anyways, let me know hoe it could be done and I think about it some more. A django example would be nice too. Regards, Stephan ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-dev] Re: [Zope3-Users] z3c.form 1.0.0 released!
On Wednesday 30 May 2007 11:06, David Pratt wrote: > 1) An iteration of the wizard that will not allow show submit button or > allow submit until the end of all steps. I have implemented this feature. The "Finish" button will now only show up when all required fields are filled out. You can update your z3c.formdemo checkout or download version 1.1.0. > 2) A demo to show how fields can be grouped. Something like Django forms > with grouping would be really nice. My two standard answers for this are usually: 1. Use sub-forms. That's what they are for. 2. Grouping fields does not make much sense, since in projects you want to lay out widgets/fields manually anyways. However, the first answer does not seem to fit your use case well and the second is a bummer for beginners. So, how would *you* like to see grouping of fields working? There are several options here. For one, one could claim that interfaces already group fields, so I could use them to define groups: >>> fields = field.Fields(interfaces.IPerson) >>> fields.groups[IPerson].title = u'Person' Another option would be to define groups on the fields manager: >>> fields = field.Fields(interfaces.IPerson, group='person') >>> fields.groups['person'].title = u'Person' We could also reuse the prefex: >>> fields = field.Fields(interfaces.IPerson, prefix='person') >>> fields.groups['person'].title = u'Person' Some other approaches could include making multiple "field.Fields" instances or have different "field.Field" implementations, similar to buttons. The next question would then be how to iterate through the groups in the widget manager. Would this be okay? >>> widgets.groups['person'].values() [...] Anyways, let me know hoe it could be done and I think about it some more. A django example would be nice too. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users