Hi All,
I have a couple of views in my project that process two forms at once
(that is, two django forms; one HTML form of course). While I maintain
the User and UserProfile models separately, for UI purposes they are
one construct, so I have an "Edit Account" page that uses a user_form
and a profile_form:
---
def account_edit(request):
if request.method == 'POST':
user_form = UserEditForm(request.POST, instance=request.user)
profile_form = ProfileEditForm(request.POST,
instance=request.user.get_profile())
...
---
In templates I have a custom inclusion tag that displays a list of
form errors. (The inline indicators, next to the fields, are just
icons. The list at the top is where the actual error messages appear.)
---
{% block content %}
{% display_form_errors %}
<form action="." method="post">
<h3>Personal Information</h3>
{% display_form_field user_form.email %}
{% display_form_field profile_form.first_name %}
{% display_form_field profile_form.last_name %}
...
---
The display_form_errors tag just passes the "form" object from the
context through to the template, and iterates over form.errors,
rendering a complete HTML list from the first <ul> to the last </ul>.
I obviously can't call display_form_errors twice, once for each form,
because there is only one logical form to the user -- two separate
lists would be silly if fields in both forms generate errors.
What I'd like to do is pass display_form_errors either a form or a
list of forms, depending on the situation, and have it iterate over
the form or each form in the list, respectively:
---
{% display_form_errors user_form profile_form %}
(or in another template with a single form:)
{% display_form_errors form %}
---
...but as far as I can tell from experimenting, that syntax isn't
valid for inclusion tags. I tried doing a regular tag, parsing the
token for form names and generating output from a template and context
manually, but that didn't seem to work either.
Could anyone steer me in the right direction for this?
A tangental question is if there is a novice's guide to the Context/
RequestContext objects anywhere -- I was able to get a semi-working
version by having the tag extract objects matching "form" or "*_form"
from context.dicts[1], but from my limited source-reading skills I
don't quite "get" how Context works. (A list of dictionaries, but how
do I know which dictionary I'm after? Seems like the dicts[1] could
easily vary and hard-coding would be a Bad Idea.)
Thanks,
Scott
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---