Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 7 and Version 8 of WidgetsBrainStorming


Ignore:
Timestamp:
02/10/06 08:44:56 (9 years ago)
Author:
michele
Comment:

remove the crap

Legend:

Unmodified
Added
Removed
Modified
  • WidgetsBrainStorming

    v7 v8  
    1 = WidgetsBrainStorming = 
    2  
    3 This page aims to collect opinions regarding TurboGears Widgets. 
    4  
    5 If you don't know TG widgets take a look at [http://tinyurl.com/aspfn this] message from Kevin. 
    6  
    7 Feel free to add your own opinions and comments to this page. 
    8  
    9 == Using Widgets == 
    10  
    11 Actually to use a widget you need to do something like this: 
    12  
    13  1. Create an instance of the widget from your controller 
    14 {{{ 
    15 #!python 
    16 ... 
    17 age_field = widgets.TextField("age", default=0, validator=validators.Int()) 
    18 ... 
    19 }}} 
    20  1. Insert your widget instance inside your template 
    21 {{{ 
    22 #!text/html 
    23 ... 
    24 <div py:replace="age_field.insert(age)"/>  
    25 ... 
    26 }}} 
    27  
    28 IMHO for the second point we can use Kid py:match attribute to do something like this: 
    29 {{{ 
    30 #!text/html 
    31 ... 
    32 <widget name="age_field" value="age" /> 
    33 ... 
    34 }}} 
    35 it shouldn't be to hard if we add to the sitetemplate a definition like this (I have not tested it): 
    36 {{{ 
    37 #!text/html 
    38 ... 
    39 <span py:match="item.tag == 'widget'" 
    40   py:replace="getattribute(self, item.get('name'), None).insert(item.get('value'))"> 
    41 </span> 
    42 ... 
    43 }}} 
    44  
    45 == Customizing Widgets Look&Feel == 
    46  
    47 Look&Feel customization is a quite important aspect for widgets. Actually you have two options: 
    48  
    49  1. Providing a custom CSS stylesheet 
    50  1. Providing a custom Kid template 
    51  
    52 Customization should be an easy task and should happen inside our templates (not the controller). 
    53  
    54 Widgets should use CSS class and selector to make it straigthforward. 
    55  
    56 === Default attributes === 
    57  
    58 During the 0.9 IRC Chat all have agreed that widgets should use namespaced class names. 
    59  
    60 For example: 
    61  
    62 {{{ 
    63 #!text/html 
    64 <div class="tg_text_field">...</div> 
    65 }}} 
    66  
    67 === Ability to set common attributes used for widgets === 
    68  
    69 There is a ticket (#106) regarding this. 
    70 This is an import requirement that will make customization even more easy. 
    71 Using the syntax I proposed above customization shouldn't be that hard and inside your template you should be able to do the following: 
    72  
    73 {{{ 
    74 #!text/html 
    75 ... 
    76 <widget name="age_field" value="age" size="30" id="id_age_field"/> 
    77 ... 
    78 }}} 
    79  
    80 But, how can we make customization as easy also for complex widgets that embeds others widgets? For example the Form widget? Any opinion? 
    81  
    82 Regarding this, I've added another idea as a comment to ticket #106. 
    83  
    84 == Smart Forms Widgets == 
    85  
    86 In my own visions a Form widget should let me do something along these lines (only a pseudo code to show the concept): 
    87  
    88 {{{ 
    89 #!python 
    90 @turbogears.expose(template="...") 
    91 def edit_contact(self): 
    92     myform = TableForm(widgets=[ 
    93                 widgets.TextField("name"), 
    94                 widgets.TextField("address"), 
    95                 widgets.TextField("age", default=0, 
    96                                 validator=validators.Int())])  
    97     return dict(form=myform) 
    98  
    99 @turbogears.expose(template="...") 
    100 def save(self, myform): 
    101     if not input_form.valid: 
    102         raise cherrypy.HTTPRedirect(...) 
    103     else: 
    104         contact = Contact.byContactId(...) 
    105         contact.name = myform.name 
    106         contact.address = myform.address 
    107         contact.age = myform.age 
    108         turbogears.flash("Changes saved!") 
    109         raise cherrypy.HTTPRedirect(...) 
    110 }}} 
    111  
    112 This way you shouldn't need a special has_error variable, or the need to check against cherrypy.request.form_errors and to take values from  cherrypy.request.input_values. 
    113  
    114 We should be able to access values from the form as normal class attributes, python properties should use to_python and from_python FormEncode methods to ensure attributes values are valid and accessible in a transparent way. 
    115  
    116 == See also == 
    117  * [http://groups.google.com/group/turbogears/browse_frm/thread/e964d2a05feda72c/103105fae5f9c5ba Forms declarative style]  
    118  * [http://groups.google.com/group/turbogears/browse_frm/thread/196550bee072ed8d/222c138bf33ba726 formencode.sqlschema] 
    119  * [http://www.djangoproject.com/documentation/forms/ Django Forms] 
    120  * [http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html RoR FormHelper] 
    121  * [http://www.thelinuxconsultancy.co.uk/quickform.php PHP PEAR QuickForm] 
    122  * [http://help.sap.com/saphelp_webas630/helpdata/en/5c/1b76bc3da0504e8b535cf3e154eaa7/content.htm SAP NetWeaver UI Element Libraries] 
     1Nothing to see, move along. :P