form error_messages doesnt work

2009-04-09 Thread emonk
Hi,
I have *this form:*

class registerForm(forms.Form):
aNumber = forms.IntegerField(
label='Some Integer Field',
max_value=,
min_value=100,
help_text='7 digits min and 8 digits max',
error_messages={
'invalid':'Only numbers pls!',
'min_value':'min 7 digits!',
'max_value':'max 8
digits!',
 }
)
*the view:*
def register_form(request):
if request.method == 'POST':
form = registerForm(request.POST)
if form.is_valid():
register = registerModel.objects.get_or_create(
aNumber=form.cleaned_data['aNumber']
)
return HttpResponseRedirect('/home/')
else:
form = registerForm()
vars = RequestContext(request, { 'form':form })
return render_to_response('register_form.html', vars)

*the model:
*class registerModel(models.Model):
aNumber = models.IntegerField(primary_key=True,unique=True,db_index=True)*
*

Well, if I put any character like "123asd" in the form field, the form
is re-rendered with the label mesaage "Only numbers pls!" at the top
of the same field rigth? that's good

But if I put only integer digits violating the rule min_value or max_value,
i get a TypeError page with:

"TypeError at /myProject/myApp/form/

not all arguments converted during string formatting

Exception Type: TypeError
Exception Value: not all arguments converted during string formatting
Exception Location: /usr/lib/pymodules/python2.5/django/forms/fields.py in
clean, line 190
Python Executable: /usr/bin/python
...
/usr/lib/pymodules/python2.5/django/forms/fields.py in clean
...
190.raise ValidationError(self.error_messages['min_value'] %
self.min_value)
..."

Why the error_message 'min_value' doesn't work as the error_message
'invalid'?
What is wrong?
Thanks a lot for any help.




-- 
---
Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
--

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread emonk
I do not understand that these messages are not working as if the other
Who care if i talk about lenght, what happen if i talk about range of
numbers?
That should be work just like the message "invalid" .

On Thu, Apr 9, 2009 at 11:50 PM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

>
> On Thu, 2009-04-09 at 23:23 -0300, emonk wrote:
> > Hi,
> > I have this form:
> > class registerForm(forms.Form):
> > aNumber = forms.IntegerField(
> > label='Some Integer Field',
> > max_value=,
> >
> > min_value=100,
> > help_text='7 digits min and 8 digits
> max',
> > error_messages={
> > 'invalid':'Only numbers
> pls!',
> >
> > 'min_value':'min 7
> digits!',
> > 'max_value':'max 8
> digits!',
>
> If you have a look at the error messages you are replacing (in
> django/forms/fields.py), you'll see that they are passed a single
> parameter (indicated by the "%s"). So your replacement messages must be
> able to handle those parameters as well.
>
> If you look a bit closer, you'll see that the parameter being passed in
> is the maximum or minimum value. You're trying to use max- and
> min-values to talk about length, which isn't really the intention, so
> things aren't going to work nicely. If you want to talk about length,
> use a CharField, or a RegexField -- since you're trying to treat the
> input as a string (with a length), rather than a number (with a size).
>
> Regards,
> Malcolm
>
>
> >
>


-- 
---
Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
--

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread emonk
btw, thanks anyway :)

On Fri, Apr 10, 2009 at 12:07 AM, emonk  wrote:

> I do not understand that these messages are not working as if the other
> Who care if i talk about lenght, what happen if i talk about range of
> numbers?
> That should be work just like the message "invalid" .
>
>
> On Thu, Apr 9, 2009 at 11:50 PM, Malcolm Tredinnick <
> malc...@pointy-stick.com> wrote:
>
>>
>> On Thu, 2009-04-09 at 23:23 -0300, emonk wrote:
>> > Hi,
>> > I have this form:
>> > class registerForm(forms.Form):
>> > aNumber = forms.IntegerField(
>> > label='Some Integer Field',
>> > max_value=,
>> >
>> > min_value=100,
>> > help_text='7 digits min and 8 digits
>> max',
>> > error_messages={
>> > 'invalid':'Only numbers
>> pls!',
>> >
>> > 'min_value':'min 7
>> digits!',
>> > 'max_value':'max 8
>> digits!',
>>
>> If you have a look at the error messages you are replacing (in
>> django/forms/fields.py), you'll see that they are passed a single
>> parameter (indicated by the "%s"). So your replacement messages must be
>> able to handle those parameters as well.
>>
>> If you look a bit closer, you'll see that the parameter being passed in
>> is the maximum or minimum value. You're trying to use max- and
>> min-values to talk about length, which isn't really the intention, so
>> things aren't going to work nicely. If you want to talk about length,
>> use a CharField, or a RegexField -- since you're trying to treat the
>> input as a string (with a length), rather than a number (with a size).
>>
>> Regards,
>> Malcolm
>>
>>
>> >>
>>
>
>
> --
> ---
> Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
> --
>



-- 
---
Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
--

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 00:07 -0300, emonk wrote:
> I do not understand that these messages are not working as if the
> other
> Who care if i talk about lenght, what happen if i talk about range of
> numbers? 

I wrote that you need to accept a format parameter in the error messages
(the "%s"). Have a look at the original messages you are trying to to
replace (in the file I pointed you to) and you'll see what I mean. I
also told you what the parameter is for (it contains the maximum or
minimum value allowed in the field). This means your error message for
those cases must use the maximum and minimum values in the string it
outputs. If that's not appropriate, then this isn't the right form field
to be using.

> That should be work just like the message "invalid" .

No they shouldn't. The error messages you are replacing are for max- and
min-value violations are specialised messages. They are giving the user
the necessary information to correct their error by providing the
maximum and minimum values.

The "invalid" error is much more generic and used when there isn't
something more specific available. You can't just guess at how things
should behave and then complain when it doesn't work like that. You have
to allow for the possibility that it's your guess which is wrong.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread Malcolm Tredinnick

On Thu, 2009-04-09 at 23:23 -0300, emonk wrote:
> Hi,
> I have this form:
> class registerForm(forms.Form):
> aNumber = forms.IntegerField(
> label='Some Integer Field',
> max_value=,
> 
> min_value=100,
> help_text='7 digits min and 8 digits max',
> error_messages={
> 'invalid':'Only numbers pls!',
> 
> 'min_value':'min 7 digits!',
> 'max_value':'max 8 digits!',  
>  

If you have a look at the error messages you are replacing (in
django/forms/fields.py), you'll see that they are passed a single
parameter (indicated by the "%s"). So your replacement messages must be
able to handle those parameters as well.

If you look a bit closer, you'll see that the parameter being passed in
is the maximum or minimum value. You're trying to use max- and
min-values to talk about length, which isn't really the intention, so
things aren't going to work nicely. If you want to talk about length,
use a CharField, or a RegexField -- since you're trying to treat the
input as a string (with a length), rather than a number (with a size).

Regards,
Malcolm


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread emonk
I understand your point, but how i do if i dont want to show the %s in my
custom error message? :S

On Fri, Apr 10, 2009 at 12:22 AM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

>
> On Fri, 2009-04-10 at 00:07 -0300, emonk wrote:
> > I do not understand that these messages are not working as if the
> > other
> > Who care if i talk about lenght, what happen if i talk about range of
> > numbers?
>
> I wrote that you need to accept a format parameter in the error messages
> (the "%s"). Have a look at the original messages you are trying to to
> replace (in the file I pointed you to) and you'll see what I mean. I
> also told you what the parameter is for (it contains the maximum or
> minimum value allowed in the field). This means your error message for
> those cases must use the maximum and minimum values in the string it
> outputs. If that's not appropriate, then this isn't the right form field
> to be using.
>
> > That should be work just like the message "invalid" .
>
> No they shouldn't. The error messages you are replacing are for max- and
> min-value violations are specialised messages. They are giving the user
> the necessary information to correct their error by providing the
> maximum and minimum values.
>
> The "invalid" error is much more generic and used when there isn't
> something more specific available. You can't just guess at how things
> should behave and then complain when it doesn't work like that. You have
> to allow for the possibility that it's your guess which is wrong.
>
> Regards,
> Malcolm
>
>
>
> >
>


-- 
---
Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
--

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread Malcolm Tredinnick

On Fri, 2009-04-10 at 00:48 -0300, emonk wrote:
> I understand your point, but how i do if i dont want to show the %s in
> my custom error message? :S

I mentioned that in my original reply in this thread: Use CharField or
RegexField. 

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread emonk
Thanks but is not a better solution, this is bug
http://code.djangoproject.com/ticket/8104#comment:1

On Fri, Apr 10, 2009 at 12:52 AM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

>
> On Fri, 2009-04-10 at 00:48 -0300, emonk wrote:
> > I understand your point, but how i do if i dont want to show the %s in
> > my custom error message? :S
>
> I mentioned that in my original reply in this thread: Use CharField or
> RegexField.
>
> Regards,
> Malcolm
>
>
>
> >
>


-- 
---
Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
--

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread Alex Gaynor
On Thu, Apr 9, 2009 at 11:58 PM, emonk  wrote:

> Thanks but is not a better solution, this is bug
> http://code.djangoproject.com/ticket/8104#comment:1
>
> On Fri, Apr 10, 2009 at 12:52 AM, Malcolm Tredinnick <
> malc...@pointy-stick.com> wrote:
>
>>
>> On Fri, 2009-04-10 at 00:48 -0300, emonk wrote:
>> > I understand your point, but how i do if i dont want to show the %s in
>> > my custom error message? :S
>>
>> I mentioned that in my original reply in this thread: Use CharField or
>> RegexField.
>>
>> Regards,
>> Malcolm
>>
>>
>>
>>
>>
>
>
> --
> ---
> Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
> --
>
> >
>
No a ticket was filed, that doesn't inherently indicate a bug(lots of
erroneous tickets are filed), as SmilyChris notes it really just needs a
docs fix, because the only other alternative is a bunch of try except blocks
which is both unreasonable, and as Malcolm has stated really indicates that
you should be using a different field type.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form error_messages doesnt work

2009-04-09 Thread emonk
ok ok, i will use a regexp field, but I still think they should be able to
make a custom error message for form.IntegerField without %s .
thanks for your help guys.

On Fri, Apr 10, 2009 at 1:02 AM, Alex Gaynor  wrote:

>
>
> On Thu, Apr 9, 2009 at 11:58 PM, emonk  wrote:
>
>> Thanks but is not a better solution, this is bug
>> http://code.djangoproject.com/ticket/8104#comment:1
>>
>> On Fri, Apr 10, 2009 at 12:52 AM, Malcolm Tredinnick <
>> malc...@pointy-stick.com> wrote:
>>
>>>
>>> On Fri, 2009-04-10 at 00:48 -0300, emonk wrote:
>>> > I understand your point, but how i do if i dont want to show the %s in
>>> > my custom error message? :S
>>>
>>> I mentioned that in my original reply in this thread: Use CharField or
>>> RegexField.
>>>
>>> Regards,
>>> Malcolm
>>>
>>>
>>>
>>>
>>>
>>
>>
>> --
>> ---
>> Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
>> --
>>
>>
>>
> No a ticket was filed, that doesn't inherently indicate a bug(lots of
> erroneous tickets are filed), as SmilyChris notes it really just needs a
> docs fix, because the only other alternative is a bunch of try except blocks
> which is both unreasonable, and as Malcolm has stated really indicates that
> you should be using a different field type.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
>
>
> >
>


-- 
---
Key fingerprint = 0CCB D0F6 47F2 5F70 6F40  53D3 7537 A0E4 94FC 40EE
--

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---