Re: Customizing forms html

2011-09-21 Thread Jacob G
And I also want to display non-field errors after the form, not before.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/66g7i8P5DqEJ.
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.



Customizing forms html

2011-09-21 Thread Jacob G
I'm trying to customize Django forms html based on three requirements:
1) Html output to match html given to me by a web site designer.
2) Automatically generate forms, so I don't have to duplicate html in 
templates.
3) Re-use as match of Django forms code as possible.

For my first attempt, I'm working on an authentication form. So here's what 
I did:
1) Derive AuthenticationForm class so that I can create use derived classes 
for the CharFields
2) Derive CharField to set css class in widget_attrs
3) Derived ErrorList to use own custom html for errors

Another problem came up: Django assumes that field errors should be 
displayed before the field label. However, I want to display the field error 
after the field's input (after a line break). It would seem that I would 
have to override BaseForm method _html_output, which I would like to avoid.

*Summary Question*: Is there a simpler way to output field error html after 
field, rather than before field, without having to override _html_output?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/TEvOanYctRYJ.
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: Where does form.is_valid() clean the form?

2011-09-21 Thread Jacob G
Thanks all.

I figured out my mess-up: In the view, I instantiated the form incorrectly 
as follows:

form = AuthenticationForm(request.POST)

Instead of the correct way:

form = AuthenticationForm(request, data=request.POST)


The debugger weirdness distracted me from the real problem. I still don't 
know what happened with the debugger, but I've got other things to do, so 
I'm moving on...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/xXaFMc2KYboJ.
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: Where does form.is_valid() clean the form?

2011-09-20 Thread Jacob G
I'm doing this because there's a problem in my code. I create a
AuthenticationForm, and post a non-existing username and password, and
call is_valid(). I expect to then that the errors property will return
at least one error, but there are actually no errors. So I step
through the debugger, and see that full_clean() is not getting called,
because _errors apparently is never None, even after setting it to
None in the BaseForm constructor.

I agree with you that I'm sure such a bug doesn't exist. But I can't
understand at all why it looks like this in the debugger. How can the
code set a variable to None, and it is set to an empty ErrorDict? It
seems like a practical joke or something.

On Sep 20, 4:55 pm, Shawn Milochik <sh...@milochik.com> wrote:
> On Tue, Sep 20, 2011 at 4:46 PM, Jacob G <ja...@fareclock.com> wrote:
> > I doubt I'm familiar enough with Django to fix bugs.
>
> Wait until the talks from DjangoCon US 2011 are out, then watch my
> lightning talk. I guarantee you could submit at least three patches
> today alone.
>
> > I am puzzled by what I am see though with the BaseForm class in Aptana
> > PyDev debugger. I noticed that full_clean() was not being called via a
> > call to is_valid. So I stepped through the debugger, and for some
> > strange reason, the BaseForm constructor, although the code says
> > "self._errors = None" the debugger watchlist shows self._errors as set
> > to an empty ErrorDict, and therefore the _get_errors() method never
> > called full_clean().
>
> > Does this make any sense? It doesn't sound right.
>
> I haven't dug into this particular code, so I don't know why it works
> that way. In any case, what is it that you're actually trying to
> accomplish? I ask because I'm pretty sure Django form validation isn't
> buggy or we'd know by now. If you're just trying to understand Django
> then that's awesome, and I hope you figure it out or someone helps
> out. But if you're digging into it to try to solve a problem in your
> own code, what is it?
>
> Shawn

-- 
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: Where does form.is_valid() clean the form?

2011-09-20 Thread Jacob G
I doubt I'm familiar enough with Django to fix bugs.

I am puzzled by what I am see though with the BaseForm class in Aptana
PyDev debugger. I noticed that full_clean() was not being called via a
call to is_valid. So I stepped through the debugger, and for some
strange reason, the BaseForm constructor, although the code says
"self._errors = None" the debugger watchlist shows self._errors as set
to an empty ErrorDict, and therefore the _get_errors() method never
called full_clean().

Does this make any sense? It doesn't sound right.

On Sep 20, 4:17 pm, Shawn Milochik <sh...@milochik.com> wrote:
> On Tue, Sep 20, 2011 at 4:14 PM, Jacob G <ja...@fareclock.com> wrote:
> > Thanks, I didn't realize errors is property that calls _get_errors().
>
> Yeah, it's non-obvious. That's one of the nice things about
> open-source, though. You can go through the code and understand how
> your tools work so you can better apply them.
>
> Side-note -- now that you're browsing Django's code, I think you could
> easily participate by going to the Trac instance and closing a few
> easy tickets. ;o)  https://code.djangoproject.com/
>
> Shawn

-- 
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: Where does form.is_valid() clean the form?

2011-09-20 Thread Jacob G
Thanks, I didn't realize errors is property that calls _get_errors().

On Sep 20, 4:11 pm, Shawn Milochik  wrote:
> Take your study/research one step further:
>
> https://code.djangoproject.com/browser/django/trunk/django/forms/form...
>
> When it checks for self.errors, the _get_errors() function calls the 
> full_clean.

-- 
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.



Where does form.is_valid() clean the form?

2011-09-20 Thread Jacob G
The Django documentation says that a form is cleaned when calling 
is_valid():

https://docs.djangoproject.com/en/dev/ref/forms/validation/ (see first 
paragraph)


However, the is_valid soure code doesn't show that is does clean, as 
follows:

def is_valid(self):

"""

Returns True if the form has no errors. Otherwise, False. If errors are

being ignored, returns False.

"""

return self.is_bound and not bool(self.errors)


And empirically in my application, I don't see any cleaning taking place 
when I call is_valid.

Am I understanding something wrong? Is an application supposed to 
full_clean() directly followed by a call to is_valid()?

Thanks.

 

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/rYlmQxyACuMJ.
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.