Redirect Helper

class cwf.views.redirect_address.RedirectAddress(request, address, relative=True, carry_get=False, ignore_get=None)[source]

Helper to determine where to redirect to.

Parameters
  • request – Object representing current Django request.

  • address – String representing the address to modify into a redirect url

  • relative – If we should be redirecting relative to the current page we’re on

  • carry_get – If we should use the GET parameters from the current request in our redirect

  • ignore_get – List of GET parameters that should be ignored if carry_get is True

Creating the redirect

RedirectAddress.modified

Returns the result of self.modify(unicode(self.address))

RedirectAddress.modify(address)[source]

Return a modified version of the address passed in as the redirect url.

Uses the following methods in a pipeline of sorts (in this order):

Information

RedirectAddress.base_url

Get base url from request.state if request has an attached state.

Otherwise, return request.META.get('SCRIPT_NAME', '')

RedirectAddress.params

Return dictionary of key value for GET params from self.request.

If not self.ignore_get then just return request.GET

Otherwise, return request.GET minus any values whose key is in self.ignore_get

Utility

RedirectAddress.strip_multi_slashes(string)[source]

Replace multiple slashes with single slashes in a string

RedirectAddress.root_url(address)[source]

Determine if address is a root url (starts with slash)

RedirectAddress.add_get_params(address)[source]

If self.carry_get is False, then just return the address as is.

Otherwise, urlencode the result of params and return a string that joins address and the parameters.

RedirectAddress.joined_address(address)[source]

If address is a root_url(), then join the address with base_url.

Otherwise, if self.relative, then join the address with self.request.path

If the address is not a root url and self.relative is False, then return as is

RedirectAddress.url_join(a, b)[source]

Helper to join two urls such that there is only one / between them.