Seeking pattern for building URLs with all query parameters intact
I've got a handful of applications that feature paginated object lists
as well as a search dialog allowing users to search for simple object
attributes.
What is the common pattern to use in Django apps to build URI query
strings in view code that can preserve parameters for rendering links
in templates? In my case I'd like to handle the following:
1. User searches for string, passed as GET parameter and application
returns paginated object list the spans multiple pages
2. First page contains links for subsequent pages ('page' parameter in
URI query string) and preserves search string (additional 'search'
parameter in URI query string)
So far I've taken key/value pairs out of request.GET and added them to
the context as more_query_params and passed them in to templates. This
seems a little raw and klugey although it works for the simple cases.
There must be a better way. Currently (from a view that returns
paginated object list:
# Determine other parameters from request, provide to template to craft
# smarter URLs that handle concurrent search + pagination (etc.).
if request.method == 'GET':
more_query_params = ''
for key, value in request.GET.items():
if key != 'page':
more_query_params += '&%s=%s' % (key, value)
return render_to_response('submissionlog_pages.html', {
'submissionlogs': submissionlogs,
'search_form': search_form,
'more_query_params': more_query_params,
}, context_instance=RequestContext(request))
What are better ways to handle this?
--
Darren Spruell
phatbuckett@gmail.com
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home