Michele Cella wrote:
> Can you explain yourself a little better? I'm really trying to
> understand what you're saying but it seems you're too vague and a
> victim of some preconceptions on this subject, sorry but if I sound
> emotional but I've spent (along with Alberto and others) a lot of my
> time (not spare) on TG widgets and hearing these things is quite
> disappointing for me.
> 
> Ciao
> Michele

I think the main problem with widgets is that no-one knows how to use them. But 
for me, a big 
problem is that I don't actually want to use a Pythonic interface to make a 
form, because after 2 
years of working as a web developer I've written too many forms to know that 
widgets just isn't 
going to work. It's fine for maybe 20% of cases where the forms are pretty bog 
standard, but when I 
want to do something a bit different suddenly I have to write my own template 
AND some pythonic 
cruft using a specific API (which isn't available) and that just makes me sad.

I think you should concentrate on what people actually don't like:

Writing forms with HTML is nearly always necessary. And I actually feel good 
after making a good UI 
out of forms. So writing HTML forms is not really something to be avoided. Sure 
if you have a 100% 
standard form, widgets is quite good, but that happens so rarely that it just 
ends up working 
against you.

For me, the perfect solution would be something like this. Feel free to ask me 
for any 
clarifications. And this is all from memory (guess why) so some names might be 
a little off:

#
# schemas.py
#
# I have to write a schema for every form. That's okay.
#

from validators import *

class ProductSchema(Schema):
        title = NotEmpty()
        description = NotEmpty()
        price = Float() # guess

#
# mywidgets.py:
#
# This is some templates for how I like my widgets. I write this when I think 
I'll have
# more than one of a certain form firld
#

from widgets import *

class StandardTextField(Textfield):
        template = """
<p>
        <label for="${field_id}">${field_label}</label>
        <input type="text" name="${field_nane}" id="${field_id}" 
value="${field_value}"/>
        <strong py:if="field_error">${field_error}</strong>
</p>"""

#
# Okay leg work done, now let's do something
#
# templates/myform.kid
#

<?python from mywidgets import * ?>

<form action="saveproduct" method="post">
<fieldset>
<legend>New Product</legend>
<div py:content="StandardTextField(name='title', label='Product title')"/>
<div py:content="StandardTextField(name='description', label='Short 
description')"/>
<!-- oh noes! A non-standard field! -->
<p>
        <label for="price">Price</label>
        &pound; <input type="text" name="price" id="price" 
value="value_for('price')"/>
        <strong py:if="error_for('price')" 
py:content="error_for('price')"></strong>
        <input type="checkbox" name="incvat" checked="value_for('incvat')"/> 
This price includes VAT
</p>
</fieldset>
<div py:content="StandardButtonRow(hiddenid='product.id')"/> <!-- I should have 
defined this in 
schemas.py. It's a <p> with class submit, a hidden field named "id" and two 
submits - Save and 
Cancel -->
</form>

#
# controllers.py
#

import schemas

class Root(controllers.Root):
        @expose(html=".templates.myform)
        def newproduct(self):
                return {"id":0}
        @expose(html=".templates.myform)
        def editproduct(self, id):
                return {"id":id}

        @expose(html=".templates.thanks")
        @validate(form=schemas.ProductSchema)
        @error_handler(editproduct)
        def saveproduct:
                # whatever
                return {"message":"Thanks"}


#### done

The point is, it would be much much better if we could define our custom stuff 
inline within Kid, 
and not in some collection of widgets. Overriding some template of the closest 
matching template and 
then calling it *only once* just doesn't make my life better. I do appreciate 
the Pythonic interface 
as widgets are at the moment - it does speed up development, but when you want 
to do something a 
little different it's a bit of a trainwreck.

Sorry :-/ You've done very well to get this far, to be honest.

-Rob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to