Re: render_to_response fails with TemplateSyntaxError: too many values to unpack

2009-08-18 Thread girzel
On Wed, Aug 19, 2009 at 8:30 AM, Janne Peltola wrote:

>
> Template rendering fails when both form data and a tuple are passed to
> render_to_response.
>
> Python: 2.6.2; Django: 1.1; Environment: Windows + built-in dev server
>
> I use the standard django.contrib.auth.models.User and .Group models.
>
> View:
>
> class FuksiForm(forms.Form):
>ryhmat = forms.ModelChoiceField(queryset=Group.objects.none(),
> empty_label = "Ei saapunut")
>
>def __init__ (self, qset):
>super(FuksiForm, self).__init__(qset)
>self.fields["ryhmat"].queryset = qset


Janne, I was able to recreate your error with a test app, and made it go
away by *not* passing qset to the super call to __init__ (which is not
expecting a qset argument).


>
>
> def fuksit(request, ohjelma_id):
>if request.method == 'POST': # If the form has been submitted...
>form = FuksiForm(request.POST) # A form bound to the POST
> data
>if form.is_valid(): # All validation rules pass
>msg = 'meh'
>return HttpResponse(msg)
>
>else:
>users =
> User.objects.filter(ryhma__nimi__startswith=ohjelma_id)
>
>groups = Group.objects.filter(name__startswith=ohjelma_id)
>
>form = FuksiForm(qset = groups)
>d = {'form': form, 'pf': users}
>
>
> Template:
>
> 
> {% for u in pf %}
>
>{{ u.first_name }} {{ u.last_name }}
>{{ u.username }}
>{{ form.ryhmat.errors }}  for="id_ryhmat">Ryhma
> {{ form.ryhmat }}
>
> {% endfor %}
> 


I would also expect that instantiating a single form and then repeating it
for each user in users may cause you difficulties when you start submitting
those forms, but I'm not sure about that...

Hope that helps,
Eric


>
>
> This produces: http://users.tkk.fi/jjpelto3/exception.html
>
> When either form or pf are removed from the dictionary, the program
> works fine. However, everything seems to be fine until
> render_to_response when I do debugging in the shell.
>
> I suspect a bug in the rendering handler, since people on #django were
> unable to help either. There are no documented similar cases.
>
> I am utterly perplexed. Please help. :)
>
> >
>

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



render_to_response fails with TemplateSyntaxError: too many values to unpack

2009-08-18 Thread Janne Peltola

Template rendering fails when both form data and a tuple are passed to
render_to_response.

Python: 2.6.2; Django: 1.1; Environment: Windows + built-in dev server

I use the standard django.contrib.auth.models.User and .Group models.

View:

class FuksiForm(forms.Form):
ryhmat = forms.ModelChoiceField(queryset=Group.objects.none(),
empty_label = "Ei saapunut")

def __init__ (self, qset):
super(FuksiForm, self).__init__(qset)
self.fields["ryhmat"].queryset = qset

def fuksit(request, ohjelma_id):
if request.method == 'POST': # If the form has been submitted...
form = FuksiForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
msg = 'meh'
return HttpResponse(msg)

else:
users = User.objects.filter(ryhma__nimi__startswith=ohjelma_id)

groups = Group.objects.filter(name__startswith=ohjelma_id)

form = FuksiForm(qset = groups)
d = {'form': form, 'pf': users}


Template:


{% for u in pf %}

{{ u.first_name }} {{ u.last_name }}
{{ u.username }}
{{ form.ryhmat.errors }} Ryhma
{{ form.ryhmat }}

{% endfor %}


This produces: http://users.tkk.fi/jjpelto3/exception.html

When either form or pf are removed from the dictionary, the program
works fine. However, everything seems to be fine until
render_to_response when I do debugging in the shell.

I suspect a bug in the rendering handler, since people on #django were
unable to help either. There are no documented similar cases.

I am utterly perplexed. Please help. :)

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