Re: How do I correctly format a Querydict derived list in a url?

2009-02-02 Thread Thomas Guettler

Alfonso schrieb:
> Thanks Alex,
>
> I tried that but no joy - the problem is I just can't get django to
> nicely capture the list's values - it's really stumped me!
>
> location_filter = request.POST.getlist("location")  does give me a
> python list of location variables. But I can't get this resultant
> [u'ireland', u'nireland'] list to become iterable where I can just
> drop the values into a HttpResponseRedirect url like /ireland-
> nireland/
>
> I think I am approaching this incorrectly - If I try request.POST
> ["location"]  It all works but only with the last item in the
> QueryDict.
>   
Hi,

I would send the list as GET data:
   http://?location=a=b
Then you can use this URL for a redirect, too.

You can use urlencode:

from django.utils.http import urlencode

to create the string after the question mark.

BTW, I think urlencode has a bug:
 http://code.djangoproject.com/ticket/9089

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~-~--~~~---~--~~
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: How do I correctly format a Querydict derived list in a url?

2009-01-31 Thread NoviceSortOf

> > > myurl.com/activities/[u'ireland',
> > > u'nireland']/: what I really want
> > > is:
>
> > > /activities/ireland-nireland/
>


I'm not sure if any of this is the 'correct' way but it likely
will work.

Try a combination of python's eval() and str()
function to convert/maninuplate the location_filter
object into a string and format into the string you want.

As well it seems you should be able to pull the elements out
of the location_filter using something like location_filter[1]
and location_filter[2] and then format the string to your
requirements.

Also note there is a django function smart_str() that might
help with working with the unicode formating.

I've not tested this exactly but something like this, in
theory

from django.utils.encoding import smart_str
location_filterAscii = smart_str(location_filter,encoding='utf-8')

Or you can simply do something like mystring.replace("u,","") and
other
python string manipulators to get the string like you want it.

Otherwise it seems this is python string manipulation stuff
you can workout on the command line, using str() and/or eval(),
and .replace.


--~--~-~--~~~---~--~~
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: How do I correctly format a Querydict derived list in a url?

2009-01-30 Thread Alfonso

Thanks Alex,

I tried that but no joy - the problem is I just can't get django to
nicely capture the list's values - it's really stumped me!

location_filter = request.POST.getlist("location")  does give me a
python list of location variables. But I can't get this resultant
[u'ireland', u'nireland'] list to become iterable where I can just
drop the values into a HttpResponseRedirect url like /ireland-
nireland/

I think I am approaching this incorrectly - If I try request.POST
["location"]  It all works but only with the last item in the
QueryDict.

Hope I'm making sense, Thanks!

Allan



On Jan 30, 7:35 pm, Alex Koshelev  wrote:
> Try this:
>
> return HttpResponseRedirect('/activities/%s/' %  "-".join(location_filter))
>
> On Fri, Jan 30, 2009 at 10:26 PM, Alfonso  wrote:
>
> > I've got a form delivering multiple variables from a checkbox group
> > via POST to a view that defines where to redirect to.
>
> > I've got django to pass the values of this Querydict to a redirect
> > response but can't change the formatting:
>
> > In my view:
>
> > location_filter = request.POST.getlist("location")
> > return HttpResponseRedirect('/activities/%s/' % location_filter)
>
> > And that gives me:
>
> > myurl.com/activities/[u'ireland',
> > u'nireland']/: what I really want
> > is:
>
> > /activities/ireland-nireland/
>
> > Any help woukd be great - I've been staring at this far too long!
>
>
--~--~-~--~~~---~--~~
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: How do I correctly format a Querydict derived list in a url?

2009-01-30 Thread Alex Koshelev
Try this:

return HttpResponseRedirect('/activities/%s/' %  "-".join(location_filter))


On Fri, Jan 30, 2009 at 10:26 PM, Alfonso  wrote:

>
> I've got a form delivering multiple variables from a checkbox group
> via POST to a view that defines where to redirect to.
>
> I've got django to pass the values of this Querydict to a redirect
> response but can't change the formatting:
>
> In my view:
>
> location_filter = request.POST.getlist("location")
> return HttpResponseRedirect('/activities/%s/' % location_filter)
>
> And that gives me:
>
> myurl.com/activities/[u'ireland',
> u'nireland']/: what I really want
> is:
>
> /activities/ireland-nireland/
>
> Any help woukd be great - I've been staring at this far too long!
> >
>

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



How do I correctly format a Querydict derived list in a url?

2009-01-30 Thread Alfonso

I've got a form delivering multiple variables from a checkbox group
via POST to a view that defines where to redirect to.

I've got django to pass the values of this Querydict to a redirect
response but can't change the formatting:

In my view:

location_filter = request.POST.getlist("location")
return HttpResponseRedirect('/activities/%s/' % location_filter)

And that gives me:

myurl.com/activities/[u'ireland', u'nireland']/: what I really want
is:

/activities/ireland-nireland/

Any help woukd be great - I've been staring at this far too long!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---