Re: newforms: common constraints

2007-07-29 Thread james_027

hi,

what will be the proper approach to do this? creating a custom fields
or custom field validation?

Thanks
james

On Jul 27, 10:53 pm, "Jacob Kaplan-Moss" <[EMAIL PROTECTED]>
wrote:
> On 7/27/07, james_027 <[EMAIL PROTECTED]> wrote:
>
> > but those min maxconstraintsare socommon? why not include it?
>
> Because "common" is different for any given user and/or site. I think
> *I've* only written a single form with min/max validation, FWIW.
> Designing a framework is hard; you've got to search for things that
> are as close to truly universal as possible. Otherwise you end up
> including every little pet feature that someone asks for, and that's
> known as "PHP".
>
> A good programmer will keep around his/her own library ofcommoncode
> and break it out whenever needed. If you need min/max validation
> often, you should make that the start of your own personal toolkit.
>
> Jacob


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: common constraints

2007-07-27 Thread Tim Chase

>> but those min max constraints are so common? why not include
>> it?
> 
> Because "common" is different for any given user and/or site.
> I think *I've* only written a single form with min/max
> validation, FWIW. Designing a framework is hard; you've got to
> search for things that are as close to truly universal as
> possible.

This is especially the case with Django...writing a simple
min/max validator is trivial to do and Django makes it easy to
use any set of validators you want on your fields.  That said, I
don't see a great reason not to include a min_length and
max_length validator in Django's standard toolkit of validators
as I've seen this question pop up a couple other times on the
list and have written them myself in the past.

> Otherwise you end up including every little pet feature that
> someone asks for, and that's known as "PHP".

but pythonistas can at least sort them into namespaces ;)

-tim



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: common constraints

2007-07-27 Thread Jacob Kaplan-Moss

On 7/27/07, james_027 <[EMAIL PROTECTED]> wrote:
> but those min max constraints are so common? why not include it?

Because "common" is different for any given user and/or site. I think
*I've* only written a single form with min/max validation, FWIW.
Designing a framework is hard; you've got to search for things that
are as close to truly universal as possible. Otherwise you end up
including every little pet feature that someone asks for, and that's
known as "PHP".

A good programmer will keep around his/her own library of common code
and break it out whenever needed. If you need min/max validation
often, you should make that the start of your own personal toolkit.

Jacob

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: common constraints

2007-07-27 Thread james_027

Thanks for the fast response Doug,

but those min max constraints are so common? why not include it?

james

On Jul 27, 1:20 pm, Doug B <[EMAIL PROTECTED]> wrote:
> Garg, hit enter too fast.
>
> Class MyForm(forms.Form):
> username = forms.CharField(max_length=12)
> def clean_username(self):
> username = self.clean_data['username']
> if username == 'bob':
>  raise ValidationError("Bob is not allowed here")
> return username
>
> If someone enters 'bob' for a username, form.is_valid() will be False,
> anything else under 12 char long is ok
>
> There are existing fields that do a lot, for email, integers, and so
> on... but if you want do do something they don't support, you've got
> to do a bit yourself.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: common constraints

2007-07-26 Thread Doug B

Garg, hit enter too fast.

Class MyForm(forms.Form):
username = forms.CharField(max_length=12)
def clean_username(self):
username = self.clean_data['username']
if username == 'bob':
 raise ValidationError("Bob is not allowed here")
return username

If someone enters 'bob' for a username, form.is_valid() will be False,
anything else under 12 char long is ok

There are existing fields that do a lot, for email, integers, and so
on... but if you want do do something they don't support, you've got
to do a bit yourself.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: common constraints

2007-07-26 Thread Doug B

newforms does that, but it's up to you do take care of the details by
either subclassing one of the existing fields like this snippet shows:
http://www.djangosnippets.org/snippets/115/

Or by making a specially named method on the form definition like
this:

Class MyForm(forms.Form)
 username = forms.CharField(max_length=12)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



newforms: common constraints

2007-07-26 Thread james_027

Hi all,

I may not well understand the purpose of newforms, or perhaps it is
still in a very early alpha stage ...

I am looking to implement some common constraints like mininum or
maximum letter of character field then values for numerical field.,
range for numerical or date field.

Thanks
james


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---