"Michele Cella" <[EMAIL PROTECTED]> writes:

> The TextField already applies a "requiredfield" class to itself if is
> required by the validator and personally I wouldn't trust anything
> other than that for doing this thing since you can define a validator
> in the schema that's required and at the same time having
> is_required=False on your field, that's another point why I think this
> is the wrong solution.

You mean something like:

class my_fields(widgets.WidgetsList):
      field1 = widgets.TextField(
           label = _(u'some label'),
           is_required = False,
      )

class my_validators(validators.Schema):
      field1 = validators.UnicodeString(not_empty = True)

?

> IMHO it's pretty safe to check for is_required by validating with an
> empty string because that's the only empty "signal" you can get from
> the web where everything is just a string.
>
> Your example:
>
>>>> test = validators.String(not_empty=True, if_invalid="abc")
>>>> test.to_python('')
> 'abc'
>>>>
>
> No exception raised, this is a FE problem, but personally I can't see
> the usefulness of if_invalid since you're saying "validate this, if
> invalid the value is this", then why validating at all?

Because you're not attributing a default value everywhere the widget is used.
If you use it in 5 different places, then there will be the same default in
all of those.  I also don't like it and haven't used it, but I believe there
might be some utility in that.

It's the same thing that setting getters and setters within the model: why not
do it all in the controller?  Because it is cleaner, it is more consistent and
it is nearer the "affected" part of your system.

Also, if_invalid can be used to do some kind of redirection, post-processing
or even changing something within the program flow (is this good?  I
dunno...). 

> So what is the obvious way?
> - using the validator parameter and not_empty

+1

> - using is_required

I don't see this as a solution since there are already many idioms within FE
(and our widgets) for that: not_empty, allow_empty and validators.NotEmpty().
Besides that, we already have if_empty to deal with empty values (that might
need being combined with some of the validators to achieve what one desires). 

Adding another alternative would just make things worse...

> With the last solution you have only this way:
>
> 1) a new validator
> TextField(validator=Int(not_empty=True))
>
> 2) tweak the default validator
> TextField(validator_args=dict(not_empty=True))

Hmmm...  I don't like the idea of a "default validator" that's not exactly the
same that is specified in FE's docs.  And I still prefer explicitly stating
what I want -- not_empty = False, if_empty = 'abc' -- than having to guess
what the default is and then combine the results.  Besides, just "adding to
the default" might cause surprises if the default changes.

> no conflicts, at init if validator is not None validators_args is not
> considered, anyway no one will use validator and validator_args (better
> name please) at the same time since it's obvious the use case they
> cover, "obvious way to do it".

Why having both? :-)

> validator -> brand new FE validador
> validator_args -> arguments for the default *FE* validator provided by
> the widget

I don't like validator_args... 

> Anyway isn't this the whole source of our discussion? providing a
> default validator for the FileField and having (as requested by Kevin)
> an easy way of marking it as required without redefining the whole
> validator?

What is the problem of saying:

field = widgets.FileField(validator=UnicodeString(not_empty=True),
      css_classes = ['required'],
      )

?  It is much clearer that this filefield widget will accept thos funky
Windows files named like "saúde.doc" (health.doc), that it can't be empty and
that it should have the CSS class 'required', for layouting purposes...

> The only point against the last solution I can see is that is more
> typing but I think is more pythonic, explicit and doesn't leave space
> for ambiguity since it's clear what the relationship between validator
> and validator_args is, and that you need to use FE to do these things.

;-)  I prefer no default validation.


-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to