1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | def persistent_params(*param_names):
def decorate(view_func):
@wraps(view_func)
def decorated(request, *args, **kwargs):
response = view_func(request, *args, **kwargs)
if response.status_code in (301, 302, 303, 307):
location = response['Location']
parts = location.split('?')
if len(parts) == 1:
query_dict = QueryDict('', mutable=True)
else:
query_dict = QueryDict(parts[1], mutable=True)
for name in param_names:
query_dict[name] = request.GET.get(name, None)
new_query_string = query_dict.urlencode()
response['Location'] = parts[0] + '?' + new_query_string
return response
return decorated
return decorate
|
More like this
- A tip for preserving GET arguments with pagination by achimnol 3 years, 11 months ago
- Append paramaters to a GET querystring (template tag) by gregb 3 years, 10 months ago
- Pagination/Filtering Alphabetically by zain 4 years, 2 months ago
- Paginator Tag by insin 6 years, 2 months ago
- Add GET parameter tag by marltu 2 years, 10 months ago
Comments
I think I'd change line 6 to be more explicit, ie:
if response.status_code in (301, 302, 303, 307):
To be safe.
#
Thanks ssadler for pointing it. :)
#